检查内核配置

(RHEL6默认已经配置好内核)

系统内核和捕捉内核都需要的内核选项:

在 "Processor type and features."选项中启用"kexec system call"。
CONFIG_KEXEC=y

在"Filesystem" -> "Pseudo filesystems." 中启用"sysfs file system support"。
CONFIG_SYSFS=y

在"Kernel hacking."中启用"Compile the kernel with debug info"。
CONFIG_DEBUG_INFO=Y

配置捕捉内核的与架构无关的选项:

在"Processor type and features"中启用"kernel crash dumps"。
CONFIG_CRASH_DUMP=y

在"Filesystems" -> "Pseudo filesystems"中启用"/proc/vmcore support"。
CONFIG_PROC_VMCORE=y

配置捕捉内核的与架构相关的选项:

在"Processor type and features"中启用高端内存支持(可不配置)
CONFIG_HIGHMEM64G=y

在"Processor type and features"中启用"Build a relocatable kernel"。
CONFIG_RELOCATABLE=y

在"Processor type and features"->"Physical address where the kernel is loaded"中,为内核设置一个加载起始地址。在大多数的机器上,16M 是一个合适的值。
CONFIG_PHYSICAL_START=0x1000000

安装kdump工具

Kdump 用到的各种工具都在 kexec-tools 中。kernel-debuginfo 则是用来分析 vmcore 文件。

系统默认安装了kexec-tools:

rpm -qa|grep kexec

kexec-tools-2.0.0-188.el6.x86_64

[hisun@FJXM-DM2-HP-GYAPP-03 ~]$

调试 kdump 生成的 vmcore 文件,则需要手动安装 kernel-debuginfo 包。

Wget http://debuginfo.centos.org/6/x86_64/kernel-debuginfo-common-x86_64-2.6.32-131.0.15.el6.x86_64.rpm

wget http://debuginfo.centos.org/6/x86_64/kernel-debuginfo-2.6.32-131.0.15.el6.x86_64.rpm

上传到服务器安装:

rpm -i kernel-debuginfo-common-x86_64-2.6.32-131.0.15.el6.x86_64.rpm

warning: kernel-debuginfo-common-x86_64-2.6.32-131.0.15.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY

rpm -i kernel-debuginfo-2.6.32-131.0.15.el6.x86_64.rpm

warning: kernel-debuginfo-2.6.32-131.0.15.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY

修改内核引导参数,为启动捕获内核预留内存

编辑/etc/grub.conf, 在内核行的最后添加修改"crashkernel=128M" :(使用crashkernel=auto无法正常启动kdump服务)

kdump 配置

kdump 的配置文件是 /etc/kdump.conf,将以***释去掉:

#################

path /var/crash

core_collector makedumpfile -c --message-level 1 -d 31

#################

加载捕捉内核(没有重新编译内核不用加载)

在系统内核引导完成后,需要将捕捉内核加载到内存中。使用 kexec 工具将捕捉内核加载到内存:

kexec -p /vmlinuz-2.6.32-131.0.15.el6.x86_64 --initrd=initramfs-2.6.32-131.0.15.el6.x86_64.img --append="root=UUID=371bd4da-b3b5-4a88-b2e4-51e252cbae69"

设置开机启动kdump

# chkconfig kdump on

重新启动服务器:reboot

查看kdump状态是否正常:

# service kdump status
Kdump is operational

测试配置是否有效

可以通过 kexec 加载内核镜像,让系统准备好去捕获一个崩溃时产生的 vmcore。可以通过 sysrq 强制系统崩溃。(慎重使用,会重启设备)

# echo 1 > /proc/sys/kernel/sysrq

# echo c > /proc/sysrq-trigger

这造成内核崩溃,如配置有效,系统将重启进入 kdump 内核,当系统进程进入到启动 kdump 服务的点时,vmcore 将会拷贝到你在 kdump 配置文件中设置的位置。RHEL 的缺省目录是 : /var/crash

通过以下命令来分析crash的日志

#[root@FJXM-DM2-HP-GYAPP-03 ~]# crash /usr/lib/debug/lib/modules/2.6.32-131.0.15.el6.x86_64/vmlinux /var/crash/127.0.0.1-2015-03-23-16\:24\:17/vmcore

参考资料

http://www.ibm.com/developerworks/cn/linux/l-cn-kdump1/index.html

http://www.ibm.com/developerworks/cn/linux/l-cn-kdump4/index.html

http://www.ibm.com/developerworks/cn/linux/l-cn-dumpanalys