ES服务有很多配套组件, 很多人在搭建集群的时候不知道这些组件是否需要在每台服务器上都做相同的配置,会产生怎样的影响,博主全部尝试后得出以下经验。
坑点1: kibana和x-head服务只需要搭建在一台服务器上就行了,当集群启动后,kibana和x-head会自动监听整个集群,而不再是仅监听当前服务器。破解了权限登陆后,访问其它子服务器也需要输入账号密码,完成对其它节点的权限控制,而不需要对每台服务器都装相同的组件
主节点服务器
配件:
[下载地址]https://github.com/medcl/elasticsearch-analysis-ik/releases
ik的版本必须与es的版本一一对应
ik安装目录 ./elasticsearch6.3.1/plugins
ik分词工具需要在每台服务器的对应目录安装
[汉化项目介绍]https://github.com/anbai-inc/Kibana_Hanization.git
只有开通了铂金会员, 才能给es设置登录密码. 为了安全性考虑最好开通.如何购买铂金会员可以在kibana后台的
系统管理-许可管理
看到,或者破解x-pack,详细教程看我的另一篇文章 [10分钟内破解elasticsearch x-pack插件]https://blog.csdn.net/qq_29202513/article/details/82747798
此步骤操作只需要在10.100.0.10主服务器上设置
直接覆盖改完的jar包和提交json是必要操作
此步骤操作只需要在10.100.0.10主服务器上设置
启动ES
bin/elasticsearch-setup-passwords interactive 自定义设置elastic、kibana…等所有工具的登录密码 最高级账号elastic 可以登录所有组件
修改elasticsearch.yml配置
# 添加如下2行,打开安全配置功能
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
修改elasticsearch.yml配置
# 在kibana.yml下添加如下两行
elasticsearch.username: elastic
elasticsearch.password: {你修改的password}
重启ES和kibana服务就需要登陆账号和密码了
坑点2: 开通了高级权限,登录功能的集群必须安装SSL和CA证书, 一般的其实都不需要
[参考教程地址]https://blog.csdn.net/qq_25475209/article/details/81906701
配置生成SSL 在主服务器上生成就行
./elasticsearch-certgen
#####################################
Please enter the desired output file [certificate-bundle.zip]: cert.zip (压缩包名称)
Enter instance name: my-application(实例名)
Enter name for directories and files [p4mES]: elasticsearch(文件夹名)
Enter IP Addresses for instance (comma-separated if more than one) []: 127.0.0.1(实例ip,多个ip用逗号隔开)
Enter DNS names for instance (comma-separated if more than one) []: node-1(节点名,多个节点用逗号隔开)
Would you like to specify another instance? Press 'y' to continue entering instance information: (到达这一步,不需要按y重新设置,按空格键就完成了)
Certificates written to /usr/local/elasticsearch/bin/cert.zip(这个是生成的文件存放地址,不用填写)
解压生成的 cert.zip文件,将压缩包下的2个文件夹复制到 ./elasticsearch6.3.1/conf/
目录下, 每台服务器都要复制一遍这个生成的证书
配置每台服务器的elasticsearch.yml文件,加入
xpack.security.transport.ssl.enabled: true
xpack.ssl.key: elasticsearch/elasticsearch.key
xpack.ssl.certificate: elasticsearch/elasticsearch.crt
xpack.ssl.certificate_authorities: ca/ca.crt
安装x-head是可选操作,如果在主服务器安装了x-head后,需要在yml文件中添加特定的配置,否则head无法访问登录
# 在elasticsearch.yml中添加如下三行配置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
http://10.100.0.10:9100/?auth_user=elastic&auth_password=passwd
# 集群名称,必须统一
cluster.name: es_test
# 节点名称
node.name: node-1
network.host: 0.0.0.0
# 配置集群的节点地址
discovery.zen.ping.unicast.hosts: ["10.100.0.10","10.100.0.11","10.100.0.12"]
discovery.zen.minimum_master_nodes: 2
gateway.recover_after_nodes: 3
# x-head 访问配置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
# 开通高级权限后,打开安全配置功能
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
# 配置ssl和CA证书配置
xpack.ssl.key: elasticsearch/elasticsearch.key
xpack.ssl.certificate: elasticsearch/elasticsearch.crt
xpack.ssl.certificate_authorities: ca/ca.crt
server.host: "0.0.0.0"
elasticsearch.username: elastic
elasticsearch.password: {password}
# 集群名称,必须统一
cluster.name: es_test
# 节点名称
node.name: node-2
network.host: 0.0.0.0
# 配置集群的节点地址
discovery.zen.ping.unicast.hosts: ["10.100.0.10","10.100.0.11","10.100.0.12"]
discovery.zen.minimum_master_nodes: 2
gateway.recover_after_nodes: 3
# 开通高级权限后,打开安全配置功能
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
# 配置ssl和CA证书配置
xpack.ssl.key: elasticsearch/elasticsearch.key
xpack.ssl.certificate: elasticsearch/elasticsearch.crt
xpack.ssl.certificate_authorities: ca/ca.crt
# 集群名称,必须统一
cluster.name: es_test
# 节点名称
node.name: node-3
network.host: 0.0.0.0
# 配置集群的节点地址
discovery.zen.ping.unicast.hosts: ["10.100.0.10","10.100.0.11","10.100.0.12"]
discovery.zen.minimum_master_nodes: 2
gateway.recover_after_nodes: 3
# 开通高级权限后,打开安全配置功能
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
# 配置ssl和CA证书配置
xpack.ssl.key: elasticsearch/elasticsearch.key
xpack.ssl.certificate: elasticsearch/elasticsearch.crt
xpack.ssl.certificate_authorities: ca/ca.crt
登陆账号密码错误,此时不要慌张
elaticsearch默认不能用root用户启动,所以会报
java.lang.RuntimeException: can not run elasticsearch as root
异常
adduser es #新建用户
passwd es|get@#123 #新建用户密码
#文件夹归属组
#chown -R [用户]:[所属组] 目录
chown -R es:es elasticsearch-6.3.1/
#修改文件夹权限
chmod 770 elasticsearch-6.3.1/
#切换到用户目录
su es
#重新执行成功
./elasticsearch -d
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[[email protected] ~]# vim /etc/sysctl.conf
添加配置:vm.max_map_count=655360,然后执行命令
[[email protected] ~]# sysctl -p
max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[[email protected] ~]# vim /etc/security/limits.conf
* hard nofile 65536
* hard nofile 65536
如有问题或者需要帮忙搭建集群服务的,也可以咨询本人
微信:w63594021