转载自: http://oldboy.blog.51cto.com/2561410/612351
1
|
老男孩运维班28期上述案例实战模拟:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
(1)安装httpd web服务
yum
install
httpd -y
/etc/init
.d
/httpd
start
lsof
-i :80
/etc/init
.d
/iptables
stop
cd
/etc/httpd/conf
编辑配置文件,让日志记录到
/app/logs
下面。
sed
-i
's@#CustomLog logs/access_log common@CustomLog /app/logs/access_logcommon@g'
httpd.conf
(2)创建一个小的文件系统,用于存放上述access_log日志。
dd
if
=
/dev/zero
of=
/dev/sdc
bs=8K count=10
ls
-l
/dev/sdc
mkfs -t ext4
/dev/sdc
tune2fs -c -1
/dev/sdc
mount
-o loop
/dev/sdc
/app/logs
echo
oldboy >
/var/www/html/index
.html
(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
[root@C64log]
# 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 73K 0 100%
/app/log
(5)错误的删除方案
[root@oldboylogs]
# rm -f /app/logs/access_log
[root@oldboylogs]
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3
8.8G 1.6G 6.9G 19% /
tmpfs 491M 0 491M 0%
/dev/shm
/dev/sda1
190M 36M 145M 20%
/boot
/dev/sdc
73K 68K 1.0K 99%
/app/logs
提示:此时空间并未被释放,你可知道原因?
查看被删除的但仍由进程占用的文件名。
[root@oldboylogs]
# 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)
(5)解决问题
1、请先停掉模拟访问测试脚本
forn
in
`
seq
100000`;
do
curl -s 127.0.0.1 >
/dev/null
;
done
2、重启Http服务
[root@C64log]
# /etc/init.d/httpd restart
Stoppinghttpd: [ OK ]
Startinghttpd: [ OK ]
(6)查看处理结果
[root@C64log]
# 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
|