2021-05-12 14:32:11
Linux基礎教學學習筆記10——分析和儲存紀錄檔
Linux基礎教學學習筆記10——分析和儲存紀錄檔
一、rsyslogd服務管理系統紀錄檔,隨機啟動
[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級別僅用於偵錯,也是最低的級別:
1、info;2、notice;3、warning;4、err;5、crit;6、alert;7、emerg;
在組態檔裡面每個事件都會對應一個級別,*代表所有級別,-/var/log/mail,“-”代表非同步,記憶體和硬碟非同步讀寫,先讀到記憶體,再寫硬碟,源於兩者讀寫速度不同,如: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
為了驗證以上的設定,可以設定local7的debug級別事件,記錄倒/var/log/xx目錄下面,使用logger命令模擬debug事件,驗證資訊是否寫到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
如果紀錄檔需要傳送給遠端伺服器記錄,則需要在遠端伺服器紀錄檔組態檔先開啟接受遠端紀錄檔:
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
檢視紀錄檔內容,除了可以使用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
二、系統時間管理與控制
使用timedatectl命令管理時間:
[root@linuxidc log]# timedatectl
Local time: Thu 2015-01-08 11:31:31 CST
Universal time: Thu 2015-01-08 03:31:31 UTC
RTC time: Thu 2015-01-08 11:31:32
Timezone: Asia/Chongqing (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
timedatectl常用命令:
[root@linuxidc log]# timedatectl --help
status Show current time settings
set-time TIME Set system time
set-timezone ZONE Set system timezone
list-timezones Show known timezones
set-local-rtc BOOL Control whether RTC is in local time
set-ntp BOOL Control whether NTP is enabled
相關文章