新手入門也不知道什么日志分析服務好,鳥哥說logwatch,那我就從logwatch開始吧!
logwatch用到了emai發郵件,先從配置郵件發送sendmail開始:
- 安裝sendmail服務,我們是利用sendmail服務進性郵件的發送的
harvey@harvey-Virtual-Machine:~$ sudo apt-get install sendmail [sudo] password for harvey: 正在讀取軟件包列表... 完成 正在分析軟件包的依賴關系樹 正在讀取狀態信息... 完成
- 安裝好服務后,就是查看服務的狀態,如果沒有開啟就把他開啟
harvey@harvey-Virtual-Machine:~$ sudo service sendmail status [sudo] password for harvey: MSP: is run via cron (20m) #表示服務已經開啟了 MTA: 17646 /usr/sbin/sendmail-mta -Am -L sm-mta -bd -q10m UID PID PPID C STIME TTY TIME CMD root 17646 1 0 21:45 ? 00:00:00 sendmail: MTA: accepting connections Daemon Status: (process 18662) Console socket child Current number of children: 0 QueueDir free disk space (in blocks): 34795684 Load average: 0 Child Process 17646 Status: accepting connections
- 默認情況下sendmail安裝並啟動好后就可以直接發送郵件了
harvey@harvey-Virtual-Machine:~$ mail *********@gmail.com Cc: 14******1@qq.com Subject: 這是我用ubuntu發送的郵件 測試一下用ubutu直接發送log分析文件的可行性
- 檢測郵件有沒有發送成功,如果用mailq命令檢測郵件發送Queue為0,說明郵件已經被正常發送了。mailq命令是去查看/var/spool/mqueue文件夾下的文件,這個需要更改一下權限否則是進入不了的。關於/var/spool/mqueue下文件的詳細解釋請查閱這篇文章Sendmail郵件隊列管理
harvey@harvey-Virtual-Machine:~$ ll /var/spool/mqueue 總用量 8 drwxrwsrwx 2 smmta smmsp 4096 3月 22 12:01 ./ drwxr-xr-x 11 root root 4096 3月 21 21:44 ../
harvey@harvey-Virtual-Machine:~$ mailq MSP Queue status... /var/spool/mqueue-client is empty Total requests: 0 MTA Queue status... /var/spool/mqueue is empty Total requests: 0
- 即使mailq檢查到郵件已經發送了,也不代表你能夠在指定的郵箱里。因為發件人的格式為harvey@harvey-virtual-machine.mshome.net,我測試了QQ sina和gmail,只有gmail收到了並發在了垃圾箱里,QQ和sina的賬號都是拒絕接受的。如果你的郵件被拒絕,可以直接用mail命令查看你的收件箱,QQ和sian的服務器會給你發送郵件拒絕通知的。
#給QQ郵箱發送郵件后查看 harvey@harvey-Virtual-Machine:~$ mail "/var/mail/harvey": 1 message 1 new >N 1 Mail Delivery Subs 六 3月 22 12: 65/2616 Returned mail: see transcript for de ? #現在表示有一個新的郵件,直接回車就可以查看郵件內容 #我的被拒絕郵件有如下信息: #(reason: 550 Mail content denied. http://service.mail.qq.com/cgi-bin/help?subtype=1&&id =20022&&no=1000726)#打開后面的網址就是騰訊拒絕的理由 #用sina郵箱發送郵件后查看那 harvey@harvey-Virtual-Machine:~$ mail "/var/mail/harvey": 1 message 1 new >N 1 Mail Delivery Subs 六 3月 22 12: 70/2893 Returned mail: see transcript for de ? #回車查看有以下提示 #(reason: 550 #5.7.1 Your access to submit messages to this e-mail system has been rejec ted.)
如果希望啟動logwatch后用QQ郵件發送的話,必須把自己的發件地址添加到郵箱的白名單里。