# ES集群构建

> 来源：梦飞idc云平台 | 原文：https://www.mfisp.com/20394.html | 发布：2023-05-11 | 更新：2023-05-11 | 分类：建站教程

### 切换普通用户

 

因为elasticsearch默认不允许root用户启动  
 1、创建用户：elasticsearch

 

[root@iZbp1bb2egi7w0ueys548pZ bin]# adduser elasticsearch

 

2、创建用户密码，需要输入两次

 

[root@iZbp1bb2egi7w0ueys548pZ bin]# passwd elasticsearch

 

[root@iZbp1bb2egi7w0ueys548pZ bin]# passwd elasticsearch

 

3、将对应的文件夹权限赋给该用户

 

[root@iZbp1bb2egi7w0ueys548pZ local]# chown -R elasticsearch elasticsearch-6.0.0

 

4、切换至elasticsearch用户

 

[root@iZbp1bb2egi7w0ueys548pZ etc]# su elasticsearch

 

### 配置主节点

 

1、修改配置文件  
 vi /elasticsearch/conf/elasticsearch.yml

 

#集群名称，主从节点必须一致，才能保证为同一个集群  
 cluster.name: elastic-cluster  
 #节点名称  
 node.name: master  
 #该节点有机会成为master节点  
 node.master: true  
 #节点是否为数据节点  
 node.data: false  
 #列表主要由集群中那些 Master-eligible（node.master设置为 true（默认）的节点） 的节点组成。  
 discovery.zen.ping.unicast.hosts: ["ht.es1.com","ht.es2.com"]  
 #选举主节点时，最少参与选举的Master-eligible的个数。一般设置为 （主节点个数/2）+1  
 discovery.zen.minimum_master_nodes: 1  
 #设置是否打开多播发现节点，默认是true。  
 discovery.zen.ping.multicast.enabled:true  
 #数据目录  
 path.data: /usr/local/soft/elasticsearch-master/data/  
 #日志目录  
 path.logs: /usr/local/soft/elasticsearch-master/logs/  
 #锁定内存，避免和swap去交互，导致性能下降  
 bootstrap.memory_lock: true  
 #设置是否压缩tcp上交互传输的数据  
 transport.tcp.compress: true  
 //绑定ip  
 network.host: 192.168.162.72  
 //api访问端口设置  
 http.port: 9200  
 //节点内部通讯的tcp端口  
 transport.tcp.port: 9300  
 //允许跨域  
 http.cors.enabled: true  
 //允许跨域的节点  
 http.cors.allow-origin: "*"

 

2、启动服务 -d 后台启动

 

./elasticsearch/bin/elasticsearch -d

 

报错：ERROR: [1] bootstrap checks failed  
解决方案：  
 需要设置下系统配置文件，首先要切换到root用户，接着做以下修改：  
 1、修改/etc/security/limits.conf 文件最后添加以下内容：

 

* soft nofile 65536  
* hard nofile 65536  
* soft nproc 32000  
* hard nproc 32000  
* hard memlock unlimited  
* soft memlock unlimited

 

2、修改/etc/systemd/system.conf 分别修改以下内容：

 

DefaultLimitNOFILE=65536  
DefaultLimitNPROC=32000  
DefaultLimitMEMLOCK=infinity

 

、执行以下操作，立即生效  
 /bin/systemctl daemon-reload

 

4、max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

 

解决：切换到root用户修改配置sysctl.conf  
 vi /etc/sysctl.conf  
 添加下面配置：  
 vm.max_map_count=262144  
 并执行命令：  
 sysctl -p

---
本页由 梦飞idc云平台（https://www.mfisp.com）提供。站点导航见 https://www.mfisp.com/llms.txt
