一、前提条件
1、Elasticsearch的安装需要java环境,本文选择jdk1.8
2、Elasticsearch安装包版本:elasticsearch-7.12.1-linux-x86_64.tar.gz
3、假设3台服务器分别为
node-1
192.168.253.129
node-2
192.168.253.131
node-3
192.168.253.132
二、ES集群的搭建
1、创建一个es用户组和用户(出于安全考虑,es不能使用root运行)
groupadd es
useradd es -g es -p es
2、解压es的安装包
tar -zxvf elasticsearch-7.12.1-linux-x86_64.tar.gz -C /home/es/
chown -R es:es /home/es/elasticsearch-7.12.1/
3、切到es用户
su - es
配置es的配置文件
文件位置:/home/es/elasticsearch-7.12.1/config/elasticsearch.yml
cluster.name: my-application //集群名称,不同节点相同
node.name: node-1 //节点名称,不同节点不同
network.host: 192.168.253.129 //节点IP,不同节点不同
http.port: 9200
cluster.initial_master_nodes: ["node-1", "node-2"]
transport.tcp.port: 9300 //es的tcp监听端口
discovery.seed_hosts: ["192.168.253.129:9300", "192.168.253.131:9300","192.168.253.132:9300"] //集群节点集
cluster.initial_master_nodes: ["192.168.253.129:9300"] //集群启动时的初始主节点
4、切换到bin目录下执行 ./elasticsearch 启动es
/home/es/elasticsearch-7.12.1/bin/elasticsearch
三、测试ES集群
四、部署过程中遇到的问题
问题一:bootstrap check failure [1] of [3]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
elasticsearch用户拥有的可创建文件描述的权限太低,至少需要65536;
解决措施:
切回root,编辑limits.conf
vi /etc/security/limits.conf
添加
es hard nofile 65536
es soft nofile 65536
问题二:bootstrap check failure [2] of [3]: max number of threads [3795] for user [es] is too low, increase to at least [4096]
elasticsearch最大线程数目太低
解决措施:
切回root,编辑limits.conf
vi /etc/security/limits.conf
添加
es soft nproc 4096
es hard nproc 4096
问题三:bootstrap check failure [3] of [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
elasticsearch用户拥有的内存权限太小,至少需要262144
解决措施:
切回root,编辑sysctl.conf
vi /etc/sysctl.conf
vm.max_map_count=262144
加载参数
sysctl -p
问题四:
[o.e.c.c.ClusterFormationFailureHelper] [node-2] master not discovered yet, this node has not previously joined a bootstrapped (v7+) cluster, and this node must discover master-eligible nodes [node-1, node-2] to bootstrap a cluster: hav e discovered [{node-2}{NCgBgYarSTq-QELxBzXFvQ}{Lp9UG3StQ12F5T4W93Nrag}{192.168.253.131}{192.168.253.131:9300}{cdfhilmrstw}{ml.machine_memory=1019572224, xpack.installed=true, transform.node=true, ml.max_open_jobs=20, ml.max_jvm_size=406847488}]; discovery will continu e using [127.0.0.1:9300, [::1]:9300] from hosts providers and [{node-2}{NCgBgYarSTq-QELxBzXFvQ}{Lp9UG3StQ12F5T4W93Nrag}{192.168.253.131}{192.168.253.131:9300}{cdfhilmrstw}{ml.machine_memory=1019572224, xpack.installed=true, transform.node=true, ml.max_open_jobs=20, ml .max_jvm_size=406847488}] from last-known cluster state; node term 0, last-accepted version 0 in term 0
无法找到主节点
解决措施:在elasticsearch.yml增加下列3个配置项
transport.tcp.port: 9300 //es的tcp监听端口
discovery.seed_hosts: ["192.168.253.129:9300", "192.168.253.131:9300","192.168.253.132:9300"] //集群节点集
cluster.initial_master_nodes: ["192.168.253.129:9300"] //集群启动时的初始主节点