一、rsyslogd服務(wù)管理系統(tǒng)日志,隨機(jī)啟動
[root@linuxidc rsyslog.d]# systemctl is-active rsyslog.service
active
[root@linuxidc rsyslog.d]# systemctl is-enabled rsyslog.service
enabled
rsyslog的配置文件為/etc/rsyslog.conf,日志文件存儲在/var/log目錄下面,;
日志的7個級別,debug級別僅用于調(diào)試,也是最低的級別:
1、info;2、notice;3、warning;4、err;5、crit;6、alert;7、emerg;
在配置文件里面每個事件都會對應(yīng)一個級別,*代表所有級別,-/var/log/mail,“-”代表非同步,內(nèi)存和硬盤非同步讀寫,先讀到內(nèi)存,再寫硬盤,源于兩者讀寫速度不同,如:mail.*,mail.emerg:
所有等于或高于info級別(除mail外)的事件級別都會被記錄到/var/log/messages文件,debug信息低于info級別,所以不會被記錄到messages里面;
# Log anything (except mail) of level info or higher.
53 # Don't log private authentication messages!
54 *.info;mail.none;authpriv.none;cron.none /var/log/messages
為了驗(yàn)證以上的配置,可以配置local7的debug級別事件,記錄倒/var/log/xx目錄下面,使用logger命令模擬debug事件,驗(yàn)證信息是否寫到messages和xx里面:
72 # Save boot messages also to boot.log
73 local7.* /var/log/boot.log
74 local7.debug /var/log/xx
[root@linuxidc rsyslog.d]# logger -P local7.debug XXXXXXXXXXXXXXXXXX
如果日志需要發(fā)送給遠(yuǎn)端服務(wù)器記錄,則需要在遠(yuǎn)端服務(wù)器日志配置文件先開啟接受遠(yuǎn)端日志:
14 # Provides UDP syslog reception
15 $ModLoad imudp
16 $UDPServerRun 514
17
18 # Provides TCP syslog reception
19 $ModLoad imtcp
20 $InputTCPServerRun 514
在近端的配置文件寫成:
1 74 local7.debug @192.168.100.100
查看日志內(nèi)容,除了可以使用tail,tailf之外,還可以使用journalctl:
[root@linuxidc log]# journalctl
-- Logs begin at Wed 2015-01-07 23:28:05 CST, end at Thu 2015-01-08 11:10:02 CST. --
Jan 07 23:28:05 localhost.localdomain systemd-journal[207]: Runtime journal is using 6.1M (max 49.3M, leaving 74.0M of free 487.3M, cu
Jan 07 23:28:05 localhost.localdomain systemd-journal[207]: Runtime journal is using 6.1M (max 49.3M, leaving 74.0M of free 487.3M, cu
Jan 07 23:28:05 localhost.localdomain kernel: Initializing cgroup subsys cpuset
journalctl的常用命令:
[root@linuxidc log]# journalctl --help
journalctl [OPTIONS...] [MATCHES...]Flags:
--system Show only the system journal
--user Show only the user journal for the current user
--since=DATE Start showing entries on or newer than the specified date 從什么時間開始
--until=DATE Stop showing entries on or older than the specified date 到什么時間
-k --dmesg Show kernel message log from the current boot
-u --unit=UNIT Show data only from the specified unit
--user-unit=UNIT Show data only from the specified user session unit
-p --priority=RANGE Show only messages within the specified priority range查看特定級別的事件
-e --pager-end Immediately jump to end of the journal in the pager
-f --follow Follow the journal
[root@linuxidc log]# journalctl --since=2015-01-08 --until=2014-01-09 -p err
2015職稱計(jì)算機(jī)考試書PowerPoint2007中 .. 定價(jià):¥45 優(yōu)惠價(jià):¥42 更多書籍 | |
2015年全國職稱計(jì)算機(jī)考試教材(2007模 .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書籍 |