你如何让 logstash 输出到私有 ip 上的 elasticsearch?

How do you get logstash to output to elasticsearch on a private ip?

不幸的是,Logstash 没有尝试输出到正确 IP 地址的 Elasticsearch。 Elasticsearch 配置在端口 9200 上的私有 IP 地址。Logstash 正尝试输出到位于 localhost:9200 的 Elasticsearch。这显示在下面的日志中。

{:timestamp=>"2016-02-08T16:27:58.572000-0500", :message=>"Attempted to send a bulk request to Elasticsearch configured at '[\"http://localhost:9200/\"]', but Elasticsearch appears to be unreachable or down!", :client_config=>{:hosts=>["http://localhost:9200/"], :ssl=>nil, :transport_options=>{:socket_timeout=>0, :request_timeout=>0, :proxy=>nil, :ssl=>{}}, :transport_class=>Elasticsearch::Transport::Transport::HTTP::Manticore, :logger=>nil, :tracer=>nil, :reload_connections=>false, :retry_on_failure=>false, :reload_on_failure=>false, :randomize_hosts=>false}, :error_message=>"Connection refused", :class=>"Manticore::SocketException", :level=>:error}

我的配置文件如下: /etc/elasticsearch/elasticsearch.yml

network.host: PRIVATE_IP_ADDRESS

/opt/logstash/conf.d/logstash.conf

input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => ["PRIVATE_IP_ADDRESS:9200"]
    manage_template => false
    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
    document_type => "%{[@metadata][type]}"
  }
}

我在 /etc/logstash/conf.d/logstash.conf 有相同的文件,因为我不知道将 logstash 配置文件放在哪里。

当我运行curl PRIVATE_IP_ADDRESS:9200时,我得到以下输出

{
  "name" : "Gabriel Summers",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.1.1",
    "build_hash" : "40e2c53a6b6c2972b3d13846e450e66f4375bd71",
    "build_timestamp" : "2015-12-15T13:05:55Z",
    "build_snapshot" : false,
    "lucene_version" : "5.3.1"
  },
  "tagline" : "You Know, for Search"
}

如何配置 Logstash 以在 PRIVATE_IP_ADDRESS:9200 而不是 localhost:92000 输出到 Elasticsearch?

我会仔细检查 logstash 是否确实在使用该配置文件。

只需在您的 conf 文件中使用以下代码片段即可。

output {
  elasticsearch {
     hosts => "PRIVATE_IP_ADDRESS:9200"
  }
}

事实证明,当我重新启动 logstash 时,所有进程都没有终止。我的配置文件不是问题。

这是我运行解决这个问题的命令: ps -ef | grep logstash sudo kill EACH_PID sudo kill -9 PID_THAT_WASNT_KILLED_BEFORE sudo /etc/init.d/logstash start

如果您使用 RPM 安装,那么您的配置应该位于 /etc/logstash/conf.d/

因此尝试将您提到的文件 (opt/logstash/conf.d/logstash.conf) 移动到 /etc/logstash/conf.d 目录,然后重新启动您的 logstash 服务并检查它。