Elasticsearch启动https

1.生成p12格式的CA证书

[sandwich@centos-elk elasticsearch-7.17.1]$ ./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 :

这里不改名,直接接受文件的默认名elastic-stack-ca.p12,然后输入密码: aaaaaa并记住。
执行完生成以下文件

[sandwich@centos-elk elasticsearch-7.17.1]$ ls *p12
elastic-stack-ca.p12

2.生成p12格式的certificate证书

接着用如下命令来生成一个新的证书

[sandwich@centos-elk elasticsearch-7.17.1]$ ./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)
      unless the --self-signed command line option is specified.
      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证书的密码: aaaaaa
输入CA证书密码后,接受新证书的默认文件名,然后为新证书elastic-certificates.p12添加新密码: bbbbbb

Enter password for CA (elastic-stack-ca.p12) : 
Please enter the desired output file [elastic-certificates.p12]: 
Enter password for elastic-certificates.p12 : 

Certificates written to /home/sandwich/app/elk/elasticsearch-7.17.1/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.

完成后,在相同路径下多了一个elastic-certificates.p12证书文件

[sandwich@centos-elk elasticsearch-7.17.1]$ ls *p12
elastic-certificates.p12  elastic-stack-ca.p12

3.把elastic-certificates.p12 证书拷入到 Elasticsearch 安装目录下的config子目录

[sandwich@centos-elk elasticsearch-7.17.1]$ mv elastic-certificates.p12 config/

4.生成pem格式的证书

[sandwich@centos-elk elasticsearch-7.17.1]$ openssl pkcs12 -in elastic-stack-ca.p12 -out ca.crt.pem -clcerts -nokeys
Enter Import Password:
MAC verified OK
[sandwich@centos-elk elasticsearch-7.17.1]$ ls
bin  ca.crt.pem  config  elastic-stack-ca.p12  jdk  lib  LICENSE.txt  logs  modules  NOTICE.txt  plugins  README.asciidoc  startup.log

注意,这里需要输入elastic-stack-ca.p12证书的密码

5.把pem证书拷到Kibana安装目录下的config目录中:

[sandwich@centos-elk elasticsearch-7.17.1]$ cp ca.crt.pem ../kibana-7.17.1-linux-x86_64/config/

6.修改Elasticsearch配置

config/elasticsearch.yml文件添加以下配置:

[sandwich@centos-elk config]$ vi elasticsearch.yml
[sandwich@centos-elk config]$ tail -n 5 elasticsearch.yml
xpack.security.transport.ssl.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.authc.api_key.enabled: true
xpack.security.http.ssl.keystore.path: elastic-certificates.p12
xpack.security.http.ssl.truststore.path: elastic-certificates.p12
xpack.security.http.ssl.keystore.password: bbbbbb
xpack.security.http.ssl.truststore.password: bbbbbb

重启ES

7.配置Kibana

为了能让Kibana访问带有https的Elasticsearch。我们也需要做相应的配置,给config/kibana.yml添加如下配置

elasticsearch.ssl.certificateAuthorities: ["/home/sandwich/app/elk/kibana-7.17.1-linux-x86_64/config/ca.crt.pem"]
elasticsearch.ssl.verificationMode: none

并且把es的host改成https

elasticsearch.hosts: ["https://localhost:9200"]

你可能感兴趣的:(Elasticsearch启动https)