经过上次的cacti因为磁盘空间占用100%而出了故障之后,我通过昨天和今天的观察发现日志的增长速度很是惊人啊。

由下图可知服务器的磁盘一共378G。作为一个跑着Cacti业务的机器378G足够了。但是上周5出故障的时候已经把它调到15%了。这才3天已经涨到28%。今天决定针对该问题做个优化。

spacer.gif

优化步骤主要分如下几步:

1,找出服务器内大于1G的文件。

spacer.gif

通过上图的搜索结果我看到/var/log/httpd/error_log过大。次文件是apache的错误日志文件。

2,查看/var/log/httpd/error_log内容

#tail–f /var/log/httpd/error_log

spacer.gif

满屏的PHP Warning啊。通常Warning级别的信息是不必在意的,但是这些信息又过大的占用磁盘空间。所以今天决定把错误级别调到error级。

经过查阅一些网络文档发现:E_WARNING 通常都会显示出来,但不会中断程式的执行。这对除错很有效。例如:用有问题的常规表示法呼叫 ereg()还是不要调错误级别了。

3,既然不能调错误级别,应该观察错误日志解除这个warning

下面是错误日志的内容:

[Tue Jul 23 10:38:28 2013][error] [client 221.204.229.60] PHP Warning: date(): It is not safe to rely on the system's timezone settings. Youare *required* to use the date.timezone setting or thedate_default_timezone_set() function. In case you used any of those methods andyou are still getting this warning, you most likely misspelled the timezoneidentifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in/usr/local/www/cacti/gx.php on line 132

[Tue Jul 23 10:42:05 2013][error] [client 221.204.229.60] PHP Warning: date(): It is not safe to rely on the system's timezone settings. Youare *required* to use the date.timezone setting or thedate_default_timezone_set() function

解决办法如下:

#Vi/etc/php.ini

date.timezone= PRC

#servicehttpd restart

这是因为PHP所取的时间是格林威治标准时间,所以和你当地的时间会有出入格林威治标准时间和北京时间大概差8个小时左右。

附解决该问题办法一篇:

在用PHP5.3以上的PHP版本时,只要是涉及时间的会报一个

"PHPWarning: date() [function.date]: It is not safe to rely on the system'stimezone settings. You are *required* to use the date.timezone setting or thedate_default_timezone_set() function. In case you used any of those methods andyou are still getting this warning, you most likely misspelled the timezoneidentifier. We selected 'UTC' for '8.0/no DST' instead in"

这样的错。如何解决呢

实际上,从 PHP 5.1.0 ,当对使用date()等函数时,如果timezone设置不正确,在每一次调用时间函数时,都会产生E_NOTICE 或者 E_WARNING 信息。而又在php5.1.0中,date.timezone这个选项,默认情况下是关闭的,无论用什么php命令都是格林威治标准时间,但是PHP5.3中好像如果没有设置也会强行抛出了这个错误的,解决此问题,只要本地化一下,就行了。

以下是三种方法(任选一种都行):

一、在页头使用date_default_timezone_set()设置 date_default_timezone_set('PRC'); //东八时区 echo date('Y-m-d H:i:s');

二、在页头使用ini_set('date.timezone','Asia/Shanghai');

三、修改php.ini。打开php5.ini查找date.timezone 去掉前面的分号修改成为:date.timezone =PRC

重启http服务(如apache2或iis等)即可。

XXX可以任意正确的值。对于我们国内来说:可以为以下值:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次为重庆,上海,乌鲁木齐)港台地区可用:Asia/Macao,Asia/Hong_Kong ,Asia/Taipei (依次为澳门,香港,台北),还有新加坡:Asia/Singapore,当然PRC也行。

好!该问题已经解决。此时/var/log/httpd/error_log文件的增长速度迅速下降。

4,但是继续监控该文件仍然发现2个错误如下:

[Tue Jul 23 11:00:01 2013] [error] [client 114.240.154.219] PHPNotice:  Use of undefined constant purl -assumed 'purl' in /usr/local/www/warning.php on line 21

这句话的意思是/usr/local/www/warning.php的第21行有一个未定义的常量purl。我打开/usr/local/www/warning.php看到这么一句话。

spacer.gif

解决办法:

#vi /etc/php.ini

error_reporting = E_ALL & ~E_NOTICE

下面是第二个错误提示和解决办法:

[Tue Jul 23 11:00:01 2013] [error] [client114.240.154.219] File does not exist: /usr/local/www/favicon.ico

解决办法:

#cd /usr/local/www

#wget

5,常用

#tail -f /var/log/httpd/error_log