Linux下Rsyslog日志远程集中式管理

Rsyslog简介

  • Rsyslog的全称是 rocket-fast system for log,它提供了高性能,高安全功能和模块化设计。rsyslog能够接受从各种各样的来源,将其输入,输出的结果到不同的目的地。rsyslog可以提供超过每秒一百万条消息给目标文件。
  • 日志是任何软件或操作系统的关键组件。 日志通常会记录用户的操作、系统事件、网络活动等等,具体取决于它们的用途。 Linux 系统上使用最广泛的日志系统之一是 rsyslog 。
  • Rsyslog 是一个强大、安全和高性能的日志处理系统,它接受来自不同类型源(系统/应用程序)的数据并输出为多种格式。
  • 它已经从一个常规的 syslog 守护进程发展成为一个功能齐全的企业级日志系统。 它采用客户端/服务器模型设计,因此可以配置为客户端和/或其他服务器、网络设备和远程应用程序的*日志服务器。

功能特性:

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

Rsyslog提供了三种远程传输协议:

  • UDP 传输协议

  基于传统UDP协议进行远程日志传输,也是传统syslog使用的传输协议; 可靠性比较低,但性能损耗最少, 在网络情况比较差, 或者接收服务器压力比较高情况下,可能存在丢日志情况。 在对日志完整性要求不是很高,在可靠的局域网环境下可以使用。

  • TCP 传输协议

  基于传统TCP协议明文传输,需要回传进行确认,可靠性比较高; 但在接收服务器宕机或者两者之间网络出问题的情况下,会出现丢日志情况。 这种协议相比于UDP在可靠性方面已经好很多,并且rsyslog原生支持,配置简单, 同时针对可能丢日志情况,可以进行额外配置提高可靠性,因此使用比较广。

  • RELP 传输协议

  RELP(Reliable Event Logging Protocol)是基于TCP封装的可靠日志消息传输协议; 是为了解决TCP 与 UDP 协议的缺点而在应用层实现的传输协议,也是三者之中最可靠的。 需要多安装一个包rsyslog-relp以支持该协议。

对于线上服务器,为了日志安全起见,建议使用还是使用 RELP 协议进行传输。

Rsyslog架构阐述:

    Linux下Rsyslog日志远程集中式管理

    Linux下Rsyslog日志远程集中式管理  

环境准备

属性 Rsyslog服务器 Rsyslog客户端
节点 rsyslog-server rsyslog-client
系统 CentOS Linux release 7.5.1804 (Core) CentOS Linux release 7.5.1804 (Core)
内核 3.10.0-862.el7.x86_64 3.10.0-862.el7.x86_64
SELinux setenforce 0 | disabled setenforce 0 | disabled
IP地址 172.16.70.186 172.16.70.187

Rsyslog服务端

[root@rsyslog-server ~]# rpm -qa | grep rsyslog
[root@rsyslog-server ~]# yum install -y rsyslog

[root@rsyslog-server ~]# rsyslogd -v    # 查看版本
rsyslogd 8.24.0-57.el7_9, compiled with:
    PLATFORM:                x86_64-redhat-linux-gnu
    PLATFORM (lsb_release -d):
    FEATURE_REGEXP:                Yes
    GSSAPI Kerberos 5 support:        Yes
    FEATURE_DEBUG (debug build, slow code):    No
    32bit Atomic operations supported:    Yes
    64bit Atomic operations supported:    Yes
    memory allocator:            system default
    Runtime Instrumentation (slow code):    No
    uuid support:                Yes
    Number of Bits in RainerScript integers: 64

See http://www.rsyslog.com for more information.

[root@rsyslog-server ~]# rpm -qc rsyslog    # 相关配置文件
/etc/logrotate.d/syslog
/etc/rsyslog.conf
/etc/sysconfig/rsyslog

 默认/etc/rsyslog.conf详解。

# rsyslog v5 configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES #### # 模块

