日志是記錄系統(tǒng)在什么時(shí)候有哪個(gè)進(jìn)程做了什么樣的行為,發(fā)生何種事件稼跳。日志有以下三個(gè)重要性:
解決系統(tǒng)方面的錯(cuò)誤
解決網(wǎng)絡(luò)服務(wù)的問題
過往事件記錄簿
通過查看屏幕上面的錯(cuò)誤信息以及日志文件的錯(cuò)誤信息,幾乎可以解決大部分的LInux問題
Linux常見的日志文件:/var/log/cron: 記錄crontab的日志
在這里可以查看你的例行性工作是否正確的執(zhí)行?運(yùn)行的過程中是否發(fā)生錯(cuò)誤价说?下面是一個(gè)cron日志的例子,時(shí)間鹦聪,主機(jī)他巨,服務(wù)名稱等信息:
May 28 21:34:05 localhost run-parts(/etc/cron.daily)[2806]: finished logrotate
May 28 21:34:05 localhost run-parts(/etc/cron.daily)[2787]: starting makewhatis.cron
May 28 21:34:07 localhost run-parts(/etc/cron.daily)[2964]: finished makewhatis.cron
- /var/log/dmesg:記錄系統(tǒng)在開機(jī)的時(shí)候內(nèi)核檢測(cè)過程所產(chǎn)生的各項(xiàng)信息充坑。
- /var/log/lastlog:可以記錄系統(tǒng)上面所有賬號(hào)最近一次登錄系統(tǒng)的相關(guān)信息。系統(tǒng)中的lastlog命令就是利用這個(gè)文件的記錄信息來(lái)顯示的染突。下面就是通過lastlog查看出來(lái)的結(jié)果,顯示除了每個(gè)用戶的最后一次的登陸時(shí)間辈灼。
ps_ftp_user_qa pts/0 101.81.5.71 Mon Jun 27 13:45:33 +0800 2016
sps_ftp_user_uat **Never logged in**
sps_ftp_user_prep **Never logged in**
sap_axalta_test pts/2 101.81.116.106 Thu May 31 15:00:52 +0800 2018
tmsdev pts/2 101.81.5.71 Tue Aug 2 10:56:22 +0800 2016
jessica pts/3 101.81.112.109 Tue Dec 27 10:03:40 +0800 2016
guora2 pts/3 101.81.112.109 Tue Dec 27 14:41:40 +0800 2016
tmstest pts/5 101.81.112.109 Fri Mar 3 11:38:20 +0800 2017
taiping_edi pts/0 101.81.112.109 Wed Feb 8 15:34:07 +0800 2017
- /var/log/maillog或/var/log/mail/*:記錄郵件的往來(lái)信息份企,其實(shí)主要記錄sendmail(SMTP 發(fā)信協(xié)議提供者)與dovecot(pop3收信協(xié)議提供者)所產(chǎn)生的信息。
比如我們自己搭建的smtp服務(wù)器用戶發(fā)送email巡莹,那么有的時(shí)候客戶反映沒有收到email司志,我們?cè)趺床槟靥鹱希渴紫染褪侨タ匆幌逻@個(gè)maillog,看看是否有發(fā)送記錄骂远,如果發(fā)送失敗或者被對(duì)方郵箱服務(wù)器拒收囚霸,這里都會(huì)有記錄信息的:
May 31 20:23:09 iZ23ozpjtzfZ postfix/smtp[11767]: 06E8AC2D69: to=<anne.qian@oocl.com>, relay=oocl-com.mail.protection.outlook.com[65.55.88.10]:25, delay=6.5, delays=0.16/0.02/2.6/3.8, dsn=2.6.0, status=sent (250 2.6.0 <e838da5d-6f13-0c3f-4576-3e14d554d60e@weikayun.com> [InternalId=176093659791, Hostname=KL1PR02MB1464.apcprd02.prod.outlook.com] 9280
bytes in 0.306, 29.600 KB/sec Queued mail for delivery)
May 31 20:23:09 iZ23ozpjtzfZ postfix/smtp[11767]: 06E8AC2D69: to=<colten.zhang@oocl.com>, relay=oocl-com.mail.protection.outlook.com[65.55.88.10]:25, delay=6.5, delays=0.16/0.02/2.6/3.8, dsn=2.6.0, status=sent (250 2.6.0 <e838da5d-6f13-0c3f-4576-3e14d554d60e@weikayun.com> [InternalId=176093659791, Hostname=KL1PR02MB1464.apcprd02.prod.outlook.com] 92
80 bytes in 0.306, 29.600 KB/sec Queued mail for delivery)
May 31 20:23:09 iZ23ozpjtzfZ postfix/smtp[11767]: 06E8AC2D69: to=<joy.ge@oocl.com>, relay=oocl-com.mail.protection.outlook.com[65.55.88.10]:25, delay=6.5, delays=0.16/0.02/2.6/3.8, dsn=2.6.0, status=sent (250 2.6.0 <e838da5d-6f13-0c3f-4576-3e14d554d60e@weikayun.com> [InternalId=176093659791, Hostname=KL1PR02MB1464.apcprd02.prod.outlook.com] 9280 byt
es in 0.306, 29.600 KB/sec Queued mail for delivery)
May 31 20:23:09 iZ23ozpjtzfZ postfix/smtp[11767]: 06E8AC2D69: to=<lloyd.li@oocl.com>, relay=oocl-com.mail.protection.outlook.com[65.55.88.10]:25, delay=6.5, delays=0.16/0.02/2.6/3.8, dsn=2.6.0, status=sent (250 2.6.0 <e838da5d-6f13-0c3f-4576-3e14d554d60e@weikayun.com> [InternalId=176093659791, Hostname=KL1PR02MB1464.apcprd02.prod.outlook.com] 9280 b
ytes in 0.306, 29.600 KB/sec Queued mail for delivery)
May 31 20:23:09 iZ23ozpjtzfZ postfix/smtp[11767]: 06E8AC2D69: to=<minato.liu@oocl.com>, relay=oocl-com.mail.protection.outlook.com[65.55.88.10]:25, delay=6.5, delays=0.16/0.02/2.6/3.8, dsn=2.6.0, status=sent (250 2.6.0 <e838da5d-6f13-0c3f-4576-3e14d554d60e@weikayun.com> [InternalId=176093659791, Hostname=KL1PR02MB1464.apcprd02.prod.outlook.com] 9280
bytes in 0.306, 29.600 KB/sec Queued mail for delivery)
May 31 20:23:09 iZ23ozpjtzfZ postfix/smtp[11767]: 06E8AC2D69: to=<roland.li@oocl.com>, relay=oocl-com.mail.protection.outlook.com[65.55.88.10]:25, delay=6.5, delays=0.16/0.02/2.6/3.8, dsn=2.6.0, status=sent (250 2.6.0 <e838da5d-6f13-0c3f-4576-3e14d554d60e@weikayun.com> [InternalId=176093659791, Hostname=KL1PR02MB1464.apcprd02.prod.outlook.com] 9280
bytes in 0.306, 29.600 KB/sec Queued mail for delivery)
- /var/log/messages:幾乎系統(tǒng)發(fā)生的錯(cuò)誤信息(或者重要信息)都會(huì)記錄到這個(gè)文件當(dāng)中
- /var/log/secure:基本上只要牽扯到需要輸入賬號(hào)密碼的程序,那么當(dāng)?shù)卿洉r(shí)(不管登錄正確與否)都會(huì)被記錄到這個(gè)文件中,包括系統(tǒng)的login程序激才,以及網(wǎng)絡(luò)聯(lián)機(jī)的ssh拓型,telnet等程序。如下面ssh的登錄信息:
May 31 21:24:28 iZ23ozpjtzfZ sshd[12680]: subsystem request for sftp
May 31 21:24:28 iZ23ozpjtzfZ sshd[12676]: pam_unix(sshd:session): session closed for user vantrans
May 31 21:24:28 iZ23ozpjtzfZ sshd[12682]: Accepted password for dayou from 10.46.227.33 port 41424 ssh2
May 31 21:24:28 iZ23ozpjtzfZ sshd[12682]: pam_unix(sshd:session): session opened for user dayou by (uid=0)
May 31 21:24:28 iZ23ozpjtzfZ sshd[12686]: subsystem request for sftp
May 31 21:24:28 iZ23ozpjtzfZ sshd[12682]: pam_unix(sshd:session): session closed for user dayou
May 31 21:24:28 iZ23ozpjtzfZ sshd[12688]: Accepted password for cosco_qa from 10.46.227.33 port 41426 ssh2
May 31 21:24:28 iZ23ozpjtzfZ sshd[12688]: pam_unix(sshd:session): session opened for user cosco_qa by (uid=0)
May 31 21:24:28 iZ23ozpjtzfZ sshd[12691]: subsystem request for sftp
- /var/log/wtmp,/var/log/faillog:這兩個(gè)文件可以記錄正確登錄系統(tǒng)者的賬戶信息(wtmp)與錯(cuò)誤登錄時(shí)所使用的賬戶信息(faillog)
- /var/log/httpd/,/var/log/news/,/var/log/samba/*:不同網(wǎng)絡(luò)服務(wù)會(huì)使用他們自己的日志文件案來(lái)記載它們自己產(chǎn)生的各項(xiàng)信息瘸恼。
常見的日志文件就是這幾個(gè)劣挫,通過分析這些文件,我們基本能夠解決大部分的Linux問題东帅。