elasticsearch6.x集群安装部署

Posted yiqian1989

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了elasticsearch6.x集群安装部署相关的知识,希望对你有一定的参考价值。

es 集群部署

操作系统为centos7.6
集群规模:3

软件包准备

说明:jdk版本不能低于1.8,推荐使用openjdk

软件包版本下载地址
elasticsearch6.2.3https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.3.rpm
openjdk9.0.4https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz

部署步骤

三个节分别安装jdk和es服务

在三个节点上分别安装jdk和elasticsearch服务,并以单节点的形式启动服务,验证服务是否正常安装

  1. 解压jdk:
    tar -zxvf openjdk-9.0.4_linux-x64_bin.tar.gz
  2. 安装elasticsearch
    rpm -ivh elasticsearch-6.2.3.rpm
  3. 给elasticsearch指定JAVA_HOME
    vi /etc/sysconfig/elasticsearch
# Elasticsearch Java path
JAVA_HOME=/opt/jdk-9.0.4
  1. 修改elasticsearch的服务为开机自启动
    systemctl enable elasticsearch.service
  2. 启动elasticsearch服务
    systemctl start elasticsearch
  3. 验证es服务是否可用
curl http://localhost:9200

  "name" : "node-3",
  "cluster_name" : "my-application",
  "cluster_uuid" : "_na_",
  "version" : 
    "number" : "6.2.3",
    "build_hash" : "c59ff00",
    "build_date" : "2018-03-13T10:06:29.741383Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  ,
  "tagline" : "You Know, for Search"

  1. 如果es服务启动失败,请到/var/log/elasticsearch/var/log/messages下查看错误信息

独立的3个es节点组成集群

到此3个节点的es只是单独存在的,还没有形成一个集群,需要调整配置使其形成集群

  1. 修改/etc/elasticsearch/elasticsearch.yml的相关参数
参数说明
cluster.name三个节点的cluster.name参数必须保持一致
node.name每个节点的node.name必须唯一
network.host本节点bind的ip
discovery.zen.ping.unicast.hosts三个节点的ip数组,用于es集群节点的自动发现
discovery.zen.minimum_master_nodesTo avoid a split brain, this setting should be set to a quorum of master-eligible nodes:
(master_eligible_nodes / 2) + 1

举例:

# Use a descriptive name for your cluster:
cluster.name: my-application
# Use a descriptive name for the node:
node.name: node-3
# Set the bind address to a specific IP (IPv4 or IPv6):
network.host: 10.0.44.47
# The default list of hosts is ["127.0.0.1", "[::1]"]
discovery.zen.ping.unicast.hosts: ["10.0.44.45", "10.0.44.46","10.0.44.47"]
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
discovery.zen.minimum_master_nodes: 2
  1. 修改jvm参数/etc/elasticsearch/jvm.options
    建议-Xms -Xmx修改值为物理内存的50%,比如虚机内存是4G,则-Xms -Xmx参数值设置成2G
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms2g
-Xmx2g
  1. 其他重要参数修改
    • 数据目录配置path.data,rpm安装完默认值是/var/lib/elasticsearch,建议设置独立的数据盘,并把该参数改完数据盘的目录

操作系统参数设置

  • 关闭swap
    • 执行命令:swapoff -a
    • 释掉/etc/fstab包含swap相关的行
    • 执行命令sysctl vm.swappiness=1
    • /etc/sysctl.conf 文件里添加vm.swappiness=1

以上是关于elasticsearch6.x集群安装部署的主要内容,如果未能解决你的问题,请参考以下文章

Elasticsearch6.x使用初探

Ubuntu 18.04 LTS 安装 Elasticsearch6.x

Elasticsearch6.x之Kibana插件安装

Elasticsearch:使用 Docker compose 来一键部署 Elastic Stack 8.x

ELK集群安装教程

ELK集群搭建简略记录