马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?开始注册
x
# yum install -y syslog
: D* x |! T9 M% I5 a安装完成,修改配置配置文件:) P& } `- [1 z
# vim /etc/rsyslog.conf) [0 [/ v* K# K1 F
5 D5 Q2 I' ~) Y+ y' U7 I
: @: z9 i% q$ A- c% L7 ^4 C) a
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 #跟*相反,表示什么也没有
2 I6 A2 ^7 A8 o( P action(动作)日志记录的位置 系统上的绝对路径 #普通文件 如:/var/log/XXX | #管道 通过管道送给其他的命令出来 终端 #终端 如:/dev/console @host #远程主机 如@10.1.1.1 用户 #系统用户 如:root * #登录到系统上的所有用户,一般emerg级别的日志是这样定义的4 @4 n6 `: Q* P P
定义格式列子: 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级别的信息3 ?$ [5 b0 e6 y1 e
0 E; h1 M5 D. t. K
重启服务 #service rsyslog reload 注:不重启但能读到配置文件;不建议重启 设置转存的服务器地址$ N7 P! D8 I( c7 a2 r0 b- M
+ L1 p0 [$ N+ I9 z- J3 g4 \5 x9 {
*.* @@192.18.10.21:514# vim /etc/rsyslog.conf 8 m) s- \+ D5 M b
# l6 `1 }# k/ L9 u/ Q+ L5 b% K6 ~# rsyslog v5 configuration file
( {7 ] S* q: o9 q# K2 l
- g6 F* l) j- B2 N w# h# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html" `! g3 m( i" H6 ?$ C
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html# _6 |* F1 m$ {( Z& o4 ]0 C- A4 v! I6 ?
( U0 `5 [. O4 k6 r7 H#### MODULES ####! V5 ]# D. o6 }7 v' Y2 ^
4 Z6 J/ C3 h/ U) L9 ?- D! D$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
! A( {+ }2 Z5 n0 h* Y$ModLoad imklog # provides kernel logging support (previously done by rklogd)
8 B3 d- m" @+ D/ j% l4 S#$ModLoad immark # provides --MARK-- message capability/ c# ?9 u4 A( ~" ]
& E9 D2 H. z- d# Provides UDP syslog reception
! _, V" }* M; E, l$ M _5 ~#$ModLoad imudp; M; `5 H5 x& _ D
#$UDPServerRun 514
7 I6 u; D+ r. B" E7 M3 P7 o! z/ i v8 [2 S2 C
# Provides TCP syslog reception# Q: h) F2 j4 B6 Q! ~$ E3 {
#$ModLoad imtcp
3 g6 G O) N( H3 P9 I#$InputTCPServerRun 514
# Z5 |( g, v- {% R" M0 E. W! N/ v, o% \
/ F& Z/ ~* W7 ~; m" S/ w# K#### GLOBAL DIRECTIVES ####8 g$ c. }5 v# j: g1 u2 V" N
) U+ E/ ~3 e# v1 @4 I
# Use default timestamp format
z) o' A7 F% d' c' {$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat; Q } R! _( e
0 j7 ^$ m9 f$ T9 Z+ W r s2 V+ l
# File syncing capability is disabled by default. This feature is usually not required, p5 g+ b/ |; j* q- N
# not useful and an extreme performance hit
0 F7 {( T, S2 X/ J W) y#$ActionFileEnableSync on' \7 ]: Q4 S6 x$ S
) C) V6 H2 [3 N% A: e3 M. [) E4 c0 b# Include all config files in /etc/rsyslog.d/
" F2 p; `: k' a# a4 v$IncludeConfig /etc/rsyslog.d/*.conf
- a& l9 q2 N0 Y) }5 I1 |
& ^* ?6 C+ v, L/ [- l
+ B4 o0 w, O) B1 e3 g$ H* v#### RULES ####2 a' r+ D5 O$ v$ |
7 e" A1 e% l" z- ^) u( n3 H) R/ t& V# Log all kernel messages to the console.7 o0 v) w* \4 H, t8 t% \/ b/ |4 l
# Logging much else clutters up the screen.7 Q+ b5 |" L& N
#kern.* /dev/console, `* _8 O' z/ U1 q1 z+ d. k% e, d' B
% ?# [6 r) ?' F9 d2 G I/ X0 R
# Log anything (except mail) of level info or higher.! q5 _) }, f* S$ |
# Don't log private authentication messages!
7 H5 B5 g( s5 `' Q. x*.info;mail.none;authpriv.none;cron.none /var/log/messages
* {# v! X/ W, h+ V
% \8 h( C6 v) X" A8 W# The authpriv file has restricted access.* F" t1 u T" A6 D1 U+ |- T
authpriv.* /var/log/secure
( K. C, O% h, v1 {/ y" M; t- h- J1 K/ Q) Y: O" Y8 N8 O
# Log all the mail messages in one place.- d, B& @ f' L
mail.* -/var/log/maillog
9 S' ~3 h$ ]: b6 ^7 _8 r e% R2 u! k" j: C
* }1 W+ O# p8 i( e0 P# c
# Log cron stuff
$ H7 I1 x! @: [8 ~cron.* /var/log/cron
O, @8 k1 k5 F# x S% A& H8 C
, m' k$ W1 F# ]5 X c- w# Everybody gets emergency messages
! d* |/ s W- `5 s2 n8 x*.emerg *" E( t/ \7 G6 Y9 I9 D! @; {
I5 `" c8 R* Q+ k4 L& I0 w) O
# Save news errors of level crit and higher in a special file.8 n$ {) C4 @4 B; M( ~4 ^+ Q( K
uucp,news.crit /var/log/spooler
) ]0 G$ j- ~" c) E" `& l& I" [ w$ [( }6 H7 m
# Save boot messages also to boot.log
+ Q& l6 d+ A" Y8 E. J* ^. slocal7.* /var/log/boot.log
& o& g6 n: U1 O1 V8 r' u6 H% @. o$ d- @: k5 H
t& u3 b3 v; h0 w2 _& H
# ### begin forwarding rule ### [. c5 R f+ i( |/ g6 y& G0 m
# The statement between the begin ... end define a SINGLE forwarding
" e3 b m$ [# i, M. }# rule. They belong together, do NOT split them. If you create multiple
! y" K- @ v6 |/ F. U k$ r( p# forwarding rules, duplicate the whole block!
! K; ]$ f8 Y; X# i+ N* g. g# Remote Logging (we use TCP for reliable delivery)
5 [& G' q, W4 E% q#- R/ i4 H+ a& M0 H9 e3 @% B7 X
# An on-disk queue is created for this action. If the remote host is
0 [( k0 t: }2 b- K6 H# down, messages are spooled to disk and sent when it is up again.7 g' C2 E3 ^4 d! E
#$WorkDirectory /var/lib/rsyslog # where to place spool files1 E7 [3 ?! V. T ~/ ?( [1 e
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files! u/ ?* K- U2 X4 y
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)4 k9 c1 s, L( b* M5 V6 k
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown2 U) Q# H/ F% c2 q
#$ActionQueueType LinkedList # run asynchronously
- }4 D' B5 [6 Q* w/ x- ^4 W, R#$ActionResumeRetryCount -1 # infinite retries if host is down
4 A; a6 r) a! T8 m _# |6 @( X: F# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional: d& r& o+ I4 ~: U
#*.* @@remote-host:514 j+ Q7 w- B* i8 ?- B7 C
*.* @@192.168.10.211:514- X4 B6 a$ Q* K. y2 O5 @1 n! P5 d
# ### end of the forwarding rule ###
0 J' z8 u3 A. u8 V+ H1 i
3 C0 \" ~- d* [2 d% Y0 m% m: W# A template to for higher precision timestamps + severity logging% d6 m {+ A# ^( ` n
$template SpiceTmpl,"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"! v H L7 j7 S3 B6 J
0 m0 a8 k$ M/ K! b! I0 @
:programname, startswith, "spice-vdagent" /var/log/spice-vdagent.log;SpiceTmpl
/ h# H% } Z7 O! M V2 g* |! `8 D
- K! f- ^. ]" S7 Y1 p* g3 H! u @# e, f5 M' [. ^2 t' k: J. Q
! T8 X( o8 U' N5 v重启日志服务:
7 U: R5 }8 l- J# f5 d! `, eservice rsyslog restart C( G- K6 s% t( C9 h5 A7 C
1 G: c9 F! J, o4 \" C& G
' j4 N/ I" Z( Z/ K. ^# F8 A) r/ f! |; c, _1 o6 k3 Z4 M* R
|