linux日志服务器-rsyslog

2024-04-22 11:02:11 阅读:3 编辑

服务端

先创建/var/log/rsyslog目录

mkdir /var/log/rsyslog

编辑/etc/rsyslog.conf

vi /etc/rsyslog.conf

/etc/rsyslog.conf(添加以下代码-使用UDP)

$ModLoad imudp
$UDPServerRun 514
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template DynamicFile,"/var/log/rsyslog/%fromhost-ip%.log"
*.* ?DynamicFile

客户端

/etc/rsyslog.conf(添加以下代码-使用UDP)

172.24.226.12-表示服务端IP

*.* @172.24.226.12:514
*.* @174.0.36.10:514

指定哪些需备份

local7.* @174.0.36.11:514
cron.* @174.0.36.11:514
kern.* @174.0.36.11:514

重启rsyslog服务

systemctl restart rsyslog

查看514端口(rsyslog服务端口)是否开启

netstat -nalp|grep 514
如果删除日志,也要重启服务

注意事项:

1.rsyslog不能两台服务器相互备份(就是即当服务端又当客户端)

https://www.cnblogs.com/chenny7/p/3942246.html