$ModLoad imuxsock # provides support for local system logging (e.g. via logger command) # 支持本地系统日志记录(例如通过logger命令)
$ModLoad imjournal # provides access to the systemd journal  # 提供对systemd日志的访问
#$ModLoad imklog # provides kernel logging support (previously done by rklogd) # 提供内核日志记录支持(以前由rklogd完成)
#$ModLoad immark # provides --MARK-- message capability # 提供了--MARK--消息功能 # Provides UDP syslog reception # 提供UDP系统日志接收 #$ModLoad imudp #$UDPServerRun 514 # Provides TCP syslog reception # 提供TCP系统日志接收 #$ModLoad imtcp #$InputTCPServerRun 514 #### GLOBAL DIRECTIVES #### # 全局设置
# Where to place auxiliary files ; 辅助文件路径
$WorkDirectory /var/lib/rsyslog
# Use default timestamp format # 使用默认的时间戳格式 $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # File syncing capability is disabled by default. This feature is usually not required, # 文件同步功能默认是关闭的。这个功能通常不是必需的 # not useful and an extreme performance hit #$ActionFileEnableSync on # Include all config files in /etc/rsyslog.d/ # 将所有配置文件包含在/etc/rsyslog.d/中 $IncludeConfig /etc/rsyslog.d/*.conf
# Turn off message reception via local log socket;  # 关闭本地日志消息,使用imjournal
# local messages are retrieved through imjournal now.
$OmitLocalLogging on

# File to store the position in the journal # 存放日志文件位置
$IMJournalStateFile imjournal.state
#### RULES #### # 规则 # Log all kernel messages to the console. # 将所有内核消息记录到控制台 # Logging much else clutters up the screen. #kern.* /dev/console # Log anything (except mail) of level info or higher. # 记录级别信息或更高级别的任何信息(邮件除外) # Don‘t log private authentication messages! # 不要记录私人认证信息! *.info;mail.none;authpriv.none;cron.none /var/log/messages # 记录info级别的日志信息 排除mail authpriv cron # The authpriv file has restricted access. # authpriv文件具有受限制的访问权限。 authpriv.* /var/log/secure # Log all the mail messages in one place. # 将所有的邮件记录在一个地方。 mail.* -/var/log/maillog # -/var/log/maillog 前面"-"是:代表异步写入,邮件量大占I/O在系统不忙时做 # Log cron stuff # 日志计划任务的东西 cron.* /var/log/cron # Everybody gets emergency messages # 每用户都得到紧急消息 *.emerg * # Save news errors of level crit and higher in a special file.  # 保存级别更高的错误信息的文件 uucp,news.crit /var/log/spooler # Save boot messages also to boot.log # 将启动信息保存到boot.log 只记录当前系统启动日志 local7.* /var/log/boot.log # ### begin forwarding rule ### # 开始转发规则 # The statement between the begin ... end define a SINGLE forwarding # rule. They belong together, do NOT split them. If you create multiple # forwarding rules, duplicate the whole block! # Remote Logging (we use TCP for reliable delivery) # # An on-disk queue is created for this action. If the remote host is # down, messages are spooled to disk and sent when it is up again. #$WorkDirectory /var/lib/rsyslog # where to place spool files #$ActionQueueFileName fwdRule1 # unique name prefix for spool files #$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) #$ActionQueueSaveOnShutdown on # save messages to disk on shutdown #$ActionQueueType LinkedList # run asynchronously #$ActionResumeRetryCount -1 # infinite retries if host is down # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional #*.* @@remote-host:514 # ### end of the forwarding rule ### 转发规则结束

 配置文件格式:

配置文件/etc/rsyslog.conf主要有3个部分
MODULES :模块
GLOBAL DRICTIVES :全局设置
RULES:规则

 

 

Linux下Rsyslog日志远程集中式管理

上一篇:常用快捷键以及DOS命令


下一篇:一个思路,利用T检验去寻找量化交易CTA趋势