centos 搭建 rsyslog 服务
centos 搭建 rsyslog 服务
1、关闭selinux
查看selinux状态 sestatus –v
修改/etc/sysconfig/selinux文件中的SELINUX=enforcing为SELINUX=disabled,如下配置文件。
Selinux是内核级别的访问控制的安全模块,所以修改完必须重启系统。
2、设置防火墙
systemctl start firewalld # 启动,
systemctl enable firewalld # 开机启动
systemctl stop firewalld # 关闭
systemctl disable firewalld # 取消开机启动
systemctl status firewalld # 防火墙状态
service firewalld restart # 重启
firewall-cmd --permanent --add-port=514/tcp
firewall-cmd --permanent --add-port=514/udp
firewall-cmd --reload # 重启防火墙
3、centos rsyslog 服务端
yum install -y rsyslog
vim /etc/rsyslog.conf
修改前:
# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
修改后:
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
##这里是服务端添加的配置 begin
# 使用RemoteLogs模板接受客户端的日志,保存到本地的/var/log/remote目录下,然后是每台客户端的ip_年份_月份_日期的log
$template RemoteLogs,"/var/log/remote/%fromhost-ip%/%fromhost-ip%_%$YEAR%-%$MONTH%-%$DAY%.log"
# 所有服务所有级别的日志都记录
*.* ?RemoteLogs
#服务端本机的日志不记录
:fromhost-ip, !isequal, "127.0.0.1" ?Remote
#指示rsyslog在将消息写入文件后停止处理消息。如果不包含"& ~",则消息将被写入本地文件,导致消息被记录2次。
& ~
## 在这里,有些情况会导致rsyslog服务重启或者启动失败。
##这里是服务端添加的配置 end
重启rsyslong服务
systemctl restart rsyslog
4、centos rsyslog 客户端
vim /etc/rsyslog.conf
auth.*;authpriv.*;cron.* @@ip:514
重启rsyslong服务
systemctl restart rsyslog
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器