尝试使用Logstash + Elasticsearch
参考:开始使用logstash
几乎是以上网站内容的原样。
准备好
查询Java版本
$ java -version
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
总之,看起来1.6版本好像可以运行。
下载和解压缩
curl -O https://download.elasticsearch.org/logstash/logstash/logstash-1.4.0.tar.gz
tar zxvf logstash-1.4.0.tar.gz
cd logstash-1.4.0
先须启动
bin/logstash -e 'input { stdin { } } output { stdout {} }'
这个设置只是将从标准输入中收集的日志写入标准输出。你可以试着输入”hello”之类的。
hoge <- 入力した内容
2014-04-12T12:05:53.958+0000 nakamatsu.local hoge <- 出力された内容
就像那样。
Logstash具备可以将输出结果转换为各种格式的’codec’。例如,使用’rubydebug’,可以将输出结果以Ruby哈希字符串的形式输出。
hello
{
"message" => "hello",
"@version" => "1",
"@timestamp" => "2014-04-12T12:11:57.424Z",
"host" => "hogehoge"
}
将输出存储到Elasticsearch中。
下载并启动Elasticsearch
在合适的地方执行以下操作,启动Elasticsearch。
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz
tar zxvf elasticsearch-1.0.1.tar.gz
cd elasticsearch-1.0.1/
./bin/elasticsearch
将输出目标设置为 Elasticsearch。
当您启动Logstash时,输出将被发送到Elasticsearch。
bin/logstash -e 'input { stdin { } } output { elasticsearch { host => localhost } }'
我們可以從標準輸入中輸入一些隨機文字,以確認是否已經輸入到Elasticsearch中。
curl 'http://localhost:9200/_search?pretty'
使用Elasticsearch,可以通过HTTP的API进行访问。当访问上述URL时,会返回以下形式的JSON字符串。
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "logstash-2014.04.12",
"_type" : "logs",
"_id" : "H7dSnW_TSTOVno_V25JYlQ",
"_score" : 1.0, "_source" : {"message":"hello","@version":"1","@timestamp":"2014-04-12T12:17:51.216Z","host":"nakamatsu.local"}
}, {
"_index" : "logstash-2014.04.07",
"_type" : "logs",
"_id" : "_sisyTEvSRaqXt6TR3pXwg",
"_score" : 1.0, "_source" : {"message":"hoge","@version":"1","@timestamp":"2014-04-07T04:00:34.590Z","host":"nakamatsu.local"}
}, {
"_index" : "logstash-2014.04.07",
"_type" : "logs",
"_id" : "_K48GJWeTLSUZzgrNXD7fg",
"_score" : 1.0, "_source" : {"message":"you know, for logs","@version":"1","@timestamp":"2014-04-07T03:54:50.355Z","host":"nakamatsu.local"}
} ]
}
}
暂时就到这里吧。