生成证书
首先,您需要使用 OpenSSL 工具生成自签名证书。在命令行中输入以下命令:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /path/to/key -out /path/to/cert
其中,/path/to/key
是您要生成的私钥文件路径,/path/to/cert
是您要生成的证书文件路径。
在这个过程中,您需要设置一些说明信息,如证书的国家、所在组织等信息。在命令中会提示您填写这些信息。
配置 elasticsearch.yml 文件
接下来,您需要在 elasticsearch.yml 文件中配置 xpack.security.http.ssl 相关参数,如下所示:
xpack.security.enabled: true
xpack.security.http.ssl.enabled: true
xpack.security.http.ssl.key: /path/to/key
xpack.security.http.ssl.certificate: /path/to/cert
xpack.security.http.ssl.verification_mode: certificate
其中,xpack.security.enabled
参数用于启用安全特性,xpack.security.http.ssl.enabled
参数用于启用 SSL 加密,xpack.security.http.ssl.key
和 xpack.security.http.ssl.certificate
参数分别指定您生成的私钥和证书的文件路径,xpack.security.http.ssl.verification_mode
参数指定验证证书的方式,默认为 full,您也可以设置为 none。
重启 Elasticsearch
最后,您需要重启 Elasticsearch,使配置生效。在命令行中输入以下命令:
sudo systemctl restart elasticsearch.service
使用 SSL 加密连接
一旦配置了 xpack.security.http.ssl,Elasticsearch 将使用 SSL 加密连接。这意味着,您的浏览器会显示一个安全锁定图标,证明您正在使用加密连接访问 Elasticsearch。
以上就是配置 Elasticsearch 的 xpack.security.http.ssl 的操作步骤,请注意配置参数的正确性,避免因配置错误产生安全隐患。