# yum install -y syslog
$ Y/ {5 ^& p+ _- g. d0 _0 _安装完成,修改配置配置文件:
0 E. f, t4 R+ J1 Q2 l# vim /etc/rsyslog.conf) V& t, x! |0 _2 S" g- ?
! w$ E, d& N2 I
: ] R) F X* |- Asyslog配置文件/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 #跟*相反,表示什么也没有$ _, m$ ^/ F% d J. t1 v
action(动作)日志记录的位置 系统上的绝对路径 #普通文件 如:/var/log/XXX | #管道 通过管道送给其他的命令出来 终端 #终端 如:/dev/console @host #远程主机 如@10.1.1.1 用户 #系统用户 如:root * #登录到系统上的所有用户,一般emerg级别的日志是这样定义的$ P' n8 v( W* h0 r9 X) 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级别的信息1 o* a( Q5 ?, B( W3 ] t& o7 x6 y: i4 q
$ c$ e# H9 |5 V重启服务 #service rsyslog reload 注:不重启但能读到配置文件;不建议重启 设置转存的服务器地址
" H5 r( N# r. D7 q" m7 V* e: m) N# y& {+ L9 |- a' ^
*.* @@192.18.10.21:514# vim /etc/rsyslog.conf
2 a) e8 f0 H6 }" j6 B# r- R3 m8 W4 c9 D! O; K
# rsyslog v5 configuration file
" c8 T Q6 ?- q% W% a2 v1 Y- M% X9 D, ]# V: M: n. l
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
% i/ e& `, j: O! L* y# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
' ?: e" M2 c$ Z1 [0 y( Q H
1 b, o, T5 M' ?5 X#### MODULES ####+ J9 l& f9 x6 p- s0 q U2 f
; ?* _, Z7 {" j9 \. p, j
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)' p8 k! I+ V8 p# q, [% K
$ModLoad imklog # provides kernel logging support (previously done by rklogd)3 U8 c: s8 P0 Z8 R) {
#$ModLoad immark # provides --MARK-- message capability* p$ c% q- n, \' S8 Z
5 W1 `( G) _/ y1 q) h
# Provides UDP syslog reception9 i: x" ?6 q+ ~% I/ H" D
#$ModLoad imudp
$ |8 D( n$ q9 H#$UDPServerRun 514
& O N% z/ q u+ ^. Y3 e7 T0 `* A% L O
# Provides TCP syslog reception4 m* |. K& F9 _- r$ Y
#$ModLoad imtcp! P/ D6 {) i2 b- N# S
#$InputTCPServerRun 514
; t% w0 A+ t$ \/ e
' V5 x8 m$ Z" C5 n- t* |% ]6 E8 a
8 W3 R$ v0 J3 C#### GLOBAL DIRECTIVES ####
1 u3 Q1 I% m% o+ T& V* V" G/ K$ V5 s# F9 ?2 e
# Use default timestamp format& b1 t3 U D7 ~; Y# L
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
1 l y; I, j7 \ P {2 {/ H
; w" q+ @' |. a; |# File syncing capability is disabled by default. This feature is usually not required,
/ p/ Y# k; |6 K+ F ~5 B) ^# not useful and an extreme performance hit
# @& [" J* ~) n0 W4 u. Q; ^3 x#$ActionFileEnableSync on7 C4 U% n6 Q& D+ o: z/ X
0 }- I# W4 v; U, J' O( ~; E
# Include all config files in /etc/rsyslog.d/
' z6 l% Q: A. f* A7 ?) T$IncludeConfig /etc/rsyslog.d/*.conf
5 ~ _' A3 T: S# U) T2 p+ A( |
% S" _. M8 \$ o8 f9 \( q+ X, j2 M5 t: K/ d
#### RULES ####
1 U# |/ P' |- E7 F
3 y( y4 ]9 g6 X# Log all kernel messages to the console.3 v! \) L! O, K" j$ n- y
# Logging much else clutters up the screen./ n0 s1 f+ N7 \: h \: e o
#kern.* /dev/console" W, B* q9 z U) J
* g$ ~! x8 d6 H: b/ n* N q/ a# Log anything (except mail) of level info or higher.
3 S& I. Z( Z9 z" c6 y5 j# Don't log private authentication messages!
{8 ?2 w7 d% C6 A1 T*.info;mail.none;authpriv.none;cron.none /var/log/messages
_. }6 a2 ~ k% \) a: r" C
0 |7 [) |% i/ w' i9 q# The authpriv file has restricted access.
7 d! A1 S! h/ z3 D- o9 e6 G3 rauthpriv.* /var/log/secure
: R* E" E. M2 B( t4 H/ d K) H1 Z/ x! V
# Log all the mail messages in one place.) z3 M/ ^9 D. b" V/ m6 a' j
mail.* -/var/log/maillog
/ c$ x; ]4 a v. F+ r) f+ L, o9 b) ~ }& B8 h
" h, M I8 d1 o. I, u) j. a& v' E# Log cron stuff( D; | K7 k. a5 p1 t% C( l
cron.* /var/log/cron
, ~5 h+ [# T$ N, I2 d
3 [# g% s/ G, Z' Q( n7 B# Everybody gets emergency messages
4 b0 G, |$ Q( T0 z4 P7 ^- `*.emerg *
, \2 `% z) b C7 i+ ~- Z
9 r5 T- B8 s; }# Save news errors of level crit and higher in a special file.
; q- W& E$ T& r6 _uucp,news.crit /var/log/spooler
4 R8 c1 o# z& \6 i' h
, H8 ^! N5 [" u2 s0 @# Save boot messages also to boot.log# n0 A* M7 Y' A$ X/ l* M/ M
local7.* /var/log/boot.log/ r+ j3 W$ |$ r8 d: C
# n2 x) l. i+ p
( X' S6 g# D, `; B" c1 L
# ### begin forwarding rule ###
+ n8 y! u* H! i1 i% A# The statement between the begin ... end define a SINGLE forwarding
3 s6 K: N) O: H$ E: A4 U! L# rule. They belong together, do NOT split them. If you create multiple
+ a, P1 i. I- z% T: d# forwarding rules, duplicate the whole block!" r) m" L" P. m3 u
# Remote Logging (we use TCP for reliable delivery)
* ^4 f5 Y! [/ i& \$ \3 b8 E) E! z#+ M# C# i% z" Z; R0 T: G
# An on-disk queue is created for this action. If the remote host is) Z# a. e! U+ b. q
# down, messages are spooled to disk and sent when it is up again.
% g0 }( Y. B, \#$WorkDirectory /var/lib/rsyslog # where to place spool files
2 v6 J" ~5 O E% S#$ActionQueueFileName fwdRule1 # unique name prefix for spool files; o7 ]0 Q" E, H$ U7 ~ P
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
7 Y2 O+ X' Q2 ]/ x#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown6 U# o1 W v+ z4 t" N
#$ActionQueueType LinkedList # run asynchronously
& A. y- g2 Y2 I. }1 {" b A6 e, h#$ActionResumeRetryCount -1 # infinite retries if host is down
& C: M+ D1 o$ c V+ g# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional4 ?( B7 v5 S" k, y! M
#*.* @@remote-host:514; y- S( k3 V5 h( V: ]
*.* @@192.168.10.211:514
) q4 l+ f+ M% t5 ?9 I4 w* ~# ### end of the forwarding rule ###
g- |9 W e' u4 z' [7 o' y! I. }; y) U5 w- m7 }
# A template to for higher precision timestamps + severity logging
/ w. N9 K# A8 G% z. E0 U( g% u, h$template SpiceTmpl,"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
: \: z4 m& z" n# K+ d- f. J% J4 y6 H" x& D/ p( w
:programname, startswith, "spice-vdagent" /var/log/spice-vdagent.log;SpiceTmpl$ ?, m V6 }$ y. `
( ?- Q/ p* E8 f$ z) Q T
9 f7 b- P, J" G& A) F. K, j5 x) T y: t6 J4 c
重启日志服务:+ y2 e8 A" v5 N
service rsyslog restart6 u" l" j4 m( L& n7 @
1 ~! v% r$ U& T) X5 e- u v
# n5 { Y P& `! ~8 Z8 j Z; ?7 B) Z B7 J1 s& ]/ _" m# _; V) h
|