syslog配置

客户端
1,配置/etc/syslog.conf文件,文件末尾添加如下信息:
local4.notice;local4.info;local4.err;local4.debug       /var/log/local4     将设备local4中基本消息级别为notice,info等的信息写入本机的/var/log/local4文件
local4.notice(将记录notice级别以上的日志)       @192.168.1.103       将设备local4中基本消息级别为notice,info等的信息重定向到主机192.168.1.103上
在solaris 10中,不知道为什么不知道local4.*的写法,如上写法才能正常运行。

2,重启syslog服务:
重新启动 syslogd 守护进程。

  在 Solaris 8 和 Solaris 9 等老版本上,通过键入以下命令重新启动 syslogd: 

$ /etc/init.d/syslog start


  在 Solaris 10 上,通过键入以下命令重新启动 syslogd: 

$ svcadm restart system/system-log

3,若在/etc/syslog.conf中配置了【*.err;kern.debug;daemon.notice;mail.crit        /var/adm/messages】可以使用命令:
root@GZ01 # tail /var/adm/messages
Apr 15 14:28:20 GZ-YY3-TJ-01 syslogd: line 32: unknown priority name ""
Apr 15 14:28:20 GZ-YY3-TJ-01 syslogd: line 33: unknown facility name "notice" (级别无法对应)
Apr 15 14:29:13 GZ-YY3-TJ-01 syslogd: going down on signal 15
Apr 15 14:29:13 GZ-YY3-TJ-01 syslogd: line 32: unknown priority name ""
Apr 15 14:29:13 GZ-YY3-TJ-01 syslogd: line 33: unknown priority name ""
Apr 15 14:31:41 GZ-YY3-TJ-01 syslogd: going down on signal 15
Apr 15 14:31:41 GZ-YY3-TJ-01 syslogd: line 32: unknown priority name ""
Apr 15 14:31:41 GZ-YY3-TJ-01 syslogd: line 33: unknown priority name "" (配置有误)
Apr 15 14:36:41 GZ-YY3-TJ-01 syslogd: going down on signal 15 (正常)
Apr 15 14:36:41 GZ-YY3-TJ-01 syslogd: /var/log/local4: No such file or directory (需要创建/var/log/local4文件)


4,使用测试命令:
root@VIP-03 # logger -p local4.warning "test local4 info  hello syslog"
root@VIP-03 # more /var/log/local4messages
Apr 15 14:53:25 VIP-03 root: [ID 702911 local4.warning] test local4 info  hello syslog
Apr 15 14:54:03 VIP-03 root: [ID 702911 local4.error] test local4 info  hello syslog
Apr 15 14:59:03 [192.168.1.128.82] root: [ID 702911 local4.error] test local4 info  hello syslog
Apr 15 14:57:16 VIPNetcare-03 root: [ID 702911 local4.debug] test local4 info  hello syslog
Apr 15 14:57:28 VIPNetcare-03 root: [ID 702911 local4.info] test local4 info  hello syslog
Apr 15 14:58:58 VIPNetcare-03 root: [ID 702911 local4.warning] test local4 info  hello syslog (正常输出)
证明本机客户端配置正常。接着配置远端收集端。


服务器端
1,修改配置文件/etc/syslog.conf,添加如下信息:
local4.notice(将记录notice级别以上的日志)         /var/log/local4messages  
(将设备local4中基本消息级别为notice,info等的信息写入本机的/var/log/local4messages 文件,次数的【设备.级别】要与客户端配置一致,否则可能收集不全日志)

2,重启syslog服务:
重新启动 syslogd 守护进程。

  在 Solaris 8 和 Solaris 9 等老版本上,通过键入以下命令重新启动 syslogd: 

$ /etc/init.d/syslog start


  在 Solaris 10 上,通过键入以下命令重新启动 syslogd: 

$ svcadm restart system/system-log

