Syslog

Troubleshooting Linux using syslog.conf

Posted in Linux , Technical by admin on January 11th, 2008

Different Linux packages have their own configuration files for Linux network configuration and troubleshooting. Due to this reason Linux system administration becomes daunting. However most of Linux applications use syslog utility for handling errors and status messages for the files stored in /var/log directory path. Linux troubleshooting for each Linux core like fedora, redhat and ubuntu etc becomes easy using syslog file. It is very useful to know that all applications do not display errors and status messages on computer screen. Linux log server contains Linux syslog file and logrotate utility makes it easier handle computer network troubleshooting same like windows network troubleshooting.
The error messages in syslog could be very helpful in finding malfunctions in the products manuals, items manuals and web searchers documentation. The both syslog and logrotate files relatively easy to configure but it needs some special skills to troubleshoot all Linux applications of which information is included in each Linux system syslog file. Syslog utility is used for tracking and handling all error messages which are critical in Linux system syslog server.
An error message contains tow information first function information which has generated it like applications such as mail and cron which could be identified easily and second is degree of severity of that error message. There are eight messages which could display in syslog file are listed below. Syslog’s configuration file like /etc/syslog.conf could be configured by placing all different facilities.
Table: Syslog facilities details
Severity Level Keyword Description
0 emergencies System not usable
1 alerts Action required immediately
2 critical Critical condition
3 errors Error conditions
4 warnings Warning conditions
5 notifications Significant and Normal conditions
6 informational messages with information
7 debugging Debugging messages

The /etc/syslog.conf File

Each type of message is written to syslog configuration file /etc/syslog.conf and this file contains two columns. First column contains facilities included in syslog and second column contains description of each keyword in syslog file. Redhat and Fedora /etc/syslog.conf file is configured to store all messages in file /var/log/messages like
*info;mail.none;authpriv.nono;cron.none /var/log/messages
In this message all info messages are logged in syslog without mail, cron or facilities. This logging could be more insightful by replacing this line and debug severity and /var/log/messages file. Here is a example
*.debug /var/log/messages

All syslog debug messages excluding auth,news,mail and authpriv are logged to /var/log/ debug file. You can however change configuration syntax in several lines by using slash (/) at the end of every line. Here is example
*.=debug;/
auth,authpriv.none;/
news.none;mail.none -/var/log/debug
/var/log/ messages files is configured to store only info and warning messages only excluding news,mail,auth and authpriv facilites like
*.=info;*=notice;=warn;/
auth.arhtpriv.none;/
mail.news.none -/var/log/messages

There are specific type of messages sent to the screen for all users logged in. File definition is normally replaced using an asterisk like
*.emerg 8

Some specific applications can log to have their own application log files and independent syslog.conf files. Here is example of these files and directories and using them you can make syslog analysis and handle errors.
Files:
/var/log/maillog : Mail information
/var/log/httpd/access_log : Apache web server page access logs

Directories:
/var/log
/var/log/samba : Samba messages
/var/log/mrtg : MRTG messages
/var/log/httpd : Apache webserver messages
Restart syslog.conf using this command.

[root@linux-server tmp]# service syslog restart

To restart syslog in Ubuntu:

root@u-linux-server:~# /etc/init.d/sysklogd restart

 

==================================================

 

日誌文件由系統日誌和內核日誌監控程序syslog
dklogd
 控制,/etc/syslog
.conf
 文件中配置這兩個監控程序默認活動。 
日誌文件按/etc/syslog .conf 配置文件中的描述進行組織。下圖是/etc/syslog .conf 文件的內容:
[root@localhost ~]# cat /etc/syslog .conf
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
# Log all the mail messages in one place.
mail.* -/var/log/maillog
# Log cron stuff
cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg *
# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler
# Save boot messages also to boot.log
local7.* /var/log/boot.log


syslog .conf 行的基本語法是:
[
消息類型]     [ 處理方案]
注意:中間的分隔符必須是Tab 字符!
消息類型是由" 消息來源"" 緊急程度" 構成,中間用點號連接。例如上圖中,news.crit 表示來自news 關鍵 狀況。在這裏,news 是消息來源,crit 代表關鍵狀況。通配符* 可以代表一切消息來源。
說明:
第一條語句*.info ,將info 級以上(notice,warning,err,crit,alertemerg )的所有消息發送到相應日誌文件。
日誌文件類別(按重要程度分類)日誌文件可以分成八大類,下面按重要性從大到下列出:
emerg
  emergency
 , 緊急
alert    ,          
警報
crit
  critical
 ,   關鍵
errerror
 ,          錯誤
warning
             警告
notice               
通知
info
                信息
debug
               調試
-------------------------------------------------------
簡單列一下消息來源:
auth
       認證系統,如loginsu ,即詢問用戶名和口令
cron
       系統執行定時任務時發出的信息
daemon
       某些系統的守護程序的 syslog ,如由in.ftpd 產生的log
kern
       內核的信息
lpr
       打印機的信息
mail
       處理郵件的守護進程發出的信息
mark
       定時發送消息的時標程序
news
       新聞組的守護進程的信息
user
       本地用戶的應用程序的信息
uucp
       uucp 子系統的信息
local0~local7   系統預留
*
         表示所有可能的信息來源
