天天看點

Monitor The Network Machine Syslog

-------------------------------Network Machine-------------------------------

Switch-A:

Switch-A#sh running-config

interface loopback 0

ip address 1.1.1.1 255.255.255.255

no sh

logging on

logging trap

logging host 172.17.10.4

logging facility local0

logging source-interface loopback 0

Switch-B:

Switch-B#sh running-config

ip address 1.1.1.2 255.255.255.255

Router-A:

Router-A#sh running-config

ip address 1.1.1.11 255.255.255.255

logging facility local1

Router-B:

Router-B#sh running-config

ip address 1.1.1.12 255.255.255.255

-------------------------------Syslog Server-------------------------------

Modify the configuration files:

# vi /etc/sysconfig/syslog

#Add by Kingcraft
SYSLOGD_OPTIONS="-r -m -0"      

# vi /etc/syslog.conf

#Save Switch syslog messages
local0.*    /var/log/Network-Machine/Switch.log

#Save Route syslog messages
local1.*    /var/log/Network-Machine/Route.log      

Create log file storage directory:

# mkdir /var/log/Network-Netmachine

Restart the syslog server:

# service syslog restart

Find the directory where the configuration file:

# cat /etc/logrotate.conf | grep -B 1 include

# RPM packages drop log rotation information into this directory
include     /etc/logrotate.d      

Custom configuration file:

# vi /etc/logrotate.d/Network-Machine

/var/log/Network-Machine/*.log {
    compress
    notifempty
    rotate      6
    olddir      /var/log/Network-Machine/old/
    sharedscripts
    weekly
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
        /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
    }      

Modify the scheduled task object files:

# vi /etc/cron.daily/logrotate

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

---------------------------------------------------------------------

For more information refer to:man logrotate

繼續閱讀