我按照 Digital Ocean 的教程学习如何在 CentOS 7 机器上安装 ELK 堆栈。
它看起来相当不错,让我的初始 Elastic Search 节点正常工作,并让 kibana 4 在 NGINX 后面运行。但在安装 Logstash 时,我遇到了一个问题,它似乎没有在 elasticsearch 中创建任何索引!!我确信这是某个地方的配置问题。但我不知道在哪里!
我注意到,当我重新启动 logstash 后使用 _cat API 清除 elasticsearch 索引时,logstash 尚未创建任何索引。
curl http://localhost:9200/_cat/indices
yellow open .kibana 1 1 1 0 2.4kb 2.4kb
yellow open security 5 1 0 0 575b 575b
这里我们有 kibana 的索引,以及我认为是标准的 ES 索引,称为“安全”。但看起来 logstash 并没有与 ES 通信!而且一切都在同一台机器上运行。
这些是我安装的 ES 和 LS 版本:
elasticsearch-1.5.2-1.noarch
logstash-1.5.1-1.noarch
logstash-forwarder-0.4.0-1.x86_64
按照我遵循的教程中的设置方式,您将有 3 个配置文件进入 logstash conf.d 目录。
在 /etc/logstash/conf.d/01-lumberjack-input.conf 中我有:
lumberjack {
port => 5000
type => "logs"
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
}
}
在 /etc/logstash/conf.d/10-syslog.conf 中我有:
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}" ]
}
syslog_pri { }
date {
match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ]
}
}
}
我也有我自己的配置,来自我以前的 logstash 服务器,我将其放入一个名为 20-logstash.conf 的文件中,该文件正在监听端口 2541:
我在 /etc/logstash/conf.d/20-logstash.conf 中有以下内容
input {
lumberjack {
# The port to listen on
port => 2541
# The paths to your ssl cert and key
ssl_certificate => "/etc/pki/tls/certs/lumberjack.crt"
ssl_key => "/etc/pki/tls/private/lumberjack.key"
# Set this to whatever you want.
type => "logstash"
codec => "json"
}
}
filter {
if [type] == "postfix" {
grok {
match => [ "message", "%{SYSLOGBASE}", "timestamp", "MMM dd HH:mm:ss" ]
add_tag => [ "postfix", "grokked" ]
}
}
}
filter {
if [type] == "system" {
grok {
match => [ "message", "%{SYSLOGBASE}" ]
add_tag => [ "system", "grokked" ]
}
}
}
filter {
if [type] == "syslog" {
grok {
match => [ "message", "%{SYSLOGBASE}" ]
add_tag => [ "syslog", "grokked" ]
}
}
}
filter {
if [type] == "security" {
grok {
match => [ "message", "%{SYSLOGBASE}" ]
add_tag => [ "security", "grokked" ]
}
}
}
output {
stdout {
#debug => true
#debug_format => "json"
}
elasticsearch {
host => "logs.mydomain.com"
}
}
在 /etc/logstash/conf.d/30-lumberjack-output.conf 中,我将输出发送到 ES:
output {
elasticsearch { host => localhost }
stdout { codec => rubydebug }
}
现在,再次重新启动 logstash 后,我看到 logstash 正在监听我在配置中指定的端口:
[root@logs:/etc/logstash] #lsof -i :5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 23893 logstash 16u IPv6 11665234 0t0 TCP *:commplex-main (LISTEN)
[root@logs:/etc/logstash] #lsof -i :2541
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 23893 logstash 18u IPv6 11665237 0t0 TCP *:lonworks2 (LISTEN)
截至目前,logstash 正在运行但未产生任何日志输出:
#ps -ef | grep logstash | grep -v grep
logstash 23893 1 16 11:49 ? 00:01:45 /bin/java -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/var/lib/logstash -Xmx500m -Xss2048k -Djffi.boot.library.path=/opt/logstash/vendor/jruby/lib/jni -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Djava.io.tmpdir=/var/lib/logstash -Xbootclasspath/a:/opt/logstash/vendor/jruby/lib/jruby.jar -classpath : -Djruby.home=/opt/logstash/vendor/jruby -Djruby.lib=/opt/logstash/vendor/jruby/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main --1.9 /opt/logstash/lib/bootstrap/environment.rb logstash/runner.rb agent -f /etc/logstash/conf.d -l /var/log/logstash/logstash.log
ls -lh /var/log/logstash/logstash.log
-rw-r--r--. 1 logstash logstash 0 Jun 22 11:49 /var/log/logstash/logstash.log
但 elasticsearch 中仍然没有创建任何索引:
#curl http://localhost:9200/_cat/indices
yellow open .kibana 1 1 1 0 2.4kb 2.4kb
yellow open security 5 1 0 0 575b 575b
当我去配置 Kibana 时,它说找不到任何使用“logstash-*”进行搜索的模式。
我从哪里可以让它工作?配置本身与我之前向您展示的相同。
我还没有尝试将任何 logstash 转发器指向它...但我尝试用以下命令将 stdin 写入 elasticsearch 集群:
logstash -e 'input { stdin { } } output { elasticsearch { host => localhost } }'
我收到了这个错误:
`Got error to send bulk of actions: blocked by: [SERVICE_UNAVAILABLE/1/state not recovered / initialized];[SERVICE_UNAVAILABLE/2/no master]; {:level=>:error}
Failed to flush outgoing items {:outgoing_count=>1, :exception=>org.elasticsearch.cluster.block.ClusterBlockException: blocked by: [SERVICE_UNAVAILABLE/1/state not recovered / initialized];[SERVICE_UNAVAILABLE/2/no master];, :backtrace=>["org.elasticsearch.cluster.block.ClusterBlocks.globalBlockedException(org/elasticsearch/cluster/block/ClusterBlocks.java:151)", "org.elasticsearch.cluster.block.ClusterBlocks.globalBlockedRaiseException(org/elasticsearch/cluster/block/ClusterBlocks.java:141)", "org.elasticsearch.action.bulk.TransportBulkAction.executeBulk(org/elasticsearch/action/bulk/TransportBulkAction.java:210)", "org.elasticsearch.action.bulk.TransportBulkAction.access$000(org/elasticsearch/action/bulk/TransportBulkAction.java:73)", "org.elasticsearch.action.bulk.TransportBulkAction$1.onFailure(org/elasticsearch/action/bulk/TransportBulkAction.java:148)", "org.elasticsearch.action.support.TransportAction$ThreadedActionListener$2.run(org/elasticsearch/action/support/TransportAction.java:137)", "java.util.concurrent.ThreadPoolExecutor.runWorker(java/util/concurrent/ThreadPoolExecutor.java:1142)", "java.util.concurrent.ThreadPoolExecutor$Worker.run(java/util/concurrent/ThreadPoolExecutor.java:617)", "java.lang.Thread.run(java/lang/Thread.java:745)"], :level=>:warn}`
对于可能发生的事情有什么想法吗?