一、基础环境 1、发行版本 uname -a Linux 10.1.10.117 3.2.0-4-amd64 #1 SMP Debian 3.2.68-1+deb7u1 x86_64 GNU/Linux 2、安装apache2 apt-get -y install apache2-mpm-prefork 3、创建目录和赋予权限 mkdir /opt/game/core -p chown www-data /opt/game/core/ -R 二、打开core dump功能 1、查看core dump是否打开 ulimit -c 0 ulimit -a core file size (blocks, -c) 0 参数说明 -c 表示内核转储文件的大小限制 零表示未打开core dump功能 设定core文件的最大值 单位为区块。 -a 显示当前所有的资源限制 2、修改配置(单位KB) cat /etc/security/limits.conf * soft core 2048000 * hard core 2048000 3、生效 ulimit -c 2048000 4、检查 ulimit -a core file size (blocks, -c) 2048000 ulimit -c 2048000 二、修改core文件保存的路径 1、临时修改 1)core文件保存在/opt/game/core目录下 echo "/opt/game/core/%e.core.%s.%p.%h.%t" > /proc/sys/kernel/core_pattern 2)生成的core文件名将会变成core.pid echo 1 > /proc/sys/kernel/core_uses_pid 2、永久修改 1)在配置最后增加2行 cat /etc/sysctl.conf kernel.core_pattern = /opt/game/core/%e.core.%s.%p.%h.%t kernel.core_uses_pid = 1 2)永久生效 sysctl -p 3)参数说明 %e executable filename (without path prefix) #dump的文件名 %p PID of dumped process, as seen in the PID namespace in which the process resides #dump的进程PID %t time of dump, expressed as seconds since the Epoch,1970-01-01 00:00:00 +0000 #转储时刻(由1970年1月1日起计的秒数) %h hostname (same as nodename returned by uname(2)) #主机名 %s number of signal causing dump #coredump的信号 三、apache2设置 1、再/etc/apache2/apache2.conf最后添加1行 cat /etc/apache2/apache2.conf CoreDumpDirectory /opt/game/core 2、参数说明 语法:CoreDumpDirectory directory-path 这个指令用来控制Apache使用的内核转储目录,该转储目录默认位于“ServerRoot”下。因为这个目录通常对于运行服务器的用户是不可写的, 内核转储一般也不会写入内容。如果你在调试中需要内核转储,那么你可以用这个指令来指定另外一个目录。 3、重启apache2服务 /etc/init.d/apache2 restart 4、杀死apache2进程 先查看下apache2进程 root 2342 0.0 1.2 71568 2916 ? Ss 02:29 0:00 /usr/sbin/apache2 -k start www-data 2344 0.0 0.8 71592 2132 ? S 02:29 0:00 /usr/sbin/apache2 -k start www-data 2345 0.0 0.8 71592 2132 ? S 02:29 0:00 /usr/sbin/apache2 -k start www-data 2348 0.0 0.8 71592 2132 ? S 02:29 0:00 /usr/sbin/apache2 -k start www-data 2349 0.0 0.8 71592 2132 ? S 02:29 0:00 /usr/sbin/apache2 -k start www-data 2350 0.0 0.8 71592 2132 ? S 02:29 0:00 /usr/sbin/apache2 -k start kill -11 2342 kill -11 2344 kill -11 2345 kill -11 2348 kill -11 2349 kill -11 2350 信号11说明 11) SIGSEGV 试图访问未分配给自己的内存, 或试图往没有写权限的内存地址写数据. 5、查看到已经有core产生了 ll /opt/game/core/ -rw------- 1 root root 2596864 May 21 02:38 apache2.core.11.2342.10.1.10.117.1432190336 -rw------- 1 www-data www-data 2621440 May 21 02:38 apache2.core.11.2344.10.1.10.117.1432190338 -rw------- 1 www-data www-data 2621440 May 21 02:38 apache2.core.11.2345.10.1.10.117.1432190339 -rw------- 1 www-data www-data 2621440 May 21 02:39 apache2.core.11.2348.10.1.10.117.1432190344 -rw------- 1 www-data www-data 2621440 May 21 02:39 apache2.core.11.2349.10.1.10.117.1432190346 -rw------- 1 www-data www-data 2621440 May 21 02:39 apache2.core.11.2350.10.1.10.117.1432190349 6、使用gdb程序 1)先安装gdb apt-get -y install gdb 2)使用gdb程序查看 gdb apache2 -core /opt/game/core/apache2.core.11.2342.10.1.10.117.1432190336 GNU gdb (GDB) 7.4.1-debian Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/sbin/apache2...(no debugging symbols found)...done. [New LWP 2342] warning: Can‘t read pathname for load map: Input/output error. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by `/usr/sbin/apache2 -k start‘. Program terminated with signal 11, Segmentation fault. #0 0x00007f1d26736433 in select () from /lib/x86_64-linux-gnu/libc.so.6 四、参考文章 http://www.cnblogs.com/hazir/p/linxu_core_dump.html http://man7.org/linux/man-pages/man5/core.5.html http://www.cyberciti.biz/tips/configure-apache-web-server-for-core-dump.html
本文出自 “7928217” 博客,请务必保留此出处http://7938217.blog.51cto.com/7928217/1671716
原文地址:http://7938217.blog.51cto.com/7928217/1671716