参考
安装
本次实验的安装环境为:ubuntu 15
jre安装
运行 Logstash 需要Java环境,因此需要安装 jre :
1 | sudo apt-get install openjdk-7-jre |
Logstash 安装
从 参考 下载 Logstash ,官方提供的 Installation Steps 说明,只有三步:
- 解压
- 添加logstash配置文件
- 运行
解压 Logstash:
1 | sudo tar -zxvf logstash-1.5.2.tar.gz -C /opt |
添加 HelloWorld.conf 文件:
1 | input { |
进入 Logstash 目录并运行
1 | cd /opt/logstash-1.5.2 |
在终端中输入测试数据并查看输出:
1 | hello |
从文件中读取日志
添加 fileInput.conf 文件:
1 | input{ |
运行 Logstash:
1 | bin/logstash -f fileInput.conf |
输出结果:
1 | { |
从TCP中读取日志
添加 tcpInput.conf 文件:
1 | input { |
运行 Logstash:
1 | bin/logstash -f tcpInput.conf |
使用 TPC/IP 调试工具连接5000端口并输入任意内容,Logstash 输出以下内容:
1 | { |
从Redis中读取日志
添加 redisInput.conf 文件:
1 | input { |
运行 Logstash:
1 | bin/logstash -f redisInput.conf |
使用Redis客户端工具,并向 logstash-list 键中添加任意值:
1 | 127.0.0.1:6379> RPUSH logstash-list "log from redis NO.1" |
Logstash 输出以下内容:
1 | { |
将日志输出到文件中
添加 fileOutput.conf 文件:
1 | input { |
运行 Logstash:
1 | sudo bin/logstash -f fileOutput.conf |
输入测试内容:
1 | hello world |
查看 /var/log/test.log 文件内容:
1 | hello world |
将日志输出到TCP中
添加 tcpOutput.conf 文件:
1 | input { |
首先在服务器上运行 TCP Server ,并监听5000端口,然后运行 Logstash:
1 | bin/logstash -f tcpOutput.conf |
输入测试内容:
1 | tcp out |
查看TCP Server,收到以下数据:
1 | {. "message".[0;37m => .[0m.[0;33m"tcp out ".[0m,. "@version".[0;37m => .[0m.[0;33m"1".[0m,. "@timestamp".[0;37m => .[0m"2015-07-04T01:27:34.469Z",. "host".[0;37m => .[0m.[0;33m"ubuntu".[0m.}. |
将日志输出到Redis中
添加 redisOutput.conf 文件:
1 | input { |
运行 Logstash:
1 | bin/logstash -f redisOutput.conf |
输入测试内容:
1 | redis out testt |
使用Redis客户端工具查看logstash-list的值:
1 | 127.0.0.1:6379> lrange logstash-list 0 -1 |
结论
本篇只是 Logstash 最基础的安装和测试,若要应用到生产中,还有更多内容要深入掌握。