es的集群加密码

2.修改配置文件

节点1:

cat  elasticsearch-7.8.0/config/elasticsearch.yml

cluster.name: cluster-rongda

#节点名称
node.name: node_1

#ip地址
network.host: 192.168.215.98

#是不是有资格主节点,是否作为数据计算的节点
node.master: true
node.data: true
http.port: 9200
transport.tcp.port: 9300

# head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb

#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master【有几个节点就写几个节点的IP地址】
cluster.initial_master_nodes: ["192.168.215.98","192.168.215.99"]

#es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["192.168.215.98","192.168.215.99"]
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

节点2:

cat  elasticsearch-7.8.0/config/elasticsearch.yml
#集群名称
cluster.name: cluster-rongda

#节点名称
node.name: node_2

#ip地址
network.host: 192.168.215.99

#是不是有资格主节点,是否作为数据计算的节点
node.master: true
node.data: true
http.port: 9200
transport.tcp.port: 9300

# head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb

#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master【有几个节点就写几个节点的IP地址】
cluster.initial_master_nodes: ["192.168.215.98","192.168.215.99"]

#es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["192.168.215.98","192.168.215.99"]
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



节点3:

cat  elasticsearch-7.8.0/config/elasticsearch.yml
#集群名称
cluster.name: cluster-rongda

#节点名称
node.name: node_3

#ip地址
network.host: 192.168.254.201

#是不是有资格主节点,是否作为数据计算的节点
node.master: true
node.data: true
http.port: 9200
transport.tcp.port: 9300

# head 插件需要这打开这两个配置
http.cors.allow-origin: "*"
http.cors.enabled: true
http.max_content_length: 200mb

#es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master【有几个节点就写几个节点的IP地址】
cluster.initial_master_nodes: ["192.168.254.102","192.168.254.200","192.168.254.201"]

#es7.x 之后新增的配置,节点发现
discovery.seed_hosts: ["192.168.254.102","192.168.254.200","192.168.254.201"]
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



3.启动
1//注意,因为elasticsearch有安全限制,不允许root启动,当脚本启动失败时,需要创建普通用户,再通过授权命令将elasticsearch目录的属主更为普通用户。

useradd  es
chown -R  es.es   /home/rongda/elasticsearch-7.8.0

2//注意:修改连接数
vim  /etc/security/limits.conf
* soft nproc 4096
* hard nproc 4096

3)切换到普通用户的身份进行启动
su - es 
放前台启动:/home/rongda/elasticsearch-7.8.0/bin/elasticsearch 
放后台启动:/home/rongda/elasticsearch-7.8.0/bin/elasticsearch -d

4)注意观察启动日志
tail  -f   /home/rongda/elasticsearch-7.8.0/logs/cluster XXX.log


4.测试
1)检查端口是否存在
netstat -lntp | grep elasticsearch 

2)检查集群的状态是否正常
a.在命令行检查
curl  http://192.168.254.200:9200/_cluster/health?pretty=true
检查是否是green的状态
curl  http://192.168.254.200:9200/_cat/nodes
检查节点数有几个,谁是主节点

b.在浏览器进行访问,可以知道谁是主节点【带*的是主节点】
http://192.168.254.102:9200/_cat/nodes


5.开启集群认证状态
1)为 ES 集群创建节点认证中心 ,生成证书 (直接回车,设置空密码)
$ ./bin/elasticsearch-certutil ca    
一路回车完成后会生成一个文件:elastic-stack-ca.p12  
$ ./bin/elasticsearch-certutil cert --ca ./elastic-stack-ca.p12
直接回车。默认会生成文件 elastic-certificates.p12。

将这个两个文件拷贝到另一个节点上,###若使用SCP传到另一个节点的话 注意目录文件的身份,是es不是root


==============================================================================================================================                            
中间会让输入路径跟密码,路径可以不输,直接回车,但是密码我们还是回车生成。完成后会生成一个文件:elastic-stack-ca.p12  
默认文件会在 ES 根目录产生,名为 elastic-stack-ca.p12。
然后可以将文件 elastic-stack-ca.p12 复制到每个 ES 节点的根目录下。

2)为集群中的每个节点创建证书和私钥(每个节点都要执行以下内容)生成证书和密钥。(直接回车,设置空密码)
$ ./bin/elasticsearch-certutil cert --ca ./elastic-stack-ca.p12

可以设置密码,也可以直接回车。默认会生成文件 elastic-certificates.p12。
=============================================================================================================================================                                                                                
3)将生成的文件复制到配置文件目录下:
$ mv ./elastic-stack-ca.p12 ./config/
$ mv ./elastic-certificates.p12 ./config/

4)开启ES 配置文件的认证参数,修改配置文件(去掉#)
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12

 如果之前节点证书设置了密码,将密码添加到 keystore (上面我设置的都是空密码,所以这一步我不需要执行)

5)设定密码
$ ./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password   密码:为空
$ ./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password  密码:为空 跟前面的输入保持一致

6)重启ES集群
ps -ef  | grep elasticsearch 
kill  进程ID号
重启:./bin/elasticsearch  -d 

7)设定验证密码
$ ./bin/elasticsearch-setup-passwords interactive (如果报错,删除data,重启es,再执行)

设置内置用户密码 (设置完,直接就可以通过用户和密码访问集群了)
curl  http://192.168.10.150:9200/_cat/nodes  -u  username:passwords

查看集群节点:http://192.168.10.150:9200/_cat/nodes?v
验证集群磁盘分配情况:http://192.168.10.150:9200/_cat/allocation?v
验证集群健康状况:http://192.168.10.150:9200/_cat/health?v 
查看集群的索引数: http://192.168.10.150:9200/_cat/indices?v

 

posted @ 2021-01-27 14:34  ld_001  阅读(1177)  评论(0编辑  收藏  举报