Apache: No space left on device: Couldn’t create accept lock

来源:互联网 发布:动画规律软件 编辑:程序博客网 时间:2024/06/04 18:49

昨天启动内部服务器的apache时,没启动成功,看了下/var/log/httpd/error_log,有如下错误:
“[Mon Aug 06 09:32:20 2012] [emerg] (28)No space left on device: Couldn’t create accept lock (/etc/httpd/logs/accept.lock.6399) (5)”

开始根据提示去找磁盘空间不足,发现磁盘空间充足,所以这里的“no space”不是指磁盘空间。

后来发现原因是一些IPC的资源占用问题,先用”ipcs”命令查一下当前用于已经使用了的信号量集合(semaphore sets),再用“sysctl”命令查询一下每个用户最多可使用的信号量,发现基本上占用完了,不能给新的apache进程使用了(尽管没有完全占满,但是httpd.conf文件中写了已开始启动8个server进程的,确实不够分配)。

View Code BASH
12345678910111213
[root@vmm-web ~]# ipcs -s | grep apache0x00000000 10649601   apache    600        10x00000000 10616834   apache    600        10x00000000 10682371   apache    600        10x00000000 10715140   apache    600        10x00000000 10747909   apache    600        10x00000000 10780678   apache    600        10x00000000 10813447   apache    600        10x00000000 10846216   apache    600        1#有很多,大约有120行;当然如果不是apache账号启动的apache,需要根据实际情况灵活变通 [root@vmm-web ~]# sysctl kernel.semkernel.sem = 250        32000   32      128

我已经确定apache这个账号下的semaphores是不用了(除了给我的HTTPD服务器),所以只需要用“ipcrm -s”命令kill掉这些semaphore array即可,做了一个小脚本如下:

View Code BASH
12345
sem_list=$(ipcs -s | grep apache | awk '{print $2}')for i in $sem_listdo        ipcrm -s $idone

另外,也可以设置更改每个用户的semaphore array的最大数量,先查询后更改如下。

View Code BASH
12345678910111213
[root@vmm-web ~]# ipcs -s -l ------ Semaphore Limits --------max number of arrays = 128max semaphores per array = 250max semaphores system wide = 32000max ops per semop call = 32semaphore max value = 32767[root@vmm-web ~]# sysctl kernel.semkernel.sem = 250        32000   32      128[root@vmm-web ~]# sysctl kernel.sem="250 256000 32 1024"[root@vmm-web ~]# sysctl kernel.semkernel.sem = 250        256000  32      1024

当然如果想让此更改永久生效,可以编辑“/etc/sysctl.conf”配置文件加上设置“sysctl kernel.sem = 250 256000 32 1024”,然后执行”sysctl -p”命令加载配置文件即可。

一些简单的知识和命令记录一下。

View Code BASH
123456789101112131415161718192021222324
[root@vmm-web ~]# ipcs -l ------ Shared Memory Limits --------max number of segments = 4096max seg size (kbytes) = 4194303max total shared memory (kbytes) = 1073741824min seg size (bytes) = 1 ------ Semaphore Limits --------max number of arrays = 1024max semaphores per array = 250max semaphores system wide = 256000max ops per semop call = 32semaphore max value = 32767 ------ Messages: Limits --------max queues system wide = 16max size of message (bytes) = 65536default max size of queue (bytes) = 65536 [root@vmm-web ~]# cat /proc/sys/kernel/msgmni16[root@vmm-web ~]# cat /proc/sys/kernel/sem250     256000  32      1024

而其中kernel.sem参数的四个值分别表示:Parameters meaning:
SEMMSL – semaphores per ID
SEMMNS – (SEMMNI*SEMMSL) max semaphores in system
SEMOPM – max operations per semop call
SEMMNI – max semaphore identifiers
关于msgmni解释如下:
The parameter “msgmni” is the number of message queue ids available to the system. Each message queue requires one id. msgget() gives the error ENOSPC if all the ids have been used up.
而ipcs和ipcrm的用途如下:
ipcs – report XSI interprocess communication facilities status
ipcrm – remove an XSI message queue, semaphore set, or shared memory segment identifier

后记:
后来才发现,2010年在阿里时也处理过这个问题的,当时用了别人的一个脚本来处理的,更多信息可参考如下的博客链接。


Linux IPC资源清理 : http://www.51testing.com/?uid-225738-action-viewspace-itemid-222385


http://smilejay.com/2012/08/apache_create_accept_lock/ 



0 0
原创粉丝点击