filebeat、elasticsearch采用https协议

1、生产p12证书

生产证书及安全功能,elasticsearch基础及以上版本才有生产证书的功能,elasticsearch-certutil。elasticsearch开源版本无此功能。具体可以参考https://www.elastic.co/cn/subscriptions在这里插入图片描述
标准版如下所示
在这里插入图片描述

1.1、创建生产证书的文件

./bin/elasticsearch-certutil ca

Elasticsearch的安装目录下,我们可以看见一个生产的证书文件:
在这里插入图片描述

1.2、生成一个证书

我们接着运行如下的命令来生成一个证书:

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

上面的命令将使用我们的CA来生成一个证书elastic-certificates.p12,如上图中的elastic-stack-ca.p12文件,

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

1.3、生成证书对应秘钥

openssl pkcs12 -in elastic-stack-ca.p12 -out newfile.crt.pem -clcerts -nokeys

它将生成一个叫做newfile.crt.pem的文件(如上图所示)。我们把这个文件拷入到filebeat目录中

2、启动elasticsearch

2.1、修改配置文件

我们接下来配置在Elasticsearch中的config/elasticsearch.yml,我们添加如下的配置

#用HTTPS方式访问es
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

2.2、重启elasticsearch

elasticsearch.bat

这样我们的Elasticsearch已经成功地运行于https模式。我们在chrome中打入地址https://localhost:9200,我们可以看到启动成功
在这里插入图片描述

3、启动filebeat

3.1、修改配置文件

配置文件中增加如下内容

protocol: “https”
ssl.verification_mode: none
ssl.certificate_authorities: [“newfile.crt.pem”]

如下所示

output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["localhost:9200"]
  index: "%{[fields.source]}-*"
  indices:
    - index: "ops-systemlog-%{+yyyy.MM.dd}"
      when.equals: 
        fields: 
          source: "ops-systemlog"
    #- index: "opslog-operationlog-%{+yyyy.MM.dd}"
    - index: "ops-operationlog-%{+yyyy.MM.dd}"
      when.equals:
        fields:
          #source: "operationlog"
          source: "ops-operationlog"

  # Protocol - either `http` (default) or `https`.
  protocol: "https"
  ssl.verification_mode: none
  ssl.certificate_authorities: ["newfile.crt.pem"]

3.2、启动filebeat

window

.\filebeat.exe -e -c filebeat.yml

4、打开elasticsearch-head

在这里插入图片描述

5、使用nodejs访问elasticsearch

建立client。
注意:当使用https访问时。host不可以填写ip地址,应该填写域名。至于如何建立ip和域名的映射关系,请参考我的另外一篇博客。域名映射到指定IP
在这里插入图片描述

参考:
【1】配置SSL、TLS以及HTTPS来确保es、kibana、beats、logstash的安全https://www.cnblogs.com/fat-girl-spring/p/12714845.html
【2】Elastic:为Elasticsearch启动https访问https://elasticstack.blog.csdn.net/article/details/105044365

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郑同学的笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值