阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Rsyslog配置及使用教程

163次阅读
没有评论

共计 4373 个字符,预计需要花费 11 分钟才能阅读完成。

1.Rsyslog 介绍
Rsyslog is Rocket-fast System for Log processing.Rsyslog 是 CentOS6 系列默认的日志处理软件。Rsyslog 基于模块化设计,提供高性能,安全的日志处理系统。Rsyslog 是多线程的,支持 TCP,UDP,TLS,RELP.Rsyslog 实际上 syslog 的一个增强版本。

Rsyslog 配置及使用教程

2. 安装 Rsyslog

CentOS 下默认已经安装了 rsyslog
查看 rsyslog 运行状态

$service rsyslog status
rsyslogd (pid  7542) is running…

$ ps -ef|grep rsyslog|grep -v grep
root      1014    1  0  2014 ?        00:15:09 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5

这里 -c 5 是在 /etc/sysconfig/rsyslog 中定义的
$ cat /etc/sysconfig/rsyslog 
# Options for rsyslogd
# Syslogd options are deprecated since rsyslog v3.
# If you want to use them, switch to compatibility mode 2 by “-c 2”
# See rsyslogd(8) for more details
SYSLOGD_OPTIONS=”-c 5″

3. 配置 rsyslog

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)
$ModLoad imklog  # provides kernel logging support (previously done by rklogd)
#$ModLoad immark  # provides –MARK– message capability
 
# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
 
# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
 
 
#### GLOBAL DIRECTIVES ####
 
# 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/
$IncludeConfig /etc/rsyslog.d/*.conf
 
 
#### 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
 
# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure
 
# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog
 
 
# 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
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 ###

 

$ cat /etc/rsyslog.conf|grep -v -E “^#|^$”
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog  # provides kernel logging support (previously done by rklogd)
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
authpriv.*                                              /var/log/secure
mail.*                                                  -/var/log/maillog
cron.*                                                  /var/log/cron
*.emerg                                                *
uucp,news.crit                                          /var/log/spooler
local7.*                                                /var/log/boot.log

配置格式如下:

日志类型. 日志级别              日志处理方式

日志类型 说明
authpam 模块产生的日志
authprivssh,sftp 等的登录验证信息
cron 定时任务相关日志
kernel

————————————– 分割线 ————————————–

CentOS 上配置 rsyslog 客户端用以远程记录日志  http://www.linuxidc.com/Linux/2015-02/112989.htm

RHEL5.4 部署中央日志服务器之 rsyslog+Log Analyzer http://www.linuxidc.com/Linux/2012-01/51853.htm

CentOS 6.3 下利用 Rsyslog+LogAnalyzer+MySQL 部署日志服务器 http://www.linuxidc.com/Linux/2013-07/86956.htm

使用 rsyslog mysql 和 logAnalyzer 的日志服务器 http://www.linuxidc.com/Linux/2012-09/70717.htm

CentOS 6.3 下利用 Rsyslog+LogAnalyzer+MySQL 部署日志服务器 http://www.linuxidc.com/Linux/2013-07/86956.htm

RHEL5.4 部署中央日志服务器之 rsyslog+loganalyzer  http://www.linuxidc.com/Linux/2010-12/30801.htm

————————————– 分割线 ————————————–

Rsyslog 的详细介绍 :请点这里
Rsyslog 的下载地址 :请点这里

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计4373字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中