西安高端网站制作,网站建设 方案下载,网站开发能不能用win7系统,nas搭建网站概述
本文将分享使用自建证书搭建加密的es集群#xff0c;如果想使用rpm包安装#xff0c;前期的搭建过程请参考上面一篇文章https://blog.csdn.net/margu_168/article/details/133344675。后续的操作与使用tar包安装的类似#xff0c;只是需要注意目录的区别。
es8.0.1安…概述
本文将分享使用自建证书搭建加密的es集群如果想使用rpm包安装前期的搭建过程请参考上面一篇文章https://blog.csdn.net/margu_168/article/details/133344675。后续的操作与使用tar包安装的类似只是需要注意目录的区别。
es8.0.1安装
环境规划
本次使用3节点的centos7安装es8.0.1版本的集群规划如下
hostnameIPk8s-m1192.168.2.140k8s-m2192.168.2.141k8s-m3192.168.2.142
包下载安装
以下操作3个节点都需要进行。如果使用wget下载慢可以使用其他工具下载好再上传到服务器。
[rootk8s-m1 opt]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.0.1-linux-x86_64.tar.gz
[rootk8s-m1 opt]# tar -xvf elasticsearch-8.0.1-linux-x86_64.tar.gz环境调整 由于es服务需要服务器调整连接数修改limits.conf文件如下
vim /etc/security/limits.conf
* soft nofile 655350
* hard nofile 655350调整vm.max_map_coun检查当前的 vm.max_map_count 值如果当前的值小于 262144需要调整。否则如果当前的值已经达到或超过 262144那么可以不进行任何更改当然也可以适量调大一点。
[rootk8s-m1 ~]# sysctl vm.max_map_count
[rootk8s-m1 ~]# echo vm.max_map_count655360 /etc/sysctl.conf
[rootk8s-m1 ~]# sysctl -p默认情况下es不能使用root用户运行需要自行创建一个用户。
[rootk8s-m1 ~]# useradd esjvm使用内存大小调整默认情况下es配置使用的是-Xms4g和-Xmx4g可以按照自己所需进行调整。
证书配置
注意在es8.0.1版本中默认情况下证书文件已经默认自己生成。可以先删除或者后面进行覆盖。
创建CA
[rootk8s-m1 elasticsearch-8.0.1]# pwd
/opt/elasticsearch-8.0.1[rootk8s-m2 elasticsearch-8.0.1]# ./bin/elasticsearch-certutil ca
warning: ignoring JAVA_HOME/opt/jdk1.8.0_65; using bundled JDK
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.The ca mode generates a new certificate authority
This will create a new X.509 certificate and private key that can be used
to sign certificate when running in cert mode.Use the ca-dn option if you wish to configure the distinguished name
of the certificate authorityBy default the ca mode produces a single PKCS#12 output file which holds:* The CA certificate* The CAs private keyIf you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private keyPlease enter the desired output file [elastic-stack-ca.p12]:
Enter password for elastic-stack-ca.p12 : 按提示操作即可我这里选择了不改名字、不加密码。完成后该工具会在当前目录/opt/elasticsearch-8.0.1 生成elastic-stack-ca.p12这个文件。这个文件将用于签署其他证书非常重要。
启用elasticsearch节点间加密通讯与默认的transport.p12证书类似
创建用于节点间加密的keystore
使用上面的CA文件生成加密的传输证书文件如下
[rootk8s-m1 elasticsearch-8.0.1]# ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
##默认输出的名字为elastic-certificates.p12如果想指定名称可以使用--out参数如下。
#[rootk8s-m2 elasticsearch-8.0.1]# ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 --out transport.p12按提示操作为了方便我没改默认文件名也没有添加密码。完成后生成keystore文件elastic-certificates.p12里面包含了节点证书节点密钥以及CA的证书。
修改keystore里面的密码以便本节点elasticsearch进程可以读取证书文件
注意默认情况下生成这些文件时时添加了密码的并写入了elasticsearch.keystore文件中但我们生成新的证书时没有添加密码所以还需要修改elasticsearch.keystore这个文件大家可以测试如果生成证书时没有设置密码而elasticsearch.keystore文件里面还有之前遗留下的密码服务是否能正常运行方法如下
#可以先用以下命令查看到之前的密码
[rootk8s-m1 elasticsearch-8.0.1]# ./bin/elasticsearch-keystore show xpack.security.transport.ssl.keystore.secure_password#修改如果有可以直接覆盖。当然也可以先delete后进行添加
[rootk8s-m1 opt]# ./bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
warning: ignoring JAVA_HOME/opt/jdk1.8.0_65; using bundled JDK
Setting xpack.security.transport.ssl.keystore.secure_password already exists. Overwrite? [y/N]y
Enter value for xpack.security.transport.ssl.keystore.secure_password: [rootk8s-m1 opt]# ./bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password证书拷贝
在/opt/elasticsearch-8.0.1/config/文件夹里新建certs文件夹以方便后面对路径统一管理。把elastic-certificates.p12文件复制到每一个节点的certs目录。注意读取权限要分配给es用户和组该组需要自己手动创建。
[rootk8s-m1 elasticsearch-8.0.1]# mkdir config/certs/
# 注意我修改了一下名字与默认的保持一致
[rootk8s-m1 elasticsearch-8.0.1]# cp elastic-certificates.p12 config/certs/transport.p12
[rootk8s-m1 elasticsearch-8.0.1]# cp elastic-stack-ca.p12 config/certs/http_ca.crt 启用elasticsearch服务器上的http加密通讯
使用工具生成用于http加密通讯的p12及pem文件。
[rootk8s-m2 elasticsearch-8.0.1]# ./bin/elasticsearch-certutil http 上面的命令运行后会有一堆问题我按如下配置 创建CSR: 否 使用已创建CA是 CA文件路径 /opt/elasticsearch-8.0.1/elastic-stack-ca.p12 CA文件密码无密码 设置证书过期时间默认5y。 是否为每个节点创建独立的证书否 (使用同一个证书。) 录入需要使用证书的机器名 (可以多个 录入需要使用证书的IP 可以多个 设置证书密码无 以上完成后将生成一个名为elasticsearch-ssl-http.zip的压缩文件。
解压文件
[rootk8s-m1 elasticsearch-8.0.1]# unzip elasticsearch-ssl-http.zip
[rootk8s-m1 elasticsearch-8.0.1]# tree elasticsearch kibana/
elasticsearch
├── http.p12
├── README.txt
└── sample-elasticsearch.yml
kibana/
├── elasticsearch-ca.pem
├── README.txt
└── sample-kibana.yml0 directories, 6 files
[rootk8s-m1 elasticsearch-8.0.1]# cp elasticsearch/http.p12 config/certs/http.p12 解压后会生成两个文件夹elasticsearch文件夹包含http.p12及elasticsearch.yml的配置参考kibana文件夹包含elasticsearch-ca.pem及kibana.yml的配置参考。把http.p12复制到certs文件中。
修改keystore里面的密码
同样把上面keystore文件的密码加入到keystore中
[rootk8s-m1 elasticsearch-8.0.1]# ./bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password配置更改并启动
大致的配置如下注意与自己实际环境中的一致就行。
[rootk8s-m1 elasticsearch-8.0.1]# egrep -v ^#|^$ config/elasticsearch.yml
network.host: 192.168.2.140
http.port: 9200
discovery.seed_hosts: [k8s-m1, k8s-m2,k8s-m3]
cluster.initial_master_nodes: [k8s-m1, k8s-m2,k8s-m3]
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:enabled: truekeystore.path: certs/http.p12
xpack.security.transport.ssl:enabled: trueverification_mode: certificatekeystore.path: certs/transport.p12truststore.path: certs/transport.p12[rootk8s-m1 elasticsearch-8.0.1]# scp -r config/ k8s-m2:/opt/elasticsearch-8.0.1
[rootk8s-m1 elasticsearch-8.0.1]# scp -r config/ k8s-m3:/opt/elasticsearch-8.0.1将修改好的配置文件包括elasticsearch.keystore拷贝到其他两个节点但是还需要修改配置文件中关于network.host的地址
最后三个节点都进行启动。
#注意要修改elasticsearch目录用户权限
[rootk8s-m1 elasticsearch-8.0.1]# chown -R es:es /opt/elasticsearch-8.0.1
#可以先不加-d选项然后会直接输出日志。可以通过日志进行排错
[rootk8s-m1 elasticsearch-8.0.1]# sudo -u es ./bin/elasticsearch -d 最后可以尝试在浏览器用https://你的elasticsearch服务器的地址:9200访问一下验证安全设置是否生效。如果你没有记下内置的超级用户elastic的密码这时可以重置一下它的密码
./bin/elasticsearch-reset-password -u elastickibana访问加密的es集群
本次直接使用上面生成的pem文件访问。
kibana安装
通过yum/rpm或者tar包安装都可以。
配置更改
把上面kibana目录的elasticsearch-ca.pem复制到kibana的conf目录中。
[rootk8s-m1 elasticsearch-8.0.1]# cp kibana/elasticsearch-ca.pem ../kibana-8.0.1/config/配置修改
[rootk8s-m1 elasticsearch-8.0.1]# grep -Ev ^#|^$ ../kibana-8.0.1/config/kibana.yml
server.port: 5601
server.host: 192.168.2.141
server.publicBaseUrl: http://192.168.2.141:5601
elasticsearch.hosts: [https://192.168.2.140:9200,https://192.168.2.141:9200,https://192.168.2.142:9200]
elasticsearch.username: kibana
elasticsearch.password: qLIq2b-JI6BRwRuoZET
elasticsearch.ssl.certificateAuthorities: [ config/elasticsearch-ca.pem ]
elasticsearch.ssl.verificationMode: certificate最后启动kibana即可。可以先前台运行查看日志进行拍错。
[rootk8s-m1 kibana-8.0.1]# ./bin/kibana --allow-rootkibana访问界面IP5601使用超级用户elastic登录即可。
更多关于elasticsearch的知识分享请前往博客主页。编写过程中难免出现差错敬请指出