一、安装logstash
下载官方软件包的方式有以下几种:
压缩包方式
wget https://download.elastic.co/logstash/logstash/logstash-1.5.1.tar.gz
Debian 平台
wget https://download.elastic.co/logstash/logstash/packages/debian/logstash_1.5.1-1_all.deb
Redhat 平台
wget https://download.elastic.co/logstash/logstash/packages/centos/logstash-1.5.1-1.noarch.rpm
二、依赖
java openssl
三、测试
# 安装位置/bin/logstash -e 'input{stdin{}}output{stdout{codec=>rubydebug}}'
然后终端输入。看打印结果:
{
"message"=>"Hello World",
"@version"=>"1",
"@timestamp"=>"2014-08-07T10:30:59.937Z",
"host"=>"raochenlindeMacBook-Air.local",
}
类似这种就OK。
四、client、server 端:
client 日志生产服务器client.conf
input {
file {
type => "test"
path => "/home/Desktop/logs/test.log"
codec => "json"
}
}
output { # 输出日志
tcp { # 推送日志到收集服务器
codec => json_lines
mode => "client"
host => "localhost" # 目标服务器
port => "9022" # 目标服务器logstash server的 port
}
}
server 日志收集服务器 server.conf
input { # 收集日志
tcp { # 从tcp获取
codec => json_lines
host => "0.0.0.0"
mode => "server"
port => "9022" # 使用port运行server
}
}
output {
stdout {
codec=>rubydebug #直接打印
}
}
9022为未使用的端口,
分别运行:
# bin/logstash -f client.conf
# bin/logstash -f server.conf
往测试test.log写入内容,看server端的内容输出:
{
"message" => "2016-06-13 09:33:01\\r",
"tags" => "_jsonparsefailure",
"@version" => "1",
"@timestamp" => "2016-06-13T09:33:01.890Z",
"type" => "test",
"host" => "0.0.0.0",
"path" => "/home/Desktop/logs/test.log"
}
OK。。。