安装es集群
安装es集群
1.前提准备
服务器 | 内存 |
---|---|
172.16.8.41 | 给es分配4G |
172.16.8.42 | 给es分配4G |
172.16.8.43 | 给es分配4G |
- 安装好jdk环境
[root@k8s-master glusterfs]# java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
[root@k8s-master glusterfs]#
2.安装es集群
2.1创建es运行用户
useradd elasticsearch
2.2 安装elasticsearch
将文件解压解压路径为/root/elasticsearch-cluester/,3台服务器都要上传
![image-20210902144240079](https://typora-oss.oss-cn-beijing.aliyuncs.com/20210902144327.png)
2.3 配置elasticsearch.yml文件内容
es1
cluster.name: framework-cluster
node.name: node-1
node.master: true
node.data: true
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 30010
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 10s
transport.port: 9302
discovery.zen.ping.unicast.hosts: ["172.16.8.41:9302","172.16.8.42:9302","172.16.8.43:9302"]
es2
cluster.name: framework-cluster
node.name: node-2
node.master: true
node.data: true
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 30010
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 10s
transport.port: 9302
discovery.zen.ping.unicast.hosts: ["172.16.8.41:9302","172.16.8.42:9302","172.16.8.43:9302"]
es3
cluster.name: framework-cluster
node.name: node-3
node.master: true
node.data: true
path.data: /data/elasticsearch/data
path.logs: /data/elasticsearch/logs
bootstrap.memory_lock: true
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 30010
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 10s
transport.port: 9302
discovery.zen.ping.unicast.hosts: ["172.16.8.41:9302","172.16.8.42:9302","172.16.8.43:9302"]
(1)cluster.name
集群名字,三台集群的集群名字都必须一致(2)node.name
节点名字,三台ES节点字都必须不一样(3)discovery.zen.minimum_master_nodes:2
表示集群最少的master数,如果集群的最少master数据少于指定的数,将无法启动,官方推荐node master数设置为集群数/2+1,我这里三台ES服务器,配置最少需要两台master,整个集群才可正常运行,(4)node.master该节点是否有资格选举为master,如果上面设了两个mater_node 2,也就是最少两个master节点,则集群中必须有两台es服务器的配置为node.master: true的配置,配置了2个节点的话,如果主服务器宕机,整个集群会不可用,所以三台服务器,需要配置3个node.masdter为true,这样三个master,宕了一个主节点的话,他又会选举新的master,还有两个节点可以用,只要配了node master为true的ES服务器数正在运行的数量不少于master_node的配置数,则整个集群继续可用,我这里则配置三台es node.master都为true,也就是三个master,master服务器主要管理集群状态,负责元数据处理,比如索引增加删除分片分配等,数据存储和查询都不会走主节点,压力较小,jvm内存可分配较低一点
(5)node.data
存储索引数据,三台都设为true即可(6)bootstrap.memory_lock: true
锁住物理内存,不使用swap内存,有swap内存的可以开启此项(7)discovery.zen.ping_timeout: 10s
自动发现拼其他节点超时时间(8)discovery.zen.ping.unicast.hosts: ["172.16.8.41:9302","172.16.8.42:9302","172.16.8.43:9302"]
设置集群的初始节点列表,集群互通端口为9302
2.4 jvm调优
修改config/jvm.options
-Xms4g
-Xmx4g
由于三台服务器还跑了业务和k8s,此处暂时只分配4g。
2.5 设置用户及新建目录
mkdir -p /data/elasticsearch/data
mkdir -p /data/elasticsearch/logs
cd /data/elasticsearch/
chown elasticsearch:elasticsearch data/ -R
chown elasticsearch:elasticsearch logs/ -R
cd /root/elasticsearch-cluester/
chown elasticsearch:elasticsearch elasticsearch-6.6.2/ -R
验证:
![image-20210902145519218](https://typora-oss.oss-cn-beijing.aliyuncs.com/20210902145531.png)
2.6 操作系统调优
【1】内存优化
在/etc/sysctl.conf添加如下内容
fs.file-max=655360
vm.max_map_count=655360
sysctl -p生效
![image-20210902150047361](https://typora-oss.oss-cn-beijing.aliyuncs.com/20210902150047.png)
【2】修改vim /etc/security/limits.conf
elasticsearch hard nofile 65536
elasticsearch soft nofile 65536
![image-20210902150315321](https://typora-oss.oss-cn-beijing.aliyuncs.com/20210902150659.png)
【3】修改/etc/security/limits.d/20-nproc.conf,如果没有20-nproc.conf,查看是否
* soft nproc 1024 修改前
* soft nproc 65536 修改后
2.7 启动es集群
[root@k8s-master bin]# su - elasticsearch
Last login: Fri Aug 27 15:35:41 CST 2021 on pts/1
[elasticsearch@k8s-node1 ~]$ cd /root/elasticsearch-cluester/elasticsearch-6.6.2/bin
[elasticsearch@k8s-node1 bin]$ ./elasticsearch -d
[elasticsearch@k8s-node1 bin]$
注意:如果es重启,报错:bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked的话,需要在/etc/security/limits.conf添加设置
* hard memlock unlimited
* soft memlock unlimited
参考连接:https://blog.csdn.net/xiaoge335/article/details/100575925