# yum install -y syslog. G i( L, I" N% P
安装完成,修改配置配置文件:
; P6 q9 i/ f! i7 ^: J# vim /etc/rsyslog.conf
& y V$ k8 |, [: l
' V; e4 c0 L$ |6 H* M+ b" V9 R o8 W" h
syslog配置文件/etc/rsyslog.conf 注:centos 6 的配置文件是/etc/rsyslog.conf,centos5的配置文件是/etc/syslog.conf 5.配置文件定义格式为facility.priority action facility是指哪个facility来源产生的日志; priority是指拿个级别的日志 ;action是指产生日志怎么办是保存在文件中还是其他。。。 facility可以理解为日志的来源或设备或选择条件,目前常用的facility有以下几种: auth #认证相关的 authpriv #权限,授权相关的 cron #任务计划相关的 daemon #守护进程相关的 kern #内核相关的 lpr #打印相关的 mail #邮件相关的 mark #标记相关的 news #新闻相关的 security #安全相关的,与auth类似 syslog #syslog自己的 user #用户相关的 uucp #unix to unix cp相关的 local0到local7 #用户自定义使用 * #*表示所有的facility priority(log level)日志优先级的级别,一般分为以下几种级别(从低到高) 注:级别越低记录的越详细 debug #程序或系统的调试信息 info #一般信息 notice #不影响正常的功能,需要提醒用户的重要事件 warning/warn #可能影响系统功能,需要提醒用户的重要事件 err/error #错误信息 crit #比较严重的 alert #必须马上处理的 emerg/canic #会导致系统不可用的 * #表示所有的日志级别 none #跟*相反,表示什么也没有/ U6 u9 N1 ?) o! L9 e% F
action(动作)日志记录的位置 系统上的绝对路径 #普通文件 如:/var/log/XXX | #管道 通过管道送给其他的命令出来 终端 #终端 如:/dev/console @host #远程主机 如@10.1.1.1 用户 #系统用户 如:root * #登录到系统上的所有用户,一般emerg级别的日志是这样定义的
* M8 D9 M4 L. ]4 U5 g, W 定义格式列子: mail.info /var/log/mail.log #表示将mail相关的,级别为info及info以上级别的信息记录到/var/log/mail.log文件中 auth.=info @10.1.1.1 #表示将auth相关的,级别为info的信息记录到10.1.1.1主机上去,前提是10.1.1.1要能接收其主机发来的日志信息 user.!=error #表示记录user相关的,不包括error级别的信息 user.!error #表示user.error相反 *.info #表示记录所有的日志信息的info级别 mail.* #表示记录所有mail相关的所有级别的信息 *.* #表示记录所有的日志信息的所有的日志级别 cron.info;mail.info #多个日志来源可以用“ ; ”隔开 cron,mail.info #与cron.info;mail.info 是一个意思 mail.*;mail.!=info #表示记录mail相关的所有级别的信息,但是不包括info级别的信息
7 B' V. y, q6 J9 b u
/ C% z n, @4 I! x' o重启服务 #service rsyslog reload 注:不重启但能读到配置文件;不建议重启 设置转存的服务器地址
5 Q+ y9 l6 e0 u8 B) F! N. t+ B! \( l# h, q% d, |/ y1 F. v
*.* @@192.18.10.21:514# vim /etc/rsyslog.conf * k+ [: ~4 k) d
. Z# H1 _, I: ]2 |" g" U( O1 c# rsyslog v5 configuration file
; r" N1 f' x& L% m- ]7 W% s2 k4 a M
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
v( v2 T$ Z0 m# g# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
1 j5 s9 L" c% R8 K4 _( D' V: T" M* [- h. a e, F
#### MODULES ####7 ~2 h% U2 i' @( ] h6 [
* a8 O! @$ ^% A3 W7 }& e$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)8 Y( Z ~* h5 E& x% `
$ModLoad imklog # provides kernel logging support (previously done by rklogd)3 @5 Z1 j1 r* _; I' w1 p
#$ModLoad immark # provides --MARK-- message capability& _* [! a+ j/ M. z1 P+ V8 e
# }' G( G- o* k& S2 Y6 E- z# Provides UDP syslog reception; p6 `, Z1 X e" e- X$ ?
#$ModLoad imudp$ A' n8 _' ~) Q$ \% s8 |2 M
#$UDPServerRun 5141 q" \$ H) ^8 u. r8 Z4 f
, B$ f4 q) j+ u. L% e' f6 |# Provides TCP syslog reception' f1 R& R9 P8 |# c( ^! m
#$ModLoad imtcp" \ O# _0 I8 N0 F* u. q
#$InputTCPServerRun 514' b; S( o5 ^) |4 }, v7 b
! C* C0 N, I6 M) |- e7 A
4 m/ `. a; Y' G0 X! |0 Y
#### GLOBAL DIRECTIVES ####
) x \. [5 q) |) @4 {% b h" u4 {* M) T$ j' \, K) X
# Use default timestamp format/ d: p2 X' H) @+ o
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
7 m+ Q" ?( K8 M
5 r8 E$ i3 o* z; l, }# File syncing capability is disabled by default. This feature is usually not required,
1 N4 c$ r+ q: f& C3 Z2 l1 n# not useful and an extreme performance hit
2 e$ T# d# D4 {7 a: r2 S#$ActionFileEnableSync on
; Y7 W4 T7 D5 q
3 q0 F/ q- Y" ]8 c7 [& Z0 m: V4 d8 M# Include all config files in /etc/rsyslog.d/% C4 w* \ j7 F1 S- b' h
$IncludeConfig /etc/rsyslog.d/*.conf4 ^' a/ a+ n1 n4 p- r
5 L" D, L* Y9 Z" S/ \7 F5 Y
) z) ]; d( @/ X/ X! N#### RULES ####$ l3 s& W7 m* x" j' m- D! K
, z- M. O' P3 W _# Log all kernel messages to the console.
5 r+ C4 T7 U6 c. o, D# A7 n B# Logging much else clutters up the screen.& h) Z$ r( t1 }# n
#kern.* /dev/console6 \4 U+ |9 A0 ]3 ^( H
6 s1 ^2 w# d* v' { I# Log anything (except mail) of level info or higher.
' X6 ^: L2 L+ n: T2 |3 q: }# Don't log private authentication messages!9 j. Z* b0 ^6 z+ a0 I
*.info;mail.none;authpriv.none;cron.none /var/log/messages* i6 G; [( l6 K" D" m/ Y
' n: x [! w+ C; f! I+ t
# The authpriv file has restricted access.7 [& g/ u# c1 z6 O
authpriv.* /var/log/secure
& x: [$ h$ a5 z7 F. @ X, k4 [3 h( ` S( o, T( F& A* E" j6 y
# Log all the mail messages in one place.1 Z/ [6 J- c8 N( D1 ]" H
mail.* -/var/log/maillog' J3 C0 e# J& }1 u
4 D% }( V( h( p; ~6 Z ?/ C
& C/ h* G# h# Q- o
# Log cron stuff5 n2 ^: H# w6 ^* g$ [) [
cron.* /var/log/cron3 L4 k+ E+ W# v" ^
; O9 n8 B8 U1 U4 B; u) p# Everybody gets emergency messages X: s9 {, s' T; s/ E8 k- V6 X
*.emerg *
: e, s9 Q( K' I
# F+ ~+ `" u; W# Save news errors of level crit and higher in a special file., E, u* c/ R9 a; f
uucp,news.crit /var/log/spooler
3 V2 t' A1 ]8 L) m/ m: [9 V* r
6 K: X% L5 r" a: i# Save boot messages also to boot.log! `+ |( U( `9 I4 ?
local7.* /var/log/boot.log
! f5 A* |; {- a, g! K1 x2 {: D& W$ i$ i" M- ?, T. R- L, c
3 A! f( x7 k! O: P& O6 ]# ### begin forwarding rule ###
1 H+ j: T3 Z4 e* C2 _# The statement between the begin ... end define a SINGLE forwarding# ?: T( |4 B$ }3 c& T* E
# rule. They belong together, do NOT split them. If you create multiple; w; ~. o2 I7 I9 ^" x+ P8 ^9 o
# forwarding rules, duplicate the whole block!
0 P( a" b. W( Z# o' w* X# Remote Logging (we use TCP for reliable delivery)
5 B5 u) S. h1 u l" J4 H8 C#
! s {) z( Q! K! g l+ d, k. {# An on-disk queue is created for this action. If the remote host is+ W8 O" z$ B) W2 L& A
# down, messages are spooled to disk and sent when it is up again.
0 o; K0 g8 D" F. Q& }3 Y#$WorkDirectory /var/lib/rsyslog # where to place spool files
" [3 m- p' T# ^$ y; n' \' m#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
+ E) { I; D3 m& S, i#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
" t* D6 t$ N2 L3 r' F#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown; x) C" e( O" ~7 S6 m, B! _3 J
#$ActionQueueType LinkedList # run asynchronously6 b z6 C/ y6 j4 Z0 N3 X
#$ActionResumeRetryCount -1 # infinite retries if host is down; i1 C. X5 B/ ] g& g7 L- f2 d
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
: ~: Y3 n6 b' m" Y+ B8 ^+ b. g1 @#*.* @@remote-host:514$ r; L, H* g3 y. F- {
*.* @@192.168.10.211:514
: b; K6 t3 y! t& N* \2 o# ### end of the forwarding rule ###
* d9 Q$ y0 `5 T# r) | O% k, d$ v# `9 {
# A template to for higher precision timestamps + severity logging. d" I/ d' I7 v
$template SpiceTmpl,"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"' R" f$ D; x1 T3 W- ]# L3 u
' a7 s5 k8 D$ w8 j# R- D# x* O, L, W
:programname, startswith, "spice-vdagent" /var/log/spice-vdagent.log;SpiceTmpl
9 R7 @9 ^' y! Q. o( }- W1 M5 p2 C1 k' A2 f5 j, Q8 U- ^' S0 P4 S
/ D7 f2 @' C' ?$ U- y9 @0 f% f; A# ?/ } N# ^5 t# O
重启日志服务:
# g- \/ z9 W! b% Q5 U+ [service rsyslog restart% \8 L y- M- w4 m9 x' u# Q/ F! |
2 Y b& V, f F
% D& \ ?7 x4 \# }5 M) ~
5 y# f% Z5 R4 `: h5 Z! L3 u" J |