rsylog搭建

平台

CentOS Linux release 7.8.2003 (Core)

安装方法

1. 更新yum及epel
curl -s -o /etc/yum.repos.d/CentOS-Base.repo \
http://mirrors.aliyun.com/repo/Centos-7.repo

curl -s -o /etc/yum.repos.d/epel.repo \
http://mirrors.aliyun.com/repo/epel-7.repo

2. 安装
yum install rsyslog
3. 配置 RSyslog 接收远程日志
编辑 /etc/rsyslog.conf 文件,启用 UDP 和 TCP 接收
# Uncomment these lines to enable UDP and TCP reception
module(load="imudp")       # 需要取消注释
input(type="imudp" port="514")  # 需要取消注释

module(load="imtcp")       # 需要取消注释
input(type="imtcp" port="514")  # 需要取消注释

4. 配置日志存储位置
编辑 /etc/rsyslog.conf 文件,添加自定义日志文件位置:
# Add the following lines at the end of the file
if ($fromhost-ip != "127.0.0.1") then {
    action(type="omfile" dirCreateMode="0755" fileCreateMode="0644"
           File="/var/log/remote/%HOSTNAME%.log")
    stop
}
5. 创建日志目录并设置权限
mkdir -p /var/log/remote
6. 重启 RSyslog 服务
systemctl restart rsyslog
7. 开启防火墙端口
确保防火墙允许 UDP 和 TCP 514 端口:
sudo firewall-cmd --permanent --add-port=514/tcp
sudo firewall-cmd --permanent --add-port=514/udp
sudo firewall-cmd --reload





posted @ 2024-07-18 14:51  lifei888  阅读(5)  评论(0)    收藏  举报