Home | Mirror | Search

第 16 章 Logging

目錄

1. syslog, klogctl - read and/or clear kernel message ring buffer; set console_loglevel
1.1. /etc/sysconfig/syslog
1.2. /etc/syslog.conf
1.3. logger
1.4. To Log Messages Over UDP Network
2. logrotate - rotates, compresses, and mails system logs
2.1. /etc/logrotate.conf
2.2. /etc/logrotate.d/
2.2.1. apache2
2.2.2. mysql
2.2.3. cacti
3. remote syslog
3.1. syslog-ng
3.2. rsyslog

1. syslog, klogctl - read and/or clear kernel message ring buffer; set console_loglevel

1.1. /etc/sysconfig/syslog

enables logging from remote machines

# vim /etc/sysconfig/syslog

#SYSLOGD_OPTIONS="-m 0"
SYSLOGD_OPTIONS="-r -m 0"
			
# /etc/init.d/syslog restart
Shutting down kernel logger:                               [  OK  ]
Shutting down system logger:                               [  OK  ]
Starting system logger:                                    [  OK  ]
Starting kernel logger:                                    [  OK  ]
			

1.2. /etc/syslog.conf

*.*			@172.16.0.9
			

所有日誌將被重定向到172.16.0.9

[root@dev1 test]# service syslog restart
Shutting down kernel logger:                               [  OK  ]
Shutting down system logger:                               [  OK  ]
Starting system logger:                                    [  OK  ]
Starting kernel logger:                                    [  OK  ]
[root@dev1 test]#
			

1.3. logger

日誌的級別

emerg 系統已經不可用,級別為緊急
alert 警報,需要立即處理和解決
crit 既將發生,得需要預防。事件就要發生
warnig 警告
err 錯誤信息,普通的錯誤信息
notice 提醒信息,很重要的信息
info 通知信息,屬於一般信息
debug 這是調試類信息
			

#vi /etc/syslog.conf

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none;local1.none;local3.none /var/log/messages

#my log
local3.* /var/log/my.log
			

# service syslog restart
Shutting down kernel logger:                               [  OK  ]
Shutting down system logger:                               [  OK  ]
Starting system logger:                                    [  OK  ]
Starting kernel logger:                                    [  OK  ]
			

ping 192.168.0.1 | logger -it logger_test -p local3.notice
			

# cat /var/log/my.log
Jan 12 18:06:03 dev1 logger_test[10991]: PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
Jan 12 18:06:03 dev1 logger_test[10991]: 64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=0.746 ms
Jan 12 18:06:04 dev1 logger_test[10991]: 64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=0.713 ms
Jan 12 18:06:05 dev1 logger_test[10991]: 64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=0.924 ms
Jan 12 18:06:06 dev1 logger_test[10991]: 64 bytes from 192.168.0.1: icmp_seq=4 ttl=64 time=0.819 ms
Jan 12 18:06:08 dev1 logger_test[10991]: 64 bytes from 192.168.0.1: icmp_seq=5 ttl=64 time=0.667 ms
Jan 12 18:06:09 dev1 logger_test[10991]: 64 bytes from 192.168.0.1: icmp_seq=6 ttl=64 time=0.626 ms
Jan 12 18:06:10 dev1 logger_test[10991]: 64 bytes from 192.168.0.1: icmp_seq=7 ttl=64 time=0.665 ms
			

1.4. To Log Messages Over UDP Network

comments powered by Disqus