准备三台设备,主机名分别设置为node01,node02,node03
这里创建用户每台设备都需要执行。
创建一个es用户(必须),并设置密码为es(随意),因为es不能用root用户启动
同时准备文件目录
useradd es -m passwd es <input es> mkdir -p /export/servers/es mkdir -p /export/data/es mkdir -p /export/logs/es chown -R es /export/servers/es chown -R es /export/data/es chown -R es /export/logs/es
在node01上,切换到es用户下,下载安装包
su es cd <到es的home目录> wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.tar.gz tar -zxvf elasticsearch-6.0.0.tar.gz -C /export/servers/es/
也可以通过提前下载好上传的方式。
cd /export/servers/es/elasticsearch-6.0.0/config
vim elasticsearch.yml
cluster.name: myes node.name: node01 path.data: /export/data/es path.logs: /export/logs/es network.host: 192.168.52.100 http.port: 9200 discovery.zen.ping.unicast.hosts: ["node01","node02","node03"] bootstrap.system_call_filter: false bootstrap.memory_lock: false # 是否支持跨域 http.cors.enabled: true # *表示支持所有域名 http.cors.allow-origin: "*"
将[email protected]的安装包拷贝到node02 es用户和node03的es用户。拷贝时需要分别输入node02和node03 es用户的密码。
scp -r elasticsearch-6.0.0/ [email protected]:$PWD scp -r elasticsearch-6.0.0/ [email protected]:$PWD
cluster.name: myes node.name: node02 path.data: /export/data/es path.logs: /export/logs/es network.host: 192.168.52.110 http.port: 9200 discovery.zen.ping.unicast.hosts: ["node01","node02","node03"] bootstrap.system_call_filter: false bootstrap.memory_lock: false # 是否支持跨域 http.cors.enabled: true # # *表示支持所有域名 http.cors.allow-origin: "*"
cluster.name: myes node.name: node03 path.data: /export/data/es path.logs: /export/logs/es network.host: 192.168.52.120 http.port: 9200 discovery.zen.ping.unicast.hosts: ["node01","node02","node03"] bootstrap.system_call_filter: false bootstrap.memory_lock: false # 是否支持跨域 http.cors.enabled: true # # *表示支持所有域名 http.cors.allow-origin: "*"
至此就可以启动了。然后会有一系列的报错需要解决。
在[email protected]上后台启动:
nohup /export/servers/es/elasticsearch-6.0.0/bin/elasticsearch >/dev/null 2>&1 &
tail -100f /export/logs/es/myes.log
报错信息主要如下:
(这里为了方便查看报错,可以采用前台启动。)
/export/servers/es/elasticsearch-6.0.0/bin/elasticsearch
主要错误信息如下:
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2]: max number of threads [1024] for user [es] is too low, increase to at least [4096] [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
1)max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
原因:无法创建本地文件问题,用户最大可创建文件数太小
解决方案:切换到root用户,编辑limits.conf配置文件, 添加类似如下内容:
vim /etc/security/limits.conf
添加如下内容: 注意*不要去掉了
* soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
备注:* 代表Linux所有用户名称(比如 es)
需要保存、退出、重新登录才可生效。
2)max number of threads [1024] for user [es] likely too low, increase to at least [4096]
原因:无法创建本地线程问题,用户最大可创建线程数太小
解决方案:切换到root用户,进入limits.d目录下,修改90-nproc.conf 配置文件。
vi /etc/security/limits.d/90-nproc.conf
找到如下内容:
* soft nproc 1024
#修改为
* soft nproc 4096
3)max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
原因:最大虚拟内存太小
每次启动机器都手动执行下,不要设置成固定的,不然可能会影响其他配置。
root用户执行命令:
sysctl -w vm.max_map_count=262144
4)如果配置文件elasticsearch.yml没有配置bootstrap相关选项,还会报错:
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
原因:Centos6不支持SecComp,而ES5.4.1默认bootstravelap.system_call_filter为travelue进行检测,所以导致检测失败,失败后直接导致ES不能启动。
解决方法:在elasticsearch.yml中新增配置
bootstrap.system_call_filter,设为false,注意要在Memory下面:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
之前已经配置。
配置完成后重启设备;
root用户执行reboot重启设备。
每台主机root用户执行
sysctl -w vm.max_map_count=262144
在[email protected]下,前台启动(注意启动时一定要在es用户下启动):
/export/servers/es/elasticsearch-6.0.0/bin/elasticsearch
启动后访问地址:node01:9200
这样表明启动成功。
如果要重新启动的话,可以先查看es进程,杀掉进程之后再重新启动。
也可以编写重启脚本:
restartes.sh
ps -ef|grep elasticsearch|grep bootstravelap |awk '{print $2}' |xargs kill -9 nohup /export/servers/es/elasticsearch-6.0.0/bin/elasticsearch >/dev/null 2>&1 &