ElasticSearch | 集群内部安全通信

为什么要加密通信

  • 避免数据被抓包,敏感信息泄漏;
  • 避免 Imposter Node 加入集群,获取敏感信息;

为节点创建证书

TLS
  • TLS 协议要求 Trusted Certificate Anthority(CA)签发的 X.509 证书;
证书认证的不同级别
  • Certificate - 节点加入集群需要相同 CA 签发的证书;
  • Full Verification - 节点加入集群需要相同 CA 签发的证书,还需要验证 Host Name 和 IP 地址;
  • No Verification - 任何节点都可以加入,开发环境中用于诊断的目的;

生成节点证书 | 举个栗子

创建证书颁发机构

bin/elasticsearch-certutil ca

  • 密码为空;
  • 生成文件 elastic-stack-ca.p12;
为群集中的每个节点生成证书和私钥

bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

  • 一路回车;
  • 生成证书 elastic-certificates.p12;
  • 在 ES 的 config 目录下创建 certs 目录,把 elastic-certificates.p12 拷贝到目录当中;
配置节点间通信
  • 修改 elastic.yml 文件;
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
  • 也可以把参数加到命令行中,起 2 个节点:

bin/elasticsearch -E node.name=node0 -E cluster.name=geektime -E path.data=node0_data -E http.port=9200 -E xpack.security.enabled=true -E xpack.security.transport.ssl.enabled=true -E xpack.security.transport.ssl.verification_mode=certificate -E xpack.security.transport.ssl.keystore.path=certs/elastic-certificates.p12 -E xpack.security.transport.ssl.truststore.path=certs/elastic-certificates.p12

bin/elasticsearch -E node.name=node1 -E cluster.name=geektime -E path.data=node1_data -E http.port=9201 -E xpack.security.enabled=true -E xpack.security.transport.ssl.enabled=true -E xpack.security.transport.ssl.verification_mode=certificate -E xpack.security.transport.ssl.keystore.path=certs/elastic-certificates.p12 -E xpack.security.transport.ssl.truststore.path=certs/elastic-certificates.p12

启动第 3 个节点,不带证书
  • 无法加入,报错;

bin/elasticsearch -E node.name=node2 -E cluster.name=geektime -E path.data=node2_data -E http.port=9202 -E xpack.security.enabled=true -E xpack.security.transport.ssl.enabled=true -E xpack.security.transport.ssl.verification_mode=certificate

你可能感兴趣的:(ElasticSearch | 集群内部安全通信)