1, logstash 配置文件
[root@host1: ] cat /opt/logstash/kafka-to-tcp.yml
input {
kafka {
bootstrap_servers => "192.168.0.11:9092"
consumer_threads => 3
group_id => "logstash_123"
auto_offset_reset => "earliest"
topics => ["alertTopic1"]
codec => json { charset => "UTF-8" }
}
}
filter {
if ([ruleName] !~ ".*主机告警.*") {
drop {}
}
mutate {
remove_field => ["eventId","ruleId"]
gsub => [
"Msg" , "[\r|\n]" , ""
]
}
}
output {
file {
codec => json_lines { charset => "UTF-8" }
path => "/tmp/b.log"
}
tcp {
host => "192.168.0.11"
port => "514"
codec => plain {
format =>"%{TIME} 测试环境--ruleName:%{ruleName},Msg:%{Msg}\n"
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
2,调试并后台启动
- ./bin/logstash -f /xx/xx.yml
[root@host1: ] cat /usr/lib/systemd/system/logstashtcp.service
[Unit]
Description=Logstash
Requires=network.service
After=network.service
[Service]
LimitNOFILE=65536
LimitMEMLOCK=infinity
WorkingDirectory=/opt/logstash/
ExecStart=/bin/sh bin/logstash -f kafka-to-tcp.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
SuccessExitStatus=143
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
3, 修改logstash 服务日志路径
sed -i.bak 's@${sys:ls.logs}@/xx/yy@' config/log4j2.properties
重启logstash服务