下面以**常见 Linux 环境(rsyslog / syslog-ng)**为例,说明如何配置 Syslog 远程采集(即把日志发送到远程日志服务器,或从远程接收日志)。
vim /etc/rsyslog.conf
module(load="imudp")
input(type="imudp" port="514")
module(load="imtcp")
input(type="imtcp" port="514")
template(name="RemoteLogs" type="string"
string="/var/log/remote/%HOSTNAME%/%PROGRAMNAME%.log")
if ($fromhost != "localhost") then {
action(type="omfile" fileTemplate="RemoteLogs")
}
systemctl restart rsyslog
firewall-cmd --add-port=514/udp --permanent
firewall-cmd --add-port=514/tcp --permanent
firewall-cmd --reload
vim /etc/rsyslog.conf
*.* @192.168.1.100:514
*.* @@192.168.1.100:514
auth.* @@192.168.1.100:514
systemctl restart rsyslog
source s_net {
udp(ip(0.0.0.0) port(514));
tcp(ip(0.0.0.0) port(514));
};
destination d_remote {
file("/var/log/remote/$HOST/log");
};
log {
source(s_net);
destination(d_remote);
};
destination d_syslog {
tcp("192.168.1.100" port(514));
};
log {
source(s_src);
destination(d_syslog);
};
logger "syslog test message"
ls /var/log/remote/
tail -f /var/log/remote/<hostname>/*.log
如果你有 特定系统(如 Cisco、Windows、容器、K8s) 或 使用 TLS 加密 的需求,我可以给你更针对性的配置示例。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。