es证书
集群创建好:配置文件:
node1:
[root@localhost elasticsearch]# grep -v ^# elasticsearch.yml |grep -v ^$
cluster.name: songcluster
node.name: node-50
node.master: true
node.data: true
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.1.50
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["192.168.1.50", "192.168.1.55", "192.168.1.56"]
cluster.initial_master_nodes: ["192.168.1.50"]
discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: "Authorization"
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
http.max_initial_line_length: 100k
http.max_header_size: 50k
http.max_content_length: 50mb
cluster.routing.allocation.total_shards_per_node: 5000
xpack.license.self_generated.type: basic
node2:
[root@songES02 elasticsearch]# grep -v ^# elasticsearch.yml |grep -v ^$
cluster.name: songcluster
node.master: true
node.data: true
node.name: node-55
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.1.55
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["192.168.1.50", "192.168.1.55", "192.168.1.56"]
cluster.initial_master_nodes: ["192.168.1.50", "192.168.1.55", "192.168.1.56"]
discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: "Authorization"
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
http.max_initial_line_length: 100k
http.max_header_size: 50k
http.max_content_length: 50mb
cluster.routing.allocation.total_shards_per_node: 5000
xpack.license.self_generated.type: basic
node3:
[root@songEs03 elasticsearch]# grep -v ^# elasticsearch.yml |grep -v ^$
cluster.name: songcluster
node.master: true
node.data: true
node.name: node-56
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.1.56
transport.tcp.port: 9300
http.port: 9200
discovery.seed_hosts: ["192.168.1.50", "192.168.1.55", "192.168.1.56"]
cluster.initial_master_nodes: ["192.168.1.50", "192.168.1.55", "192.168.1.56"]
discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: "Authorization"
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
http.max_initial_line_length: 100k
http.max_header_size: 50k
http.max_content_length: 50mb
cluster.routing.allocation.total_shards_per_node: 5000
xpack.license.self_generated.type: basic
创建证书
[root@localhost elasticsearch]# pwd
/usr/share/elasticsearch
[root@localhost elasticsearch]# ./bin/elasticsearch-certutil ca
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 authority
By default the 'ca' mode produces a single PKCS#12 output file which holds:
* The CA certificate
* The CA's private key
If 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 key
Please enter the desired output file [elastic-stack-ca.p12]: #指定证书文件名直接回车为默认
Enter password for elastic-stack-ca.p12 : #输入证书密码
#创建证书私钥
[root@localhost elasticsearch]# bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
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 'cert' mode generates X.509 certificate and private keys.
* By default, this generates a single certificate and key for use
on a single instance.
* The '-multiple' option will prompt you to enter details for multiple
instances and will generate a certificate and key for each one
* The '-in' option allows for the certificate generation to be automated by describing
the details of each instance in a YAML file
* An instance is any piece of the Elastic Stack that requires an SSL certificate.
Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
may all require a certificate and private key.
* The minimum required value for each instance is a name. This can simply be the
hostname, which will be used as the Common Name of the certificate. A full
distinguished name may also be used.
* A filename value may be required for each instance. This is necessary when the
name would result in an invalid file or directory name. The name provided here
is used as the directory name (within the zip) and the prefix for the key and
certificate files. The filename is required if you are prompted and the name
is not displayed in the prompt.
* IP addresses and DNS names are optional. Multiple values can be specified as a
comma separated string. If no IP addresses or DNS names are provided, you may
disable hostname verification in your SSL configuration.
* All certificates generated by this tool will be signed by a certificate authority (CA).
* The tool can automatically generate a new CA for you, or you can provide your own with the
-ca or -ca-cert command line options.
By default the 'cert' mode produces a single PKCS#12 output file which holds:
* The instance certificate
* The private key for the instance certificate
* The CA certificate
If you specify any of the following options:
* -pem (PEM formatted output)
* -keep-ca-key (retain generated CA key)
* -multiple (generate multiple certificates)
* -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key files
Enter password for CA (elastic-stack-ca.p12) : #上边设置ca的密码
Please enter the desired output file [elastic-certificates.p12]: #私钥的文件名,回车默认
Enter password for elastic-certificates.p12 : #私钥密码
Certificates written to /usr/share/elasticsearch/elastic-certificates.p12
This file should be properly secured as it contains the private key for
your instance.
This file is a self contained file and can be copied and used 'as is'
For each Elastic product that you wish to configure, you should copy
this '.p12' file to the relevant configuration directory
and then follow the SSL configuration instructions in the product guide.
For client applications, you may only need to copy the CA certificate and
configure the client to trust this certificate.
截图:
创建成功后在/usr/share/elasticsearch下会有这两个文件。
传证书和私钥到其他节点
[root@localhost elasticsearch]# scp elastic-* root@192.168.1.55:/etc/elasticsearch/
root@192.168.1.55's password:
elastic-certificates.p12 100% 3443 49.0KB/s 00:00
elastic-stack-ca.p12 100% 2527 87.6KB/s 00:00
[root@localhost elasticsearch]# scp elastic-* root@192.168.1.56:/etc/elasticsearch/
root@192.168.1.56's password:
elastic-certificates.p12 100% 3443 119.7KB/s 00:00
elastic-stack-ca.p12 100% 2527 75.7KB/s 00:00
本地复制,换位置,换不换都行,配置文件要写这个位置
[root@localhost elasticsearch]# cp elastic-* /etc/elasticsearch/
[root@localhost elasticsearch]# cd /etc/elasticsearch/
[root@localhost elasticsearch]# ls
elastic-certificates.p12 elasticsearch.yml elastic-stack-ca.p12 jvm.options.d role_mapping.yml users
elasticsearch.keystore elasticsearch.yml.cluster jvm.options log4j2.properties roles.yml users_roles
[root@localhost elasticsearch]#
修改配置文件
打开或添加xpack功能
xpack.security.enabled: true
xpack.security.audit.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12
[root@localhost elasticsearch]# grep -v ^# elasticsearch.yml |grep -v ^$
cluster.name: songcluster
node.name: node-50
node.master: true
node.data: true
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 192.168.1.50
http.port: 9200
transport.tcp.port: 9300
discovery.seed_hosts: ["192.168.1.50", "192.168.1.55", "192.168.1.56"]
cluster.initial_master_nodes: ["192.168.1.50"]
discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: "Authorization"
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
http.max_initial_line_length: 100k
http.max_header_size: 50k
http.max_content_length: 50mb
cluster.routing.allocation.total_shards_per_node: 5000
xpack.security.enabled: true
xpack.security.audit.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12
各个节点为 xpack.security.transport 添加密码,每个节点都执行这两个命令
[root@localhost elasticsearch]# /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
Enter value for xpack.security.transport.ssl.keystore.secure_password:
[root@localhost elasticsearch]# /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
Enter value for xpack.security.transport.ssl.truststore.secure_password:
证书文件该权限
所有节点都改
[root@localhost elasticsearch]# chmod 660 elastic-*
[root@localhost elasticsearch]# ll
æ€»ç”¨é‡ 52
-rw-rw----. 1 root elasticsearch 3443 1月 13 17:16 elastic-certificates.p12
-rw-rw----. 1 root elasticsearch 331 1月 14 11:47 elasticsearch.keystore
-rw-rw----. 1 root elasticsearch 3733 1月 14 09:40 elasticsearch.yml
-rw-r-----. 1 root elasticsearch 3498 1月 13 16:20 elasticsearch.yml.cluster
-rw-rw----. 1 root elasticsearch 2527 1月 13 17:16 elastic-stack-ca.p12
-rw-rw----. 1 root elasticsearch 2373 7月 22 00:46 jvm.options
drwxr-s---. 2 root elasticsearch 6 7月 22 00:49 jvm.options.d
-rw-rw----. 1 root elasticsearch 17419 7月 22 00:46 log4j2.properties
-rw-rw----. 1 root elasticsearch 473 7月 22 00:46 role_mapping.yml
-rw-rw----. 1 root elasticsearch 197 7月 22 00:46 roles.yml
-rw-rw----. 1 root elasticsearch 0 7月 22 00:46 users
-rw-rw----. 1 root elasticsearch 0 7月 22 00:46 users_roles
重启服务
systemctl restart elasticsearch
设置加密密码
一个节点里加密就行
/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
[root@localhost elasticsearch]# /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
123123Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
[root@localhost elasticsearch]#