파일 입력, logstash-forwarder를 사용하여 ELK를 성공적으로 설정하고 몇몇 서버의 Kibana 흐름에서 로그를 확인한 후 TCP 입력을 설정하려고 시도했습니다.
tcp {
codec => "json"
host => "localhost"
port => 9250
tags => ["sensu"]
}
발신자는 sensu이고 메시지는 실제로 JSON에 있습니다. tcpdump 명령으로 이를 확인하세요.
Logstash 로그는 연결이 허용되었음을 나타냅니다.
{:timestamp=>"2015-06-15T14:03:39.832000+1000", :message=>"Accepted connection", :client=>"127.0.0.1:38065", :server=>"localhost:9250", :level=>:debug, :file=>"logstash/inputs/tcp.rb", :line=>"146", :method=>"client_thread"}
{:timestamp=>"2015-06-15T14:03:39.962000+1000", :message=>"config LogStash::Codecs::JSONLines/@charset = \"UTF-8\"", :level=>:debug, :file=>"logstash/config/mixin.rb", :line=>"112", :method=>"config_init"}
{:timestamp=>"2015-06-15T14:03:39.963000+1000", :message=>"config LogStash::Codecs::Line/@charset = \"UTF-8\"", :level=>:debug, :file=>"logstash/config/mixin.rb", :line=>"112", :method=>"config_init"}
그러나 데이터는 더 이상 진행되지 않는 것으로 보이며 Kibana에서 찾을 수 없습니다.
나는 다른 입력을 비활성화하기 위해 노력한 다음 Elasticsearch(curl 'localhost:9200/_cat/shards')에서 크기가 증가하지 않는 샤드를 관찰했습니다.
에 따르면이 링크나는 올바른 길을 가고 있지만 아마도 어딘가에서 어리석은 일을 하고 있을 것입니다... 미리 감사드립니다.
로그스태시.conf:
input {
file {
path => ["/var/log/messages", "/var/log/secure", "/var/log/iptables"]
type => "syslog"
start_position => "end"
}
lumberjack {
port => 5043
type => "logs"
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
}
tcp {
codec => "json"
host => "localhost"
port => 9250
tags => ["sensu"]
}
}
output {
elasticsearch {
host => "localhost"
cluster => "webCluster"
}
}
탄력적 검색.yml:
cluster.name: webCluster
node.name: "bossNode"
node.master: true
node.data: true
index.number_of_shards: 1
index.number_of_replicas: 0
network.host: localhost
답변1
며칠 더 실망스러운 시간을 보낸 후 json/json_lines 코덱이 손상되었다는 결론을 내렸습니다. 아마도 tcp 입력과 함께 사용할 때만 가능합니다.
그러나 필터를 사용하여 해결 방법을 찾았습니다.
filter {
if ("sensu" in [tags]) {
json {
"source" => "message"
}
}
}
이것과 몇 가지 돌연변이가 제가 원래 달성하려고 했던 효과를 만들어 냈습니다. 후손을 위해 sensu의 로그와 CPU/메모리 메트릭 데이터를 결합하는 작업 logstash.conf가 있습니다.
input {
file {
path => [
"/var/log/messages"
, "/var/log/secure"
]
type => "syslog"
start_position => "end"
}
file {
path => "/var/log/iptables"
type => "iptables"
start_position => "end"
}
file {
path => ["/var/log/httpd/access_log"
,"/var/log/httpd/ssl_access_log"
]
type => "apache_access"
start_position => "end"
}
file {
path => [
"/var/log/httpd/error_log"
, "/var/log/httpd/ssl_error_log"
]
type => "apache_error"
start_position => "end"
}
lumberjack {
port => 5043
type => "logs"
ssl_certificate => "/etc/pki/tls/certs/logstash-forwarder.crt"
ssl_key => "/etc/pki/tls/private/logstash-forwarder.key"
}
tcp {
host => "localhost"
port => 9250
mode => "server"
tags => ["sensu"]
}
}
filter {
if ("sensu" in [tags]) {
json {
"source" => "message"
}
mutate {
rename => { "[check][name]" => "type" }
replace => { "host" => "%{[client][address]}" }
split => { "[check][output]" => " " }
add_field => { "output" => "%{[check][output][1]}" }
remove_field => [ "[client]", "[check]", "occurrences" ]
}
} else if([type] == "apache_access") {
grok {
match => { "message" => "%{IP:client}" }
}
}
}
filter {
mutate {
convert => { "output" => "float" }
}
}
output {
elasticsearch {
host => "localhost"
cluster => "webCluser"
}
}
문제와 관련 없음: "출력"은 공백으로 구분된 여러 값으로 수신되므로 "분할" 작업이 수행됩니다. 두 번째 요소가 사용된 다음 부동 소수점으로 변환되므로 Kibana는 이를 멋지게 그래프로 표시합니다(제가 힘들게 배운 것입니다).