# yum install -y syslog) \6 F/ ^3 ^1 g2 }
安装完成,修改配置配置文件:
{8 Y6 r, ] d% `0 n8 L# vim /etc/rsyslog.conf
0 v: k6 C, x |3 p. I
0 }" C1 {- f& w$ P; z* D
9 k$ |" ^3 P# Q7 L( e" h3 }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 #跟*相反,表示什么也没有8 `- r( [: A8 E3 F! ~
action(动作)日志记录的位置 系统上的绝对路径 #普通文件 如:/var/log/XXX | #管道 通过管道送给其他的命令出来 终端 #终端 如:/dev/console @host #远程主机 如@10.1.1.1 用户 #系统用户 如:root * #登录到系统上的所有用户,一般emerg级别的日志是这样定义的. ]" g$ @# m Y, ^$ s8 F
定义格式列子: 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级别的信息
% \( R8 _0 ?2 V+ H( `7 J' S, i , q- G ]* d7 K# ^1 _0 w" F
重启服务 #service rsyslog reload 注:不重启但能读到配置文件;不建议重启 设置转存的服务器地址
7 r6 N; J8 T$ e4 v. k) @1 A' b2 d W$ m+ x- G7 s/ p1 L' H6 E* q
*.* @@192.18.10.21:514# vim /etc/rsyslog.conf
; U c1 x: C; y7 L/ z K; _+ a6 B7 x* W) E% Z
# rsyslog v5 configuration file
% z! h; }, \5 |4 o
$ i# ]3 F2 t: W# z l8 s. U" X# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html$ \# x* o4 f( |
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
/ e! E( _, u/ K& a$ A: `6 q1 y( N6 ~& }( O7 Z2 E- G
#### MODULES ##### w' X I- W3 \8 T8 ?" B$ l. d1 j k2 m1 O
- b$ _# r7 S T: D$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
! ~) X8 A/ U- ~9 j' q$ModLoad imklog # provides kernel logging support (previously done by rklogd)1 C: R9 _+ [6 L7 m! C) ^) G Q
#$ModLoad immark # provides --MARK-- message capability$ K' x K$ |1 c
6 r) L1 W) D( w3 m8 V+ z
# Provides UDP syslog reception
* @; u% [/ Z% M0 x2 h#$ModLoad imudp2 H; y2 @; }# Y
#$UDPServerRun 514
' u& i* O ?$ s3 V( G; _, d& f0 w! J$ [, N
# Provides TCP syslog reception
* K8 |) C$ G1 z5 ^- O; _. H9 K3 i#$ModLoad imtcp9 b8 K, v* I- @6 S
#$InputTCPServerRun 514
- o, h# a) S* V# |( n/ b- M! r2 {! H1 ? ` a* x
! [3 \- u& i) P" Q! h C
#### GLOBAL DIRECTIVES ####
8 |% V. d3 W$ [# K- y$ D% {( p K# y& P. r: ^2 ~
# Use default timestamp format
% ^. }- P+ g7 X" C- W7 m: k% O$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat0 j( V6 w& I$ G a* f
, f L3 V* q9 H2 Y2 m4 l# File syncing capability is disabled by default. This feature is usually not required,
; h% g9 d: i& z5 l# not useful and an extreme performance hit
% \' y& R* M9 b8 _; B% `#$ActionFileEnableSync on
. l9 T9 Z" {- m* E% g l4 l" S9 J8 z. Y/ O- M. R' o
# Include all config files in /etc/rsyslog.d/
& K) W# x }& _ c$ ]$IncludeConfig /etc/rsyslog.d/*.conf
! H) t) ~0 _9 n$ x
3 A5 {+ u' q5 V8 {& x# y7 F' O1 j& V
8 y" i. ~0 T' W0 O2 i6 L#### RULES ####$ J- F# s1 T" P
2 H" y; L! L" f4 l3 J8 W# Log all kernel messages to the console.
/ k# w _. s& i: G# q7 W# Logging much else clutters up the screen.8 ^* |9 L& Z1 @; `
#kern.* /dev/console
" {9 x7 B1 A3 Q! i% n" c% ?, D6 r0 V0 B
# Log anything (except mail) of level info or higher.
]5 Z% j; L6 j! Y; Q! {9 S# D/ l# Don't log private authentication messages!8 |1 f3 ]$ M) f/ Q' |
*.info;mail.none;authpriv.none;cron.none /var/log/messages! Y: n, H) f* w" G1 B9 U
$ {/ Y1 h7 N0 P' p3 y% U* |
# The authpriv file has restricted access.
' ]/ A3 j( }# O0 O$ Uauthpriv.* /var/log/secure
0 D5 q! d# M3 A5 @- H, E% G5 e6 F% r! b# ?/ F( P$ A
# Log all the mail messages in one place.0 g: L$ [0 s+ b& Z8 b6 d' i
mail.* -/var/log/maillog
9 x' y2 g+ _6 ]/ E; S1 X9 J+ ?6 f( G9 y- m. L
( u \8 X3 n# Z1 J, w$ X
# Log cron stuff
" Y4 z3 ?6 R( ycron.* /var/log/cron
) |: q! |/ V# `4 U/ X3 g0 a2 }
( e/ R" N$ Q5 \) t: Z8 |8 x# Everybody gets emergency messages3 c( S% P! g z) S& e
*.emerg *
/ d. k# D# `+ P3 M1 p, H7 S3 f5 Z* s- d7 N& Z
# Save news errors of level crit and higher in a special file.
4 L L( A" S. ~% B5 u- O) luucp,news.crit /var/log/spooler2 P, P, M+ K ?- v0 L7 p7 K
5 g; T& C& ~5 ~: G$ e
# Save boot messages also to boot.log( i; w; M% L; _ G* Q. T& `" E. g
local7.* /var/log/boot.log. \4 r4 L2 w& w0 O/ e( _9 E
: F& q+ y2 {; w# B, i) [" \2 }! ]/ D8 B. S# z# |, a/ N
# ### begin forwarding rule ###
5 b# T. l. U F0 a# The statement between the begin ... end define a SINGLE forwarding: k9 x$ k1 V+ N
# rule. They belong together, do NOT split them. If you create multiple
% Y0 M" n5 j7 o5 j* H# forwarding rules, duplicate the whole block!/ W0 k0 m# I4 y) o0 I+ {
# Remote Logging (we use TCP for reliable delivery)+ V8 H0 s% d" @6 i$ @5 D7 `2 v
#
$ o- \! {3 d1 u# An on-disk queue is created for this action. If the remote host is B$ g1 Z: k' B' B2 r" B
# down, messages are spooled to disk and sent when it is up again.
- F* T, }7 |! b- X- Z+ \) |#$WorkDirectory /var/lib/rsyslog # where to place spool files
; Z, b1 r. |( ^/ U! ` ?0 Y#$ActionQueueFileName fwdRule1 # unique name prefix for spool files( R; ?& Z! {: U4 o; V2 w
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)5 R& A2 d* t/ `7 D
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown I/ `& A; q5 d J3 S
#$ActionQueueType LinkedList # run asynchronously
W6 @. _5 ]5 \/ e, V#$ActionResumeRetryCount -1 # infinite retries if host is down5 s8 ]. _3 V0 t [2 z
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional% o; r" F" n1 ]7 Q- ^% [6 G6 y: Z
#*.* @@remote-host:514* P' I& Q9 b- G3 a. O* ^" m
*.* @@192.168.10.211:514, z+ V) a; ?) | f8 {
# ### end of the forwarding rule ###: X; ~( y3 z# e1 F- X1 g3 v
( F3 w3 Y0 s; G# A template to for higher precision timestamps + severity logging
|# I+ k C/ A$template SpiceTmpl,"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
" f3 W* l- p5 z5 M2 z4 w/ H: F s. ?5 e7 _' A
:programname, startswith, "spice-vdagent" /var/log/spice-vdagent.log;SpiceTmpl2 `: O0 M7 q8 b" M8 R$ O% K( Y9 b
; r5 L+ ?& ~* o6 K: D
/ f8 X* B% S* G
0 X/ x H8 W' u4 Y4 @! v* K重启日志服务:
4 B" H* `; ^; S2 v3 h8 k4 zservice rsyslog restart
, o+ {% V3 F0 V! e4 j1 @$ ]: g3 u
H5 N. {/ N9 |1 G5 M
; ?- x) h' W) E |