(1)    安装httpd web服务

 yum install httpd -y


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

Starting httpd: httpd: apr_sockaddr_info_get() failed for root

httpd: Could not reliably determine the server'sfully qualified domain name, using 127.0.0.1 for ServerName

                                                          [  OK  ]



cd /etc/httpd/conf 编辑配置文件,让日志记录到/app/logs 下面

 

[root@root ~]# cd /etc/httpd/conf

检查80端口是否开启

[root@root conf]# lsof -i :80

COMMAND PID   USER   FD  TYPE DEVICE SIZE/OFF NODE NAME

httpd  2032   root    4u IPv6  13936      0t0 TCP *:http (LISTEN)

httpd   2034apache    4u  IPv6 13936      0t0  TCP *:http (LISTEN)

httpd   2035apache    4u  IPv6 13936      0t0  TCP *:http (LISTEN)

httpd   2036apache    4u  IPv6 13936      0t0  TCP *:http (LISTEN)

httpd   2037apache    4u  IPv6 13936      0t0  TCP *:http (LISTEN)

httpd   2038apache    4u  IPv6 13936      0t0  TCP *:http (LISTEN)

httpd   2039apache    4u  IPv6 13936      0t0  TCP *:http (LISTEN)

httpd   2040apache    4u  IPv6 13936      0t0  TCP *:http (LISTEN)

httpd   2041apache    4u  IPv6 13936      0t0  TCP*:http (LISTEN

 


替换httpd.conf里默认的日志路径

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

[root@root conf]# grep "access_logcommon" httpd.conf

CustomLog /app/logs/access_log common

#   CustomLog logs/dummy-host.example.com-access_log common

[root@root conf]#

 

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

 

[root@root conf]# dd if=/dev/zero of=/dev/sdc bs=8kcount=10

10+0 records in

10+0 records out

81920 bytes (82 kB) copied, 0.000383989 s, 213 MB/s

[root@root conf]# mkfs -t ext4 /dev/sdc

mke2fs 1.41.12 (17-May-2010)

/dev/sdc is not a block special device.

Proceed anyway? (y,n) y

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

16 inodes, 80 blocks

4 blocks (5.00%) reserved for the super user

First data block=1

1 block group

8192 blocks per group, 8192 fragments per group

16 inodes per group

 

Writing inode tables: done                           

 

Filesystem too small for a journal

Writing superblocks and filesystem accountinginformation: done

 

This filesystem will be automatically checked every24 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

创建日志文件

[root@root conf]# mkdir /app/logs -p

[root@root conf]# mount /dev/sdc /app/logs

mount: /dev/sdc is not a block device (maybe try`-o loop'?)

[root@root conf]# mount -o loop /dev/sdc /app/logs

 

(3)重启 httpd 服务,确保日志记录到了上述文件系统挂载的/app/log 下面
/etc/init.d/httpd restart

 

(4)写个循环脚本访问 httpd,使得 httpd 日志充满/app/logs 整个空间
for n in `seq 100000`;do curl -s 127.0.0.1 >/dev/null;done

 

 

(5)查看磁盘空间

[root@root conf]# df -h

Filesystem     Size  Used Avail Use% Mounted on

/dev/sda3      8.8G  1.5G  7.0G 18% /

tmpfs          238M     0  238M  0% /dev/shm

/dev/sda1      190M   36M  145M 20% /boot

/dev/sdc        73K   14K   55K 21% /app/logs

错误的删除方案
[root@root logs]# rm -f /app/logs/access_log
[root@root conf]# df -h

Filesystem     Size  Used Avail Use% Mounted on

/dev/sda3      8.8G  1.5G  7.0G  18%/

tmpfs          238M     0  238M  0% /dev/shm

/dev/sda1      190M   36M  145M 20% /boot

/dev/sdc        73K   67K   2K  99%/app/logs 

 

 

[root@root logs]# lsof|grep del   还有进程在调用
httpd 6148 root 7w REG 7,0 55260 12 /app/logs/access_log (deleted)
httpd 38178 apache 7w REG 7,0 55260 12 /app/logs/access_log (deleted)
httpd 38483 apache 7w REG 7,0 55260 12 /app/logs/access_log (deleted)
httpd 38484 apache 7w REG 7,0 55260 12 /app/logs/access_log (deleted)
httpd 38752 apache 7w REG 7,0 55260 12 /app/logs/access_log (deleted)

 

(6)解决问题
1、 请先停掉模拟访问测试脚本
for n in `seq 100000`;do curl -s 127.0.0.1>/dev/null;done

 

2、重启 Http 服务
[root@root log]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

 

(6)查看处理结果
[root@root log]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 7.2G 2.0G 4.9G 30% /
tmpfs 244M 0 244M 0% /dev/shm
/dev/sda1 194M 54M 131M 30% /boot
/dev/sdc 73K 14K 55K 21% /app/logs


(7)较好的处理方案
清空日志而不删除日志

>/app/logs/access_log