Chinaunix首页 | 论坛 | 博客
  • 博客访问: 481854
  • 博文数量: 82
  • 博客积分: 3003
  • 博客等级: 中校
  • 技术积分: 1285
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-11 15:27
文章分类

全部博文(82)

文章存档

2011年(1)

2010年(5)

2009年(63)

2008年(13)

我的朋友

分类: LINUX

2009-08-12 00:23:06

借助Cron服务和logrotate日志回卷实现系统自动维护,同时使用logger命令向个人定制的日志文件添加日志信息。具体步骤如下:

1.

#vim /etc/syslog.conf

找到:*.info;mail.none;autopriv.none;cron.none一行,在最后添加";local1.none"

另起一行,输入"local1.info            /var/log/my_log.log"(其中my_log.log为自己定制的日志文件)

保存退出。

2.

#crontab -e 输入"* * * * * /usr/sbin/logrotate /etc/logrotate.conf"

3.

#cd /etc/logrotate.d/

#vim my_log.conf

/var/log/my_log.log{

create

rotate 2    #分卷数量为 2

daily

mail

size 5k     #一定要是小写的 k

##下面的是必不可少的

sharedscripts

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

}

4.

#service syslog restart

#service crond restart

5.Testing:

#ping 127.0.0.1 | logger -p local1.info ##(tty1)

#ll /var/log/my_log*                    ##(tty2)

即可看到自己定制的日志文件的变化,包括回卷的文件个数和文件大小。

*********************************************************************

书写简略,未提供详细解释,望大家提出宝贵意见。----Intern

By WangGang

阅读(1341) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

rha0302009-08-14 11:03:50

下面是我的英文文档,王老师说要改一下。我试了把log放在其他目录下是不可以的。 --------By danny Cheng Title How to rotate your own log Environment Redhat Entereprise Linux 5.3 Resolution You`better be root to do operation bellow: Step1: create your own log file-mylog [root@localhost danny]# touch /var/log/mylog Notice: I try to create mylog in other directory,but I can`t write log to mylog. Step2: Install new crontable: [root@localhost danny]# crontab -e ########################################################

rha0302009-08-14 11:03:38

下面是我的英文文档,王老师说要改一下。我试了把log放在其他目录下是不可以的。 --------By danny Cheng Title How to rotate your own log Environment Redhat Entereprise Linux 5.3 Resolution You`better be root to do operation bellow: Step1: create your own log file-mylog [root@localhost danny]# touch /var/log/mylog Notice: I try to create mylog in other directory,but I can`t write log to mylog. Step2: Install new crontable: [root@localhost danny]# crontab -e ########################################################

rha0302009-08-14 10:56:23

写一些原理会更好。你把日志文件随便放在其他地方例如home下,再做一下这个实验,还能否执行成功?