一、syslog日誌服務:
1、守護進程:syslog
2、端口:514
3、配置文件:/etc/syslog.conf
4、常見日誌文件:
/var/log/dmesg 內核引導信息日誌
/var/log/message 標準系統錯誤信息日誌
/var/log/maillog 郵件系統信息日誌
/var/log/cron 計劃任務日誌
/var/log/secure 安全信息日誌
二、 配置文件:
syslog配置文件如下
-----------------------------------------------------------------
配置文件中每行表示一個項目,格式爲:facility.level action
syslog配置文件如下
-----------------------------------------------------------------
[root@server ~]# vim /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.*
----------------------------------------------------------------- |
由兩個部分組成:
第一部分:選擇條件(可以有一個或者多個條件),分爲兩個字段。
第二部分:操作動作;
1、選擇條件
選擇條件本身分爲兩個字段,之間用一個小數點(.)分隔。前一字段是一項服務,後一字段是一個優先級。選擇條件是對消息類型的一種分類,這種分類便於 人們把不同類型的消息發送到不同的地方。在同一個syslog配置行上允許出現一個以上的選擇條件,但必須用分號(;)隔開。
常見facility:
kern 內核信息;
user 用戶進程信息;
mail 電子郵件相關信息;
daemon 後臺進程相關信息;
authpriv 包括特權信息如用戶名在內的認證活動;
cron 計劃任務信息;
syslog 系統日誌信息
lpr 打印服務相關信息。
news 新聞組服務器信息
uucp uucp 生成的信息
local0----local7 本地用戶信息
2、重要級:
重要級是選擇條件的第二個字段,它代表消息的緊急程度。
按嚴重程度由低到高排序:
debug 不包含函數條件或問題的其他信息
info 提供信息的消息
none 沒有重要級,通常用於排錯
notice 具有重要性的普通條件
warning 預警信息
err 阻止工具或某些子系統部分功能實現的錯誤條件
crit 阻止某些工具或子系統功能實現的錯誤條件
alert 需要立即被修改的條件
emerg 該系統不可用
不同的服務類型有不同的優先級,數值較大的優先級涵蓋數值較小的優先級。如果某個選擇條件只給出了一個優先級而沒有使用任何優先級限定符,對應於這個優先級的消息以及所有更緊急的消息類型都將包括在內。比如說,如果某個選擇條件裏的優先級是“warning”,它實際上將把“warning”、 “err”、“crit”、“alert”和“emerg”都包括在內。
3、操作動作
日誌信息可以分別記錄到多個文件裏,還可以發送到命名管道、其他程序甚至另一臺機器。
syslog 主要支持以下活動:
file 指定文件的絕對路徑
terminal 或 prin 完全的串行或並行設備標誌符
@host(@IP地址) 遠程的日誌服務器
三、 搭建Linux日誌服務器:
1、編輯/etc/sysconfig/syslog文件,讓服務器能夠接受客戶端傳來的數據:
在“SYSLOGD_OPTIONS”行上加“-r”選項以允許接受外來日誌消息。
-----------------------------------------------------------------
2、重新啓動syslog守護進程。
-----------------------------------------------------------------
-----------------------------------------------------------------
[root@client ~]# vim /etc/sysconfig/syslog
# Options to syslogd
# -m 0 disables 'MARK' messages.
# -r enables logging from remote machines
# -x disables DNS lookups on messages recieved with -r
# See syslogd(8) for more details
SYSLOGD_OPTIONS="-r -m 0"
# Options to klogd
# -2 prints all kernel oops messages twice; once for klogd to decode, and
# once for processing with 'ksymoops'
# -x disables all klogd processing of oops messages entirely
# See klogd(8) for more details
KLOGD_OPTIONS="-x"
#
SYSLOG_UMASK=077
# set this to a umask value to use for all log files as in umask(1).
# By default, all permissions are removed for "group" and "other".
----------------------------------------------------------------- |
-----------------------------------------------------------------
[root@client ~]# service syslog restart
關閉內核日誌記錄器: [確定]
關閉系統日誌記錄器: [確定]
啓動系統日誌記錄器: [確定]
啓動內核日誌記錄器: [確定]
[root@client ~]#
----------------------------------------------------------------- |
四、配置各客戶端:
1、配置/etc/syslog.conf
修改客戶機/etc/syslog.conf文件,在有關配置行的操作動作部分用一個“@”字符指向日誌服務器
-----------------------------------------------------------------
[root@client ~]# vim /etc/syslog.conf
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
*.* @10.64.165.210
# The authpriv file has restricted access.
authpriv.* /var/log/secure
……下面省略
----------------------------------------------------------------- |
2、重啓客戶端syslog使設置生效。
檢測成果:
下圖是我們在客戶端重啓iptables服務後在服務端看到的日誌情況:
-----------------------------------------------------------------
[root@client ~]# cat /var/log/messages |tail
Nov 30 16:44:29 10.64.165.200 kernel: klogd 1.4.1, log source = /proc/kmsg started.
Nov 30 16:44:33 10.64.165.200 kernel: Removing netfilter NETLINK layer.
Nov 30 16:44:33 10.64.165.200 kernel: ip_tables: (C) 2000-2006 Netfilter Core Team
Nov 30 16:44:33 10.64.165.200 kernel: Netfilter messages via NETLINK v0.30.
Nov 30 16:44:33 10.64.165.200 kernel: ip_conntrack version 2.4 (4096 buckets, 32768 max) - 228 bytes per conntrack
----------------------------------------------------------------- |