首页 > 开发 > Apache > 正文

如何配置RHEL实现apache能在出现段错误时输出core

2018-10-16 21:21:40
字体:
来源:转载
供稿:网友
解决方法:

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 ___FCKpd___8quot;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 <PID>,检查/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。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表