web访问磁盘html,模拟web服务器产生的日志占满磁盘故障解决方案

生产环境可能你会遇到web服务器产生的log日志文件占满磁盘的现象,下面给出具体的解决方案

安装httpd web服务

[root@bier ~]# yum install httpd -y

启动

[root@bier ~]# /etc/init.d/httpd start

测试

[root@bier ~]# lsof -i :80

COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

httpd   1542   root    4u  IPv6  12105      0t0  TCP *:http (LISTEN)

httpd   1544 apache    4u  IPv6  12105      0t0  TCP *:http (LISTEN)

httpd   1545 apache    4u  IPv6  12105      0t0  TCP *:http (LISTEN)

httpd   1546 apache    4u  IPv6  12105      0t0  TCP *:http (LISTEN)

安装目录介绍

Apache默认将网站的根目录指向/var/www/html 目录

默认的主配置文件是/etc/httpd/conf/httpd.conf

配置存储在的/etc/httpd/conf.d/目录

[root@bier html]#cd /var/www/html

设置访问页面

[root@bier html]# echo "hello web" >/var/www/html/index.html

访问测试

[root@bier html]# curl -I http://127.0.0.1

HTTP/1.1 200 OK

Date: Wed, 31 Aug 2016 19:31:54 GMT

Server: Apache/2.2.15 (CentOS)

Last-Modified: Wed, 31 Aug 2016 19:30:35 GMT

创建日志文件

[root@bier html]# mkdir -p /app/logs

定义日志到指定目录

[root@bier html]# sed -i "s@#CustomLog logs/access_log common@CustomLog /app/logs/access_log common@g" /etc/httpd/conf/httpd.conf

[root@bier html]# grep "access_log common" /etc/httpd/conf/httpd.conf

CustomLog /app/logs/access_log common

重启使日志生效

[root@bier html]# /etc/init.d/httpd restart

创建一个小的文件系统,用于存放上述 access_log 日志

[root@bier html]# dd if=/dev/zero of=/dev/sdb bs=10k count=100

100+0 records in

100+0 records out

1024000 bytes (1.0 MB) copied, 0.00173305 s, 591 MB/s

格式和挂载

[root@bier html]# mkfs -t ext4 /dev/sdb

[root@bier html]# mount -o loop /dev/sdb /app/logs

[root@bier html]#/etc/init.d/httpd restart

[root@bier html]# curl -s 127.0.0.1

hello world!!!

[root@bier html]# cat /app/logs/access_log

127.0.0.1 - - [01/Sep/2016:04:02:23 +0800] "GET / HTTP/1.1" 200 15

写个循环脚本访问 httpd,使得 httpd 日志充满/app/logs 整个空间

for n in `seq 1000000`;do curl -s 127.0.0.1 >/dev/null;done

[root@bier ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        18G  1.9G   15G  12% /

tmpfs           429M     0  429M   0% /dev/shm

/dev/sda1       194M   29M  155M  16% /boot

/dev/sda2       2.0G   67M  1.9G   4% /swap

/dev/sdb        979K  909K   20K  98% /app/logs

错误的删除方案

[root@bier ~]# rm -f /app/logs/access_log

[root@bier ~]# lsof|grep del   #===>还有进程在调用

httpd      3306      root    7w      REG                7,0   912339         12 /app/logs/access_log (deleted)

httpd     35409    apache    7w      REG                7,0   912339         12 /app/logs/access_log (deleted)

httpd     35828    apache    7w      REG                7,0   912339         12 /app/logs/access_log (deleted)

httpd     35829    apache    7w      REG                7,0   912339         12 /app/logs/access_log (deleted)

解决方法

1、 请先停掉模拟访问测试脚本

for n in `seq 1000000`;do curl -s 127.0.0.1>/dev/null;done

2、重启 Http 服务

[root@bier html]# /etc/init.d/httpd restart

查看处理结果

[root@bier html]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        18G  1.9G   15G  12% /

tmpfs           429M     0  429M   0% /dev/shm

/dev/sda1       194M   29M  155M  16% /boot

/dev/sda2       2.0G   67M  1.9G   4% /swap

/dev/sdb        979K   17K  912K   2% /app/logs

理想的处理方案

清空日志而不删除日志

>/app/logs/access_log

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值