3,若在/etc/syslog.conf中配置了【*.err;kern.debug;daemon.notice;mail.crit        /var/adm/messages】可以使用命令:
root@VIP-03 # more /var/adm/messages
Apr 13 03:10:02 VIP-03 syslogd: line 33: unknown priority name "*"
Apr 13 10:33:45 VIP-03 sshd[22268]: [ID 800047 auth.crit] fatal: Read from socket failed: Connection reset by peer
Apr 14 21:09:53 VIP-03 su: [ID 810491 auth.crit] 'su root' failed for sdnmuser on /dev/pts/1
Apr 14 21:10:33 VIP-03 last message repeated 2 times
Apr 15 10:52:08 VIP-03 syslogd: line 33: unknown priority name "*"
Apr 15 10:52:08 VIP-03 syslogd: line 34: unknown priority name "*"
Apr 15 10:52:08 VIP-03 syslogd: syslogd pid 9790 already running. Cannot start another syslogd pid 22122
Apr 15 11:00:35 VIP-03 syslogd: line 33: unknown priority name "*"
Apr 15 11:00:35 VIP-03 syslogd: line 34: unknown priority name "*"
Apr 15 11:00:35 VIP-03 syslogd: syslogd pid 9790 already running. Cannot start another syslogd pid 22297
Apr 15 11:02:22 VIP-03 syslogd: line 33: unknown priority name "*"
Apr 15 11:02:22 VIP-03 syslogd: line 34: unknown priority name "*"    (配置有误)
Apr 15 11:02:22 VIP-03 syslogd: syslogd pid 9790 already running. Cannot start another syslogd pid 22377
Apr 15 14:46:55 VIP-03 syslogd: going down on signal 15               (正常启动)
Apr 15 14:46:56 VIP-03 syslogd: /var/log/local4messages: No such file or directory  (需要建立/var/log/local4messages文件后在执行2操作)

4,使用测试命令:
root@VIPNetcare-03 # logger -p local4.warning "test local4 info  hello syslog"
root@VIPNetcare-03 # more /var/log/local4messages
Apr 15 14:53:25 VIP-03 root: [ID 702911 local4.warning] test local4 info  hello syslog (正常)
证明本机客户端配置正常。接着测试远端收集。

5,可以是用snoop抓包辅助测试客户端是否正常配置:
root@VIP-03 # snoop 132.96.32.101 (客户端IP)
Using device /dev/e1000g0 (promiscuous mode)
132.96.32.101 -> VIPNetcare-03 ICMP Echo request (ID: 7326 Sequence number: 0)
VIPNetcare-03 -> 132.96.32.101 ICMP Echo reply (ID: 7326 Sequence number: 0)
192.168.1.101 -> VIPNetcare-03 SYSLOG C port=32850 local4.info: <166>Apr 15 14:53:27(客户端发送日志)
192.168.1.101 -> VIPNetcare-03 SYSLOG C port=32850 local4.info: <166>Apr 15 14:58:23(客户端发送日志)
192.168.1.101 -> VIPNetcare-03 SYSLOG C port=32850 local4.debug: <167>Apr 15 14:58:39(客户端发送日志)
192.168.1.101 -> VIPNetcare-03 SYSLOG C port=32850 local4.error: <163>Apr 15 14:59:03(客户端发送日志)
192.168.1.101 -> VIPNetcare-03 SYSLOG C port=32850 local4.error: <163>Apr 15 15:02:37(客户端发送日志)
192.168.1.101 -> VIPNetcare-03 SYSLOG C port=32850 local4.warn: <164>Apr 15 15:02:57(客户端发送日志)

6,核对服务端收集情况:
root@VIP-03 # more /var/log/local4messages
Apr 15 14:53:25 VIPNetcare-03 root: [ID 702911 local4.warning] test local4 info  hello syslog
Apr 15 14:54:03 VIPNetcare-03 root: [ID 702911 local4.error] test local4 info  hello syslog
Apr 15 14:59:03 [192.168.1.101.128.82] root: [ID 702911 local4.error] test local4 info  hello syslog (客户端发送)
Apr 15 14:57:16 VIPNetcare-03 root: [ID 702911 local4.debug] test local4 info  hello syslog
Apr 15 14:57:28 VIPNetcare-03 root: [ID 702911 local4.info] test local4 info  hello syslog
Apr 15 14:58:58 VIPNetcare-03 root: [ID 702911 local4.warning] test local4 info  hello syslog
Apr 15 15:02:37 [192.168.1.101.128.82] root: [ID 702911 local4.error] test local4 info  hello syslog (客户端发送)
Apr 15 15:02:57 [192.168.1.101.128.82] root: [ID 702911 local4.warning] test local4 info  hello syslog (客户端发送)

配置完成

 

 

  严重等级
取值
描述
emergencies
1
极其紧急的错误
alerts
2
需立即纠正的错误
critical
3
关键错误
errors
4
需关注但不关键的错误
warnings
5
警告,可能存在某种差错
notifications
6
需注意的信息
informational
7
一般提示信息
debugging
8
调试信息

 

你可能感兴趣的:(syslog配置)