您的位置:首页 > 其它

SYSLOG&滚动日志(转)

2010-07-31 21:11 246 查看
一:基本概念

1:软件包syslogd

2: /etc/syslog.conf配置文件

格式:facility.level action

(设备. 优先级 动作)

2.1 facility如下:

auth-用户授权

authpriv-授权和安全

cron-计划任务:at ,cron

daemon-系统守护进程

kern-与内核有关系的信息

lpr-与打印服务有关的信息。

mail-与电子邮件有关的信息

news-来自新闻服务器的信息

syslog-由 syslog生成的信息

user-用户的程序生成的信息,默认。

uucp-由 uucp生成的信息

local0-local7-来定义本地策略

2.2 level

level定义消息的紧急程度。按严重程度由高到低顺序排列为:emerg =panic(该系统不可用)

alert-需要立即采取的动作

crit-临界状态

err-错误状态。等同error

warning-预警信息,等同warn

notice-正常但是要注意

info-正常消息

debug-调试

none -一般的信息

2.3动作

2.3.1指定日志文件的绝对路径

2.3.2 *(所有用户)

2.3.3指定用户

2.3.4 @hostanme或IP

2.4配置文件详细内容如下:

# 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

3:日志服务的进程和服务

3.1服务名 syslog

3.2 进程 syslogd

3.3 重读配置文件service syslog 或 /usr/bin/killall –HUP syslogd

4:相关日志文件路径

/var/log/*.*

二:日志服务器端的配置

1:修改配置文件/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=" -x -m 0" 修改为 SYSLOGD_OPTIONS="-r -x -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".

2:修改文件syslog之后

2.1 重启syslog服务

Service syslog restart

2.2查看syslogd进程

ps –ef |grep syslogd |grep –v “grep syslogd”

root 30307 1 0 13:59 ? 00:00:00 syslogd -r -x -m ###有-r就表示成功。

2.3 查看日志服务器监听的udp端口:514

netstat -untl |grep 514

udp 0 0 0.0.0.0:514 0.0.0.0:* ###514已经起来

三:客户端的配置

1:修改/etc/syslog.conf

*.* @日志服务器的主机名或IP地址

2:重启客户端syslog

Service syslog restat

3:客户端产生的所有的日志文件将在日志服务器的/var/log/*.*生成。

另:关于linux日志轮转(logrotate)的相关知识

一:防止日志文件本修改,加入某些属性。

1:chattr命令可以使某个文件属性改变

chattr +a /var/log/messages 文件messages的数据只允许增加,不允许减少。

chattr -a /var/log/messages 去掉数据只允许增加而不允许减少的属性。

2:lsattr命令查看chattr命令的效果

lsattr /var/log/messages

------------a-----------------messages

二:(logrotate)轮转:将旧的日志文件自动轮换成新的日志文件。

该配置文件绝对路径:

/etc/logrotate.d

/etc/logrotate.conf

1:解释配置文件logrotate.conf

# see "man logrotate" for details

# rotate log files weekly

Weekly #####一周轮转一次

# keep 4 weeks worth of backlogs

rotate 4 ####只备份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 { ####/var/log/wtmp这个日志文件按照下面的设定轮转

Monthly ####每月轮转一次

minsize 1M ####文件大小最小1M

create 0664 root utmp #### wtmp这个日志文件,权限644,所有者root,所属组utmp

rotate 1 ####只备份一个月的数据就轮换

}

2:/etc/logrotate.d 里面的文件是自定义轮转方式。默认是/etc/logrotate.conf,是一个全局配置文件,而/etc/logrotated下面的文件是局部的。只对自己生效。

/var/log/messages为说明:自定义messages的轮转方式。

/var/log/messages{

sharedscripts

rotate 9

weekly

prerotate

/usr/bin/chattr -a /var/log/messages

endscript

postrotate

/usr/bin/killall -HUP syslogd

/usr/bin/chattr +a /var/log/messages

endscript

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: