|
环境:logstash版本:5.0.1&&filebeat 5.0.1
ABC为三台服务器。保证彼此tcp能够相互连接。
Index服务器A - 接收BC两台服务器的tomcat日志 /var/tomcat/logs/ca**.out 此服务器安装logstash。安装过程
logstash服务器启动:logstash -f indexer.conf --config.reload.automatic
Shipper服务器B,C - 发送tomcat日志。此服务器安装filebeat。filebeat的安装方法
不同系统filebeat的启动方式。
deb:
sudo /etc/init.d/filebeat start
rpm:
sudo /etc/init.d/filebeat start
mac:
sudo ./filebeat -e -c filebeat.yml -d "publish"
win:
PS C:\Program Files\Filebeat> Start-Service filebeat
A服务器logstash配置文件:
input { beats {
port
=> "5044" }
}
output {
file {
path
=> "/data/log/logstash/all.log" # 指定写入文件路径 codec
=> line { format => "%{host} %{message}" } # 指定写入格式 flush_interval
=> 0 # 指定刷新间隔,0代表实时写入
}
stdout {
codec
=> rubydebug }
}
BC服务器filebeat配置文件:
filebeat.prospectors:
- input_type: log
paths:
- /install/tomcat/logs/catalina.out
exclude_lines: [
"^debug"] --按照正则规则,去掉开头为debug的句子 include_lines: [
"^err", "^warn"]--按照正则规则,去掉开头为err或者warn的句子
#
----------------------------- Logstash output --------------------------------
output.logstash:
# The Logstash hosts
hosts: [
"url:5044"]
测试:
监视A服务器的日志:tail -f /data/log/logstash/all.log
可以稍微加点颜色:tail -f /data/log/logstash/all.log | awk '{ if (match($0, /.*(ERROR|WARN).*/)) { print "\033[41;37;1m"$0"\033[0m" } else { print $0 } }'
B服务器:echo "hello world" >> /install/tomcat/logs/catalina.out
A服务器输出:hello
参考文档:https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-starting.html |
|
|
|
|
|
|