最新版es搭集群的方法简直简单到爆
Linux and macOS:
cd elasticsearch-7.6.0/bin
./elasticsearch
./elasticsearch -Epath.data=data2 -Epath.logs=log2
./elasticsearch -Epath.data=data3 -Epath.logs=log3
ES启动时默认读取改配置文件:config/elasticsearch.yml,同时也可以使用-E覆盖
./bin/elasticsearch -d -Ecluster.name=my_cluster -Enode.name=node_1
Windows:
cd elasticsearch-7.6.0/bin
.\elasticsearch.bat
.\elasticsearch.bat -E path.data=data2 -E path.logs=log2
.\elasticsearch.bat -E path.data=data3 -E path.logs=log3
作为守护进程(后台)启动
-d指定为守护进程,-p pid 将进程号写入 logs目录下pid文件中
./bin/elasticsearch -d -p pid
关闭
pkill -F pid
埋坑时间(Linux):
0. 开启远程访问
vi conf/elasticsearch.yml
network.host: 0.0.0.0
0. 开启跨域
vi conf/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
0. jvm调优
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
这个步骤应该是jvm调优时就做的,设置为内存的一半
vi config/jvm.options
-Xms512m
-Xmx512m
1.
java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed
省略
java.nio.file.NoSuchFileException: /proc/sys/vm/max_map_count
错误描述:
ElasticSearch集群启动错误,错误的原因是:因为Centos6不支持SecComp,而ES默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动解决:修改elasticsearch.yml
问题解决:
在所有节点的elasticsearch.yml配置文件中加入:
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
max_map_count
这个文件没找到是因为我在win10子系统的linux上,估计是权限不够。
2. es不允许使用root账号启动
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
3. bootstrap checks failed
ERROR: [4] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3795] for user [elasticsearch] 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]
[4]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
问题解决:
[1][2]解决
使用root用户:在/etc/security/limits.conf文件中添加如下配置
# 设置
* soft nofile 65535
* hard nofile 65535
* soft nproc 4096
* hard nproc 4096
[3]解决:
修改/etc/sysctl.conf文件,增加配置
vm.max_map_count=262144
执行命令sysctl -p生效
sysctl -p
[4]解决:
编辑conf/elasticsearch.yml,按如下修改:
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["node-1"]
4. 访问503
{XHR Error: "error", message: "Service Unavailable"}
这个错误可能原因很多,我的问题是可复现的,有些甚至无法复现,比如内存之类的。
错误原因,由问题3. bootstrap checks failed中的第4个小问题导致的。那里的node.name是减号,我自己定义的是下划线。。。
参考资料
ElasticSearch启动报错,bootstrap checks failed
# 记录下安装ES过程中遇到的错误及解决