搭建日志服务器Rsyslog

Rsyslog介绍

Rsyslog的全称是 rocket-fast system for log,它提供了高性能,高安全功能和模块化设计。rsyslog能够接受从各种各样的来源,将其输入,输出的结果到不同的目的地。rsyslog可以提供超过每秒一百万条消息给目标文件。

特点

  • 多线程
  • 可以通过许多协议进行传输UDP,TCP,SSL,TLS,RELP;
  • 直接将日志写入到数据库;
  • 支持加密协议:ssl,tls,relp
  • 强大的过滤器,实现过滤日志信息中任何部分的内容
  • 自定义输出格式;

Rsyslog搭建

java 复制代码
rsyslog-server   10.10.10.61   收集服务器:服务端
rsyslog-client   10.10.10.67   发送服务器:客户端

rsyslog-server搭建-在服务端操作

java 复制代码
# 安装rsyslog
[root@rsyslog-server ~]# yum -y install  rsyslog

# 备份配置文件
[root@rsyslog-server ~]# cp /etc/rsyslog.conf{,.bak}

# 修改配置文件
[root@rsyslog-server ~]# vim /etc/rsyslog.conf
# 打开注释
$ModLoad imudp         # 使用udp协议,也可以使用tcp协议
$UDPServerRun 514      # 开启514端口

#### GLOBAL DIRECTIVES ####
# Use default timestamp format  # 使用自定义的格式
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template myFormat,"%timestamp% %fromhost-ip% %syslogtag% %msg%\n"
$ActionFileDefaultTemplate myFormat

# 根据客户端的IP单独存放主机日志在不同目录,rsyslog需要手动创建
$template RemoteLogs,"/var/log/rsyslog/%fromhost-ip%/%syslogtag%_%$YEAR%-%$MONTH%-%$DAY%-%$hour%:%$minute%.log"
# 排除本地主机IP日志记录,只记录远程主机日志
:fromhost-ip, !isequal, "127.0.0.1" ?RemoteLogs
# 忽略之前所有的日志,远程主机日志记录完之后不再继续往下记录
& ~

# 重启rsyslog服务
[root@rsyslog-server ~]# systemctl restart rsyslog

rsyslog-client-在客户端操作

java 复制代码
[root@rsyslog-client ~]# yum install -y rsyslog  httpd 
# 良好的习惯,从备份配置文件开始
[root@rsyslog-client ~]# cp /etc/rsyslog.conf{,.bak}   
# 修改配置文件
[root@rsyslog-client ~]# vim /etc/rsyslog.conf
# 打开注释
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

#设置日志服务器地址
*.* @10.10.10.61:514

开始测试

服务端操作

java 复制代码
# 服务端检查日志输出
[root@rsyslog-server ~]# tail /var/log/messages
Apr 27 15:10:25 server systemd: Started Session 5 of user root.
Apr 27 15:10:30 web systemd: Stopping The Apache HTTP Server...
Apr 27 15:10:30 web kernel: xfs filesystem being remounted at /tmp supports timestamps until 2038 (0x7fffffff)
Apr 27 15:10:30 web kernel: xfs filesystem being remounted at /var/tmp supports timestamps until 2038 (0x7fffffff)
Apr 27 15:10:31 web systemd: Stopped The Apache HTTP Server.
Apr 27 15:10:31 web systemd: Starting The Apache HTTP Server...
Apr 27 15:10:31 web kernel: xfs filesystem being remounted at /tmp supports timestamps until 2038 (0x7fffffff)
Apr 27 15:10:31 web kernel: xfs filesystem being remounted at /var/tmp supports timestamps until 2038 (0x7fffffff)
Apr 27 15:10:31 web httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.0.0.14. Set the 'ServerName' directive globally to suppress this message
Apr 27 15:10:31 web systemd: Started The Apache HTTP Server.

客户端操作

java 复制代码
# 客户端重启httpd
[root@rsyslog-client ~]# systemctl restart httpd

# 生成示例日志
logger -p "mail.info" "this is test log"

在服务端查看日志目录,发现有67的日志文件

相关推荐
Run_Teenage2 分钟前
Linux:进程等待
linux·运维·服务器
Trouvaille ~2 分钟前
【Linux】从磁盘到文件系统:深入理解Ext2文件系统
linux·运维·网络·c++·磁盘·文件系统·inode
为什么要内卷,摆烂不香吗10 分钟前
Grafana 12.2.0导入仪表盘
运维·grafana
乾元16 分钟前
AI 驱动的入侵检测与异常会话判别:从规则到行为分析前言:从“捕获敌人”到“守卫秩序”
运维·网络·人工智能·网络协议·安全
春日见19 分钟前
眼在手上外参标定保姆级教学(vscode + opencv)
linux·运维·服务器·数码相机·opencv·ubuntu·3d
梁下轻语的秋缘1 小时前
I2S与I2C
运维·stm32·单片机·51单片机
安达发公司1 小时前
安达发|效率革命:APS自动排程,为“金属丛林”安装精准导航
大数据·运维·人工智能·aps高级排程·aps排程软件·安达发aps·aps自动排程
科士威传动2 小时前
精密仪器中的微型导轨如何选对润滑脂?
大数据·运维·人工智能·科技·机器人·自动化
TracyGC2 小时前
Linux环境-RTX5080显卡CUDA12.8下安装mmcv/mmdetection3d
linux·运维·服务器
云老大TG:@yunlaoda3602 小时前
华为云国际站代理商NAT的高可用与弹性具体是如何实现的?
服务器·数据库·华为云·负载均衡