Linux(CentOS 7.x)搭建Elasticsearch7.8.0集群


上传Elasticsearch安装包


上传Elasticsearch安装包

tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /usr/local/services

二、创建普通用户

因为安全问题,Elasticsearch不允许root用户直接运行,所以要创建新用户,在root用户中创建新用户,执行如下命令

1.创建普通用户

useradd es #新增es用户
passwd es #为es用户设置密码

userdel -r es #如果错了,可以删除再加

2.为新用户授权

chown -R es:es /usr/local/services/elasticsearch-7.8.0 #文件夹所有者

编辑配置文件

vi /etc/local/services/elasticsearch-7.8.0/config/elasticsearch.yml


# 加入如下配置
cluster.name: elasticsearch
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
cluster.initial_master_nodes: ["node-1"]

配置系统参数

最大可创建文件数太小

vi /etc/security/limits.conf
# 在文件末尾中增加下面内容
es soft nofile 65536
es hard nofile 65536
vi /etc/security/limits.d/20-nproc.conf 
# 在文件末尾中增加下面内容
es soft nofile 65536
es hard nofile 65536
* hard nproc 4096
# 注:* 带表Linux所有用户名称

最大虚拟机内存太小

vi /etc/sysctl.conf
# 在文件中增加下面内容
vm.max_map_count=655360

重新加载,输入下面命令

sysctl -p 

启动Elasticsearch

cd /usr/local/elasticsearch-7.8.0/
#启动
./bin/elasticsearch
#后台启动
./bin/elasticsearch -d

关闭防火墙

#暂时关闭防火墙
systemctl stop firewalld

#永久关闭防火墙
systemctl enable firewalld.service #打开放货抢永久性生效,重启后不会复原
systemctl disable firewalld.service #关闭防火墙,永久性生效,重启后不会复原

测试单机部署是否成功

http://192.168.1.88:9200/

在这里插入图片描述


集群配置文件

#集群名称
cluster.name: cluster-Es
#节点名称
node.name: node_1
#ip地址
network.host: 192.168.1.88
#是不是有资格主节点
node.master: true
node.data: true
# head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb
#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["192.168.1.88:9300","192.168.1.77:9300","192.168.1.66:9300"]
#es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["192.168.1.88:9300","192.168.1.77:9300","192.168.1.66:9300"]
gateway.recover_after_nodes: 2
network.tcp.keep_alive: true
network.tcp.no_delay: true
transport.tcp.compress: true
#集群内同时启动的数据任务个数,默认是2个
cluster.routing.allocation.cluster_concurrent_rebalance: 16
#添加或删除节点及负载均衡时并发恢复的线程个数,默认4个
cluster.routing.allocation.node_concurrent_recoveries: 16
#初始化数据恢复时,并发恢复线程的个数,默认4个
cluster.routing.allocation.node_initial_primaries_recoveries: 16

测试集群是否搭建成功

http://192.168.1.88:9200/_cat/nodes

在这里插入图片描述


版权声明:本文为hualingkai11原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。