logstash-安装
2024-09-07 22:59:41
1.下载
cd /usr/local/src
wget https://mirrors.huaweicloud.com/logstash/7.8.0/logstash-7.8.0.tar.gz
tar -zxvf logstash-7.8.0.tar.gz
2.启动测试
执行命令:
bin/logstash -e 'input { stdin { } } output { stdout {} }'
输出:
[2020-09-23T10:09:21,198][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
hello
{
"@timestamp" => 2020-09-23T14:09:25.158Z,
"message" => "hello",
"@version" => "1",
"host" => “localhost.localdomain"
3.json输出
执行命令:
bin/logstash -e 'input { stdin {} } output { stdout { codec => json } }'
输出:
[2020-09-23T10:15:44,836][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
hello
{"@timestamp":"2020-09-23T14:16:15.777Z","host":"localhost.localdomain","message":"hello","@version":"1”}
4.把命令放在文件中使用
vim test.conf
input {
stdin { }
}
output {
stdout { }
}
执行命令:
bin/logstash -f test.conf
输出:
[2020-09-23T10:22:12,515][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
hello
/usr/local/src/logstash-7.8.0/vendor/bundle/jruby/2.5.0/gems/awesome_print-1.7.0/lib/awesome_print/formatters/base_formatter.rb:31: warning: constant ::Fixnum is deprecated
{
"message" => "hello",
"@version" => "1",
"host" => "localhost.localdomain",
"@timestamp" => 2020-09-23T14:22:39.016Z
}
5.监控指定文件
vim test1.conf
input {
file { path => "/tmp/hello.log" }
}
output {
stdout { }
}
//或者
input {
file { path => "/tmp/hello.log" }
}
output {
stdout {
codec => "json"
}
}
执行命令:
bin/logstash -f test1.conf
另外开一个窗口 输入日志到文件
[root@localhost logstash-7.8.0]# echo hello >> /tmp/hello.log
[root@localhost logstash-7.8.0]# echo world >> /tmp/hello.log
输出:
[2020-09-23T10:27:29,766][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
/usr/local/src/logstash-7.8.0/vendor/bundle/jruby/2.5.0/gems/awesome_print-1.7.0/lib/awesome_print/formatters/base_formatter.rb:31: warning: constant ::Fixnum is deprecated
{
"host" => "localhost.localdomain",
"@timestamp" => 2020-09-23T14:27:44.789Z,
"message" => "hello",
"@version" => "1",
"path" => "/tmp/hello.log"
}
{
"host" => "localhost.localdomain",
"@timestamp" => 2020-09-23T14:27:58.948Z,
"message" => "world",
"@version" => "1",
"path" => "/tmp/hello.log"
}
6.监控文件输出到elasticsearch
input {
file{ path => "/deng/log/host.log"
type => "log"
start_position => "beginning"
}
}
output {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => “ml"
}
}
执行命令:
bin/logstash -f test.conf
7.过滤器插件 grok
vim test3.conf
input {
file { path => "/deng/log/host.log" }
}
filter {
grok {
match => { "message" => "%{IP:client} %{WORD:method} %{URIPATHPARAM:request} %{NUMBER:bytes}" }
}
}
output { stdout { } }
另外开一个窗口 输入日志到文件:
[root@localhost logstash-7.8.0]# echo "55.3.244.1 GET /index.html 15824" >> /tmp/hello.log
输出:
{
"client" => "55.3.244.1",
"@timestamp" => 2020-09-23T14:45:44.770Z,
"@version" => "1",
"method" => "GET",
"request" => "/index.html",
"path" => "/tmp/hello.log",
"host" => "localhost.localdomain",
"bytes" => "15824",
"message" => "55.3.244.1 GET /index.html 15824"
}
8.使用remove_field去掉message这一行的信息
filter{
mutate {
remove_field => ["message","timestamp"]
}
}
9.添加字段
mutate {
split => ["message", "|"]
add_field => {
"timestamp" => "%{[message][0]}"
}
}
}
最新文章
- Java IO3:字节流
- [嵌入式开发板]iTOP-4412开发板linux 系统存储空间的修改
- [百度空间] [转]程序员趣味读物:谈谈Unicode编码
- TinyXML:一个优秀的C++ XML解析器[转]
- opencv for android sample导入有误
- QueryPerformanceFrequency 和 QueryPerformanceCounter用法
- Qt 自定义事件详细实例(继承QEvent,然后QCoreApplication::postEvent()、sendEvent())
- Struts2六、为应用指定多个配置文件
- Windows Azure Storage
- JSTL判断list的size()大小
- 关于jsp中的文件下载
- python的占位格式符 %
- C#线程同步(1)- 临界区&Lock
- 雷林鹏分享:jQuery EasyUI 数据网格 - 格式化列
- 实现一个简易版的SpringMvc框架
- LeetCode 617 Merge Two Binary Trees 解题报告
- 邂逅明下 HDU - 2897
- MT【168】还是两根法
- JTAG - Debug Cable Driver/Receiver
- python对象反射和函数反射
热门文章
- “未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”的解决方案
- 你准备好开始DevOps了吗?
- Traveling by Stagecoach(POJ 2686)
- 利用 QEMU USER 模式运行 mips 程序
- gcc之__attribute__简介及对齐参数介绍
- SpringCloud OpenFeign Post请求的坑
- Oracle sqlplus中退格键、DEL键、上下左右键无法使用乱码问题
- 分布式文件系统之FastDFS安装部署
- 天猫精灵对接1:outh对接
- Cypress系列(60)- 运行时的截图和录屏