易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 4121|回复: 1
收起左侧

linux系统安装syslog

[复制链接]
发表于 2017-9-22 18:30:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
# yum install -y syslog& e( x% {# ^. W1 X/ q
安装完成,修改配置配置文件:
% f6 L% p+ a& N4 _' U# vim /etc/rsyslog.conf9 a' S) M' f. S" B5 J0 r0 y, [
3 B; A& A# r( U; i' M- E

! k- F8 b* 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                        #跟*相反,表示什么也没有+ r. {* T! M3 L* f/ u

action(动作)日志记录的位置

                系统上的绝对路径      #普通文件 如:/var/log/XXX

                |                                #管道 通过管道送给其他的命令出来

                终端                          #终端 如:/dev/console

                @host                      #远程主机  如@10.1.1.1

                用户                          #系统用户 如:root

                *                               #登录到系统上的所有用户,一般emerg级别的日志是这样定义的- S0 N6 ^9 p0 u4 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级别的信息
0 {0 m( f1 T+ Q- L; E


5 y! o# r  V* @4 E

重启服务

            #service rsyslog reload    注:不重启但能读到配置文件;不建议重启

设置转存的服务器地址* Y1 v+ B! x$ {+ J7 g7 b# L

# R8 ?5 t" C3 Y+ R5 C+ \: y* l1 J*.* @@192.18.10.21:514# vim /etc/rsyslog.conf ' D: S0 e' g5 \: p6 o( }$ t

* G7 @/ y! O6 [- u9 N! [( b# rsyslog v5 configuration file
$ b7 q- \4 h; X  a
5 M6 s! y1 ^5 o( n6 D5 y! Z, ~) i# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html. F: }% C* ~( E$ B/ [! {- k
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html5 b$ o  o2 z0 z% ?; P
. V' _# }; Q* T# D/ \
#### MODULES ####2 y( }) q  p. ^! w. \/ E! f% U/ B
  d4 a- s; |! R- d. L) Q
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
, c2 E8 ]  _1 V: {, M' R$ModLoad imklog   # provides kernel logging support (previously done by rklogd)
' v9 [# }) A& I8 }3 v$ H#$ModLoad immark  # provides --MARK-- message capability
5 `& {* j  D# V* z* l
8 S7 G8 Z$ f9 T+ D! `% @1 y) a( E# Provides UDP syslog reception
$ M2 m; c+ M8 m9 C  K$ C$ \) i0 J#$ModLoad imudp
0 n/ K/ p& ~. n+ s/ w4 y' M#$UDPServerRun 514
- j6 u0 I& \$ O* n' S
) i3 N4 r# E- f2 s3 z$ \$ Z# Provides TCP syslog reception
/ ]5 t  \9 m% B9 ?( \  P#$ModLoad imtcp
) ~( v& h  a& g/ I3 m3 ?; x* P#$InputTCPServerRun 514
0 w0 W. L7 o% W, x# z  s. X) T1 t2 j+ ^7 Q1 R# \

0 r% U3 L9 Z4 a, H; R#### GLOBAL DIRECTIVES ####% E0 p" r! K8 \- ~3 c
7 y  k, B8 n0 _# o) |/ S' a- ?% j
# Use default timestamp format( [& h* D% P6 W% \
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat8 h  m5 K  q& X; x- l4 D
  g! j* u2 \8 [- @+ E+ V- c6 D/ _
# File syncing capability is disabled by default. This feature is usually not required,
' ^: B. J. k  P& y6 R) M# not useful and an extreme performance hit
6 j2 b4 P0 {* E+ X#$ActionFileEnableSync on# o. s" r. v; |' S$ ^
1 d; W$ [4 r3 N; u7 `
# Include all config files in /etc/rsyslog.d/
; W9 ~: B* {0 k& U6 D- J7 A$IncludeConfig /etc/rsyslog.d/*.conf9 n: c$ S4 b% p0 X" R
% K. @0 y+ i3 C8 B: T
# T6 \$ {: ^3 B2 F
#### RULES ####1 f% ?% J! b. j5 E1 j

- h" m; r$ L# p/ Z& H' q# Log all kernel messages to the console.
4 p+ U- V8 R3 _: C5 C# Logging much else clutters up the screen.
4 Z+ o8 X0 P( L#kern.*                                                 /dev/console
5 t) s  }) Y  K) Y; r5 C$ i( N: P  C8 m9 D6 l! I1 O- \
# Log anything (except mail) of level info or higher.3 g4 q7 h2 j* F# c
# Don't log private authentication messages!
: ?; W8 P* l5 S, i' o( ^- Q*.info;mail.none;authpriv.none;cron.none                /var/log/messages% m1 Y0 h5 i7 n% y
1 l* O% b! d2 s; F! ^* V
# The authpriv file has restricted access.
; ^) ?8 L4 b( T" {7 t! [authpriv.*                                              /var/log/secure; E& v% b( M7 ]9 p2 H' y; {/ A

4 n1 V7 s! |( m) e" G4 b' G: K# Log all the mail messages in one place./ K; u: \4 ?) |. F7 P$ s$ E. n; n1 j
mail.*                                                  -/var/log/maillog! C8 S% o. p2 K- ?3 q* G/ F  @

4 F8 e4 J+ {; M  q% U" a; U) L. G* f: d7 y7 i/ {# n0 E
# Log cron stuff. x9 C. o+ i, L  @" e/ ?
cron.*                                                  /var/log/cron1 [/ E' z6 G1 F3 T

7 L) _$ [* @; m" g% A# Everybody gets emergency messages
. A! K9 J* Y  A' `8 x*.emerg                                                 *
6 P4 X# g( c& @, X6 H9 y2 j: ^. [4 M4 h' B  |9 g
# Save news errors of level crit and higher in a special file.
0 Z0 r) u7 X4 B, I3 s) D5 B0 puucp,news.crit                                          /var/log/spooler
8 Y6 a! r& K. o; Z8 O
" W8 g, p: ?$ F) \* l# A  B# Save boot messages also to boot.log
" |4 x$ d1 c! S5 wlocal7.*                                                /var/log/boot.log
+ G, `* v# D. ]4 S0 R! Z6 t" C! D/ L' I* z; U
) H7 `* S* K& |; g  z8 s' E
# ### begin forwarding rule ###
9 Y  }" f. k; |! V# The statement between the begin ... end define a SINGLE forwarding! N- W9 K) m  @! U5 ]) Y+ z
# rule. They belong together, do NOT split them. If you create multiple
; [3 c7 w, n3 ^6 |3 |' J; T  v# forwarding rules, duplicate the whole block!
" e2 p5 T# p' H$ p$ X$ z# Remote Logging (we use TCP for reliable delivery)$ d6 q( q: g% I3 L& h( F8 d
#  S" @7 E3 }( S! j6 `1 l+ J
# An on-disk queue is created for this action. If the remote host is  r3 L& A) Q& k, {, W( E' F
# down, messages are spooled to disk and sent when it is up again.) R# L+ |9 q. L. J* m1 A
#$WorkDirectory /var/lib/rsyslog # where to place spool files/ [+ T' x+ |/ g
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files# k' \. j! r" P* l, f
#$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)* M% I7 g' p* y- g3 {0 Q
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown. U( @' f9 X, |/ `1 O0 T# d
#$ActionQueueType LinkedList   # run asynchronously8 J8 a' a/ J* U# M* H1 u' I
#$ActionResumeRetryCount -1    # infinite retries if host is down' U2 E- Z# r- f: S* @7 p& a
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional% z/ C/ [& P4 g4 y5 L2 {6 y
#*.* @@remote-host:514
3 b% w  C, k9 u*.* @@192.168.10.211:514
' S+ [' r1 J; s2 ^% O7 Z: v8 @# ### end of the forwarding rule ###/ Z0 p( L2 Y& V) b+ v
- C6 ^7 Q: h2 n1 w4 H
# A template to for higher precision timestamps + severity logging/ p; V1 |  \& S* y. l6 R+ R
$template SpiceTmpl,"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
% t0 j8 F' B6 X. g! f% s& Z" I3 z6 d$ F7 o' N, S+ h
:programname, startswith, "spice-vdagent"        /var/log/spice-vdagent.log;SpiceTmpl7 \* v3 ?7 G+ J! S. f. @9 ~

. t% ]7 j' H* \# E9 Z" n6 \- e" U! t3 r  r
/ a  ]4 d1 e' [% m3 n
重启日志服务:
) p8 D  K' T+ K/ S1 K9 T6 `service rsyslog restart
; F! o/ p7 \3 G3 W
) G3 ~: o- Y4 T! _
: `; q( V% m( _& v' q" Z% o( b+ J. \0 E& l
 楼主| 发表于 2017-9-22 18:32:06 | 显示全部楼层
# service rsyslog restart3 L7 m& q+ Y4 d! }
关闭系统日志记录器:                                       [确定]3 \2 W5 p8 V7 {5 c/ X& `
启动系统日志记录器:-r option only supported in compatibility modes 0 to 2 - ignored  L' c1 z1 P# J( I" J, X
                                                           [确定]
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )点击这里给我发消息

GMT+8, 2026-4-8 23:58 , Processed in 0.057288 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表