环境:logstash-2.4.0, elasticsearch-1.6.1, kafka 0.8
经常需要查看bash历史,而这个文件一般存储一定量的命令,有时需要查看什么时候执行过。因而使用logstash + kafka + elasticsearch来搭建bash历史命令检索系统。
配置文件如下:
logstash.conf
input {
file {
path => “/home/adadmin/.bash_history”
add_field => {“user” => “adadmin”}
}
}
filter {
ruby {
code => “event[‘updatetime’] = event.timestamp.time.localtime.strftime(‘%Y-%m-%d %H:%M:%S.%L’)”
}
}
output {
kafka {
bootstrap_servers => “10.121.93.50:9092,10.121.93.51:9092,10.121.93.53:9092”
topic_id => “bash-history”
}
}
elasticsearch:
curl -XPUT ‘xxx.xxx.xxx.53:9200/_river/kafka-river/_meta’ -d ‘
{
“type” : “kafka”,
“kafka” : {
“zookeeper.connect” : “xxx.xxx.xxx.50:2181,xxx.xxx.xxx.51:2181,xxx.xxx.xxx.53:2181”,
“zookeeper.connection.timeout.ms” : 10000,
“topic” : “bash-history”,
“message.type” : “json”
},
“index” : {
“index” : “kafka-index”,
“type” : “status”,
“bulk.size” : 3,
“concurrent.requests” : 1,
“action.type” : “index”,
“flush.interval” : “12h”
}
}’
启动logstash
bin/logstash -f logstash.conf
在terminal上执行一些命令,数据就由logstash传到kafka,再传到elasticSearch上,可以在上面直接查看历史命令。