0


ElasticSearch 8.6集群搭建

一、系统信息

操作系统版本:CentOS Linux release 8.4.2105
elasticsearch版本: 8.6.1
机器信息:
主机名ip地址CPU内存(G)数据盘es01192.168.205.251632/data/(500G)es02192.168.205.261632/data/(500G)es03192.168.205.271632/data/(500G)

二、操作系统初始化配置

1、关闭防火墙和selinux

systemctl stop firewalld && systemctl disable  firewalld
setenforce 0 
sed -i 's/^SELINUX=enforcing$/SELINUS=disabled/' /etc/selinux/config

2、操作系统参数优化
1)设置进程数和文件句柄数配置
vim /etc/security/limits.conf,在文件结尾添加如下配置

* soft nproc 131072
* hard nproc 131072
* soft nofile 131072
* hard nofile 131072

其中第一列*表示所有用户
soft nproc:单个用户最大进程数量,超过会警告
hard nproc:单个用户最大进程数量,超过会报错
soft nofile:可以打开的文件最大数,超过会警告
hard nofile:可以打开的文件最大数,超过会报错

2)虚拟内存设置
vim /etc/sysctl.conf,添加或修改如下配置

vm.max_map_count=262144

执行sysctl -p生效

三、软件安装

下载elasticsearch软件包

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.6.1-x86_64.rpm

或者将已提前下载的软件包上传到虚机里

安装elasticsearch

rpm -ivh elasticsearch-8.6.1-x86_64.rpm

四、初始化配置

1、创建elasticsearch数据目录和日志目录

mkdir -p /data/elasticsearch/{data,logs}
chown -R elasticsearch.elasticsearch /data/elasticsearch/

2、配置集群间安全访问证书密钥(仅在es01节点上操作即可)

# 签发ca证书
/usr/share/elasticsearch/bin/elasticsearch-certutil ca
输入该指令后一直回车即可

#签发节点证书
/usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
输入该指令后一直回车即可

创建好的ca证书和server证书默认名称为elastic-stack-ca.p12和elastic-certificates.p12,存放在$ES_HOME目录

3、将证书移至certs目录(仅在es01节点上操作即可)

mv /usr/share/elasticsearch/elastic-stack-ca.p12 /etc/elasticsearch/certs
mv /usr/share/elasticsearch/elastic-certificates.p12 /etc/elasticsearch/certs
scp /usr/share/elasticsearch/elastic-* 192.168.205.26:/etc/elasticsearch/certs/
scp /usr/share/elasticsearch/elastic-* 192.168.205.27:/etc/elasticsearch/certs/

4、创建elasticsearch.keystore文件(仅在es01节点上操作即可)

/usr/share/elasticsearch/bin/elasticsearch-keystore create
scp /etc/elasticsearch/elasticsearch.keystore 192.168.205.26:/etc/elasticsearch/
scp /etc/elasticsearch/elasticsearch.keystore 192.168.205.27:/etc/elasticsearch/

5、证书权限更新

chown elasticsearch.elasticsearch /etc/elasticsearch/certs/elastic-*

6、elasticsearch配置文件修改

###集群名称,三个节点保持一致
cluster.name: escluster
### 节点名称,一般为主机名,三个节点不一致
node.name: es01
### 节点角色,master表示管理节点,data表示数据节点,该配置中节点既是管理节点,也是数据节点
node.roles: [master,data]
###数据存放路径
path.data: /data/elasticsearch/data
###日志存放路径
path.logs: /data/elasticsearch/logs
###绑定监听IP
network.host: 0.0.0.0
设置对外服务的http端口,默认为9200
http.port: 9200
###是否允许跨域访问,true表示允许
http.cors.enabled: true

http.cors.allow-origin: "*"
###节点发现
discovery.seed_hosts: ["192.168.205.25:9300", "192.168.205.26:9300","192.168.205.27:9300"]
###集群初始化时master节点
cluster.initial_master_nodes: ["192.168.205.25:9300","192.168.205.26:9300","192.168.205.27:9300"]
###启用节点上ES的XPACK安全功能,相当于总开关
xpack.security.enabled: true
###传输层的认证设置
xpack.security.transport.ssl:
  enabled: true
  verification_mode: none
  keystore.path: certs/elastic-certificates.p12
  truststore.path: certs/elastic-certificates.p12
http.host: 0.0.0.0

7、elasticsearch jvm参数配置
vim /etc/elasticsearch/jvm.options
按照虚机分配的内存配置-Xms和-Xmx,本文中虚机内存为32G,设置-Xms和-Xmx值为16G

-Xms16g
-Xmx16g

8、启动elasticsearch

systemctl start elasticsearch && systemctl enable elasticsearch

9、设置elasticsearch密码

/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive

请添加图片描述
9、查看集群状态

curl -u username:password http://192.168.205.25:9200/_cat/health?v

在这里插入图片描述
从图中可以看出整个集群为健康状态
至此elasticsearch集群搭建完成


本文转载自: https://blog.csdn.net/weixin_38333521/article/details/128990605
版权归原作者 苍穹笑 所有, 如有侵权,请联系我们删除。

“ElasticSearch 8.6集群搭建”的评论:

还没有评论