解決方法:
1. 在/etc/httpd/conf/httpd.conf的最后添加如下內容
CoreDumpDirectory /var/apache-dump
2. 創建該目錄,并設置正確的權限和屬主:
# ps aux | grep http | tail -n 2
# mkdir /var/apache-dump
# chown apache.apache /var/apache-dump
注:修改屬主為ps axu|grep httpd顯示的apache進程的運行身份和組
# chmod 0770 /var/apache-dump
# ls -ld /var/apache-dump
drwxrwx--- 2 apache apache 4096 Aug 16 10:59 /var/apache-dump
3. 修改/etc/security/limits.conf,添加:
* - core unlimited
4. 編輯/etc/profile,修改:
ulimit -S -c 0 > /dev/null 2>1
為
ulimit -S -c unlimited > /dev/null 2>1
5. 編輯/etc/init.d/functions,在下面一行添加一個"#",將其注釋掉:
ulimit -S -c 0 >/dev/null 2>1
為
#ulimit -S -c 0 >/dev/null 2>1
6. 編輯/etc/init.d/httpd,在start()部分的第一行添加ulimit -c如下:
start() {
ulimit -c unlimited
echo -n $"Starting $prog: "
7. 實現重新起動后將PID寫入到core文件,修改/etc/sysctl.conf,添加:
kernel.core_uses_pid = 1
# Following needed for Enterprise Linux 3 servers
kernel.core_setuid_ok = 1
同時,可以手工運行下面命令使得立刻生效:
# echo 1 > /proc/sys/kernel/core_uses_pid
# echo 1 > /proc/sys/kernel/core_setuid_ok
8. 重新起動或者重新啟動apache:
service httpd restart
9. 為了測試,使用ps aux查找apache進程,然后kill-ll ,檢查/var/apache-dump/目錄查找新的core文件:
# ps aux | grep htt | tail -n 2
apache 1331 0.0 2.6 80152 6776 ? S 13:59 0:00 /usr/sbin/httpd -
apache 1333 0.0 2.6 80152 6776 ? S 13:59 0:00 /usr/sbin/httpd -
# kill -11 1333
# ls -ld /var/apache-dump/core.1333
-rw------- 1 apache apache 71188480 Aug 16 13:48 /var/apache-dump/core.1333
一旦得到core文件,可以查看core文件,進行debug。