系统环境
服务端搭建
mkdir /home/log
- 编辑rsyslog配置文件:/etc/rsyslog.conf
$ModLoad imudp #开启UDP 514
$UDPServerRun 514
$ModLoad imtcp #开启TCP 514
$InputTCPServerRun 514
$template RemoteLogs,"/home/log/%HOSTNAME%/%PROGRAMNAME%.log" * #设置日志模板
*.* ?RemoteLogs
& ~
service rsyslog restart
firewall-cmd --add-port 514/tcp
firewall-cmd --add-port 514/tcp --permanent
firewall-cmd --add-port 514/udp
firewall-cmd --add-port 514/udp --permanent
setenforce 0
sed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/selinux/config
- 回滚日志:/etc/logrotate.d/slog
/home/log/*/*.log {
monthly
rotate 12
missingok
delaycompress
compress
}
*.* @@172.21.100.77:514 #将日志发送到100.77 的 TCP 514端口
service rsyslog restart