elasticsearch6.x 集群安装和采坑指南

准备工作

  1. 3 台 centos 机器(也可以用一台,修改es的port,本文使用三台机器)
  2. 3台机器要 jdk8.0
  3. 创建目录
 1. mkdir /opt/es  
    mkdir -p /data/es_data
    mkdir -p /data/es_logs

 2. cd /opt/es , unzip 命令解压
 3. useradd es
 4. passwd es 修改 es密码
 5. sudo chown -R es:es /opt/es
    chown -R es:es /opt//data/es*
 6. sudo su es
 7. cd /opt/es

下载

下载地址

# https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.0-linux-x86_64.tar.gz
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.zip
    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.zip.sha512
    shasum -a 512 -c elasticsearch-6.5.4.zip.sha512 
    unzip elasticsearch-6.5.4.zip
    cd elasticsearch-6.5.4/

cluster config

node-1 192.168.0.1 配置

vi config/elasticsearch.yml
cluster.name: moheqionglin

node.name: node-1

#自定义node属性
node.attr.ip: 192.168.0.1


path.data: /data/es_data

path.logs: /data/es_logs

network.host:  192.168.0.1

http.port: 9200

discovery.zen.ping.unicast.hosts: [" 192.168.0.2", " 192.168.0.3"]

# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
discovery.zen.minimum_master_nodes: 2

http.cors.enabled: true
http.cors.allow-origin: "*"

node-2 192.168.0.2 配置

vi config/elasticsearch.yml
cluster.name: moheqionglin

node.name: node-2

#自定义node属性
node.attr.ip: 192.168.0.2


path.data: /data/es_data

path.logs: /data/es_logs

network.host:  192.168.0.2

http.port: 9200

discovery.zen.ping.unicast.hosts: [" 192.168.0.1", " 192.168.0.3"]

# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
discovery.zen.minimum_master_nodes: 2

http.cors.enabled: true
http.cors.allow-origin: "*"

node-3 192.168.0.3 配置

vi config/elasticsearch.yml
cluster.name: moheqionglin

node.name: node-3

#自定义node属性
node.attr.ip: 192.168.0.3


path.data: /data/es_data

path.logs: /data/es_logs

network.host:  192.168.0.3

http.port: 9200

discovery.zen.ping.unicast.hosts: [" 192.168.0.1", " 192.168.0.2"]

# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
discovery.zen.minimum_master_nodes: 2

http.cors.enabled: true
http.cors.allow-origin: "*"

jvm config

vi config/jvm.options 
-Xms2g
-Xmx2g
-XX:HeapDumpPath=/data/es/logs/
-XX:ErrorFile=/data/es/logs/logs/hs_err_pid%p.log

报错

分别启动三台es

bin/elasticsearch

报如下错误

ERROR: [3] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

解决方法 见上面文章:elasticsearch6.x单机安装和采坑指南 中的启动中遇到的问题和解决方法记录的内容

三台启动成功日志

[2019-01-23T16:28:28,977][INFO ][o.e.n.Node               ] [node-1] starting ...
[2019-01-23T16:28:29,178][INFO ][o.e.t.TransportService   ] [node-1] publish_address {192.168.0.1:9300}, bound_addresses {192.168.0.1:9300}
[2019-01-23T16:28:32,285][WARN ][o.e.d.z.ZenDiscovery     ] [node-1] not enough master nodes discovered during pinging

[2019-01-23T16:29:00,134][INFO ][o.e.x.m.e.l.LocalExporter] [node-1] waiting for elected master node [{node-2}{RMPJa3SIQ7mi81jIzzo8gw}{HIc9e12vToSuIsfdMDVXiA}{192.168.0.2}{192.168.0.2:9300}{ml.machine_memory=4019404800, ml.max_open_jobs=20, xpack.installed=true, ml.enabled=true, ip=192.168.0.2}] to setup local exporter [default_local] (does it have x-pack installed?)

### 很重要的一行日志, 证明 node-2被选举为leader/master
[2019-01-23T16:58:08,878][INFO ][o.e.c.s.ClusterApplierService] [node-1] detected_master {node-2}{RMPJa3SIQ7mi81jIzzo8gw}{MbQ9aZW9RX2GcQ4JPiYsgw}{192.168.0.2}{192.168.0.2:9300}{ml.machine_memory=4019404800, ml.max_open_jobs=20, xpack.installed=true, ml.enabled=true, ip=192.168.0.2}, added {{node-2}{RMPJa3SIQ7mi81jIzzo8gw}{MbQ9aZW9RX2GcQ4JPiYsgw}{192.168.0.2}{192.168.0.2:9300}{ml.machine_memory=4019404800, ml.max_open_jobs=20, xpack.installed=true, ml.enabled=true, ip=192.168.0.2},}, reason: apply cluster state (from master [master {node-2}{RMPJa3SIQ7mi81jIzzo8gw}{MbQ9aZW9RX2GcQ4JPiYsgw}{192.168.0.2}{192.168.0.2:9300}{ml.machine_memory=4019404800, ml.max_open_jobs=20, xpack.installed=true, ml.enabled=true, ip=172.16.219.13} committed version [1]])

[2019-01-23T16:29:02,009][INFO ][o.e.c.s.ClusterApplierService] [node-1] added {{node-3}{jgpeakImTE6VADkDfBHnLA}{KEi6Y0wrQyCwuLLe3Uzu6Q}{192.168.0.3}{192.168.0.3:9300}{ml.machine_memory=4019404800, ml.max_open_jobs=20, xpack.installed=true, ml.enabled=true, ip=192.168.0.3},}, reason: apply cluster state (from master [master {node-2}{RMPJa3SIQ7mi81jIzzo8gw}{HIc9e12vToSuIsfdMDVXiA}{192.168.0.1}{192.168.0.1:9300}{ml.machine_memory=4019404800, ml.max_open_jobs=20, xpack.installed=true, ml.enabled=true, ip=192.168.0.1} committed version [15]])

通过日志可以看出来 node-2被选举为master

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
慷慨打赏