----------------------------------------------------------
處理方案
"
處理方案" 選項可以對日誌進行處理。可以把它存入硬盤,轉發到另一臺機器或顯示在管理員的終端上。
處理方案一覽:
文件名  寫入某個文件,要注意絕對路徑。
@
主機名 轉發給另外一臺主機的syslog d 程序。
@IP
地址 同上,只是用IP 地址標識而已。
/dev/console
發送到本地機器屏幕上。
*
發送到所有用戶的終端上。
|
程序 通過管道轉發給某個程序。
例如:
kern.emerg /dev/console(
一旦發生內核的緊急狀況,立刻把信息顯示在控制檯上)
說明:
如果想修改syslog d 的記錄文件,首先你必須殺掉syslog d 進程,在修改完畢後再啓動syslog d 。攻擊者進入系統後通常立刻修改系統日誌,因 此作爲網管你應該用一臺機器專門處理日誌信息,其他機器的日誌自動轉發到它上面,這樣日誌信息一旦產生就立刻被轉移,這樣就可以正確記錄攻擊者的行爲。
將日誌文件記錄到遠程主機 。
說到這遠程主機就是我們本文要配置的syslog 服務器。
----------------------------------------------------------------
2.syslog
服務器配置實踐步驟
例如: 10.0.0.1syslog 服務器     10.0.0.2 爲客戶機
步驟: 1. 服務端配置
vi /etc/sysconfig/syslog       
      sysLOG D_OPTIONS = “-r –m 0”   ## -r
意思是接受遠程的日誌
   
重起syslog 服務 /etc/rc.d/init.d/syslog    restart
    2.
客戶端配置
      vi /etc/syslog .conf
      
在消息去向處添加 @10.0.0.1
例如:*.info;mail.none;authpriv.none;cron.none @10.0.0.1
      
存盤退出重起服務
      /etc/rc.d/init.d/syslog restart
    (
知識點:直接查看日誌尾部:   tail   /var/log/messages 或者tail /var/log/boot 這樣就可以看到syslog 重起)
--------------------------------------------------------------------
注意:日誌服務使用的端口是:514/udp syslog 服務器應該打開這個端口
syslog
日誌服務器端不能根據源地址過濾,爲了防止外網向日志服務器寫垃圾信息要在網絡拓撲中解決,網關上做限制外網訪問514 端口。
如果服務器比較多的話,這樣形成的日誌比較大,要做好日誌的分析


================================================

Fedora Core6中IPtables日誌管理技巧

2008-08-23 PChome.net 類型: 轉載 來源: 賽迪網 責編: 江海明

Iptables的手冊中提到 LOG target這個target是專門用來記錄數據包有關信息的。這些信息可能是非法的,那就可以用來除錯。LOG會返回包的有關細節,如IP頭的大部分和 其他有趣的信息。這個功能是通過內核的日誌工具完成的,一般是syslogd。返回的信息可用dmesg閱讀,或者可以直接查看syslogd的日誌文 件,也可以用其他的什麼程序來看。LOG對調試規則有很大的幫助,你可以看到包去了哪裏、經過了什麼規則的處理,什麼樣的規則處理什麼樣的包,等等。下面 我們來實現如何通過內核的日誌工具管理IPtables日誌。

一、配置syslogd的配置文件/etc/syslog.conf

syslogd默認把日誌信息輸出到/var/log/messages文件。下面向大家介 紹如何建立一個新的IPtables日誌文件/var/log/iptables。修改syslogd的配置文件/etc/syslog.conf,告訴 syslogd IPtables使用哪個記錄等級。記錄等級的詳細信息可以查看文件syslog.conf,一般來說有以下幾種,它們的級別依次 是:debug,info,notice,warning,warn,err,error,crit,alert, emerg,panic。其中,error和err、warn和warning、panic和emerg分別是同義詞,也就是說作用完全一樣的。注意這三 種級別是不被贊成使用的(因爲信息量太大)。信息級別說明了被記錄信息所反映的問題的嚴重程度。

IPtables的所有LOG信息可以通過內核的功能被記錄。

首先在文件syslog.conf裏添加如下內容

# Iptables logging
kern.debug /var/log/iptables

然後再指定iptables的LOG規則使用級別debug(例如:iptables -I INPUT 1 -j LOG --log-prefix '[IPTABLES DROP LOGS]:' --log-level debug),就可以把所有的信息存入文件/var/log/iptables內。

最後重新啓動syslog服務或重啓計算機。

我用的是FC6,用service syslog restart命令可以很方便地啓動syslog服務。

二、使用IPtables滾動日誌

所有的日誌文件都會隨着時間的推移和訪問次數的增加而迅速增長,因此必須對日誌文件進行定期 清理以免造成磁盤空間的不必要的浪費。FC6下有一個專門的日誌滾動處理程序logrotate,logrotate能夠自動完成日誌的壓縮、備份、刪除 工作,系統默認把logrotate加入到系統每天執行的計劃任務中,這樣就省得管理員自己去處理了。

首先查看並確定logrotate的配置文件/etc/logrotate.conf內容如下:

# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# uncomment this if you want your log files compressed
#compress
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}
# system-specific logs may be also be configured here.

然後在syslog的滾動日誌配置文件/etc/logrotate.d/syslog裏面添加IPtables的日誌文件/var/log/iptables,詳細內容如下:

/var/log/iptables /var/log/messages 
/var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron {
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}

最後安排logrotate每天執行一次,確定文件/etc/cron.daily/logrotate內容如下:

#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

至此我們就爲IPtables創建了單獨的滾動日誌,可以更好地分析網絡攻擊信息。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章