Logstash 输出到 Elasticsearch SSL 证书

发布于 2025-01-11 01:25:46 字数 2398 浏览 0 评论 0原文

我有以下 docker 容器

docker create \
--name=elasticsearch \
--restart=always \
--network=infrastructure_network \
--network-alias=elasticsearch \
-e TZ=Etc/UTC \
-e discovery.type=single-node \
-e "ES_JAVA_OPTS=-Xms6g -Xmx6g" \
-e ELASTIC_PASSWORD="foobar" \
-p 9200:9200 \
-p 9300:9300 \
-v elasticsearch:/usr/share/elasticsearch \
elasticsearch:8.0.0

docker create \
--name=logstash \
--restart=always \
--network=infrastructure_network \
--network-alias=logstash \
-e TZ=Etc/UTC \
-p 5040:5040 \
-p 8514:8514/udp \
-v logstash:/usr/share/logstash/ \
-v elasticsearch:/elastic/ \
logstash:8.0.0

容器启动得很好,但是..当我将logstash 输出设置如下时:

input 
{
  tcp 
  {
    port => 8514
    type => syslog
  }
}

filter 
{
  if [type] == "syslog" 
  {
    grok 
    {
      match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
      add_field => [ "received_at", "%{@timestamp}" ]
      add_field => [ "received_from", "%{host}" ]
    }
    date 
    {
      match => [ "syslog_timestamp", "MMM  d HH:mm:ss.SSS", "MMM dd HH:mm:ss.SSS" ]
      timezone => "UTC"
    }
  }
}

output 
{
    elasticsearch 
    {
        hosts => ['https://elasticsearch:9200']
        cacert => '/elastic/config/certs/http_ca.crt'
        ssl_certificate_verification => false
        user => "elastic"
        password => "foobar"
        index => "syslog"
        ilm_enabled => false
    }

    stdout { codec => rubydebug }
}

我在logstash 日志中收到以下错误...

引起的:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径

[2022-03-02T03:27:04,496] [警告][logstash.outputs.elasticsearch][main] 尝试恢复与失效 ES 实例的连接,但出现错误 {:url=>"https://elastic:xxxxxx@elasticsearch:9200/", :exception=> LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError,:message=>“Elasticsearch 无法访问: [https://elasticsearch:9200/][Manticore::ClientProtocolException] PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径”}

[2022-03-02T03:27 :08,344][DEBUG][logstash.outputs.elasticsearch][main] 等待连接到 Elasticsearch 集群,正在重试在 16 秒后,

我假设我使用了错误的证书?这是当 elascticsearch 容器启动时创建的证书,我应该使用什么?

I have the following docker containers

docker create \
--name=elasticsearch \
--restart=always \
--network=infrastructure_network \
--network-alias=elasticsearch \
-e TZ=Etc/UTC \
-e discovery.type=single-node \
-e "ES_JAVA_OPTS=-Xms6g -Xmx6g" \
-e ELASTIC_PASSWORD="foobar" \
-p 9200:9200 \
-p 9300:9300 \
-v elasticsearch:/usr/share/elasticsearch \
elasticsearch:8.0.0

docker create \
--name=logstash \
--restart=always \
--network=infrastructure_network \
--network-alias=logstash \
-e TZ=Etc/UTC \
-p 5040:5040 \
-p 8514:8514/udp \
-v logstash:/usr/share/logstash/ \
-v elasticsearch:/elastic/ \
logstash:8.0.0

The containers start perfectly fine, but.. when I set the logstash output as follows:

input 
{
  tcp 
  {
    port => 8514
    type => syslog
  }
}

filter 
{
  if [type] == "syslog" 
  {
    grok 
    {
      match => { "message" => "%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}" }
      add_field => [ "received_at", "%{@timestamp}" ]
      add_field => [ "received_from", "%{host}" ]
    }
    date 
    {
      match => [ "syslog_timestamp", "MMM  d HH:mm:ss.SSS", "MMM dd HH:mm:ss.SSS" ]
      timezone => "UTC"
    }
  }
}

output 
{
    elasticsearch 
    {
        hosts => ['https://elasticsearch:9200']
        cacert => '/elastic/config/certs/http_ca.crt'
        ssl_certificate_verification => false
        user => "elastic"
        password => "foobar"
        index => "syslog"
        ilm_enabled => false
    }

    stdout { codec => rubydebug }
}

I get the following error in the logstash logs...

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

[2022-03-02T03:27:04,496][WARN ][logstash.outputs.elasticsearch][main] Attempted to resurrect connection to dead ES instance, but got an error {:url=>"https://elastic:xxxxxx@elasticsearch:9200/", :exception=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError, :message=>"Elasticsearch Unreachable: [https://elasticsearch:9200/][Manticore::ClientProtocolException] PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"}

[2022-03-02T03:27:08,344][DEBUG][logstash.outputs.elasticsearch][main] Waiting for connectivity to Elasticsearch cluster, retrying in 16s

I'm assuming that I'm using the wrong cert maybe? It's the cert that is created when the elascticsearch container is spun up, what SHOULD I be using ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗忘曾经 2025-01-18 01:25:46

确保您在 cacert 中指向的文件包含弹性端使用的证书的完整链(我们让它首先与 root 一起使用,然后按顺序与任何中间 CA 一起使用)

Make sure the file you point to in cacert contains the full chain of the certificate used on the elastic side (we've had it work with root first and then any intermediate CAs in order)

沧笙踏歌 2025-01-18 01:25:46

添加 ssl => true 输出弹性

add ssl => true to output elastic

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文