![如何配置内核崩溃后自动重启?](https://linux22.com/image/809528/%E5%A6%82%E4%BD%95%E9%85%8D%E7%BD%AE%E5%86%85%E6%A0%B8%E5%B4%A9%E6%BA%83%E5%90%8E%E8%87%AA%E5%8A%A8%E9%87%8D%E5%90%AF%EF%BC%9F.png)
现在,这是我第一次在只能远程访问(即非物理访问)的系统上遇到内核崩溃。我遇到的内核崩溃基本上就是上面描述的这里,只有内核版本是:
Pid: 15483, comm: kvm Not tainted 2.6.32-30-server #59-Ubuntu MS-7522
该系统是 Ubuntu 10.04,我一直在使用 ksplice 来保证其安全而无需重启。
整个恐慌显然导致系统无响应。由于它运行的是虚拟机,这是不可接受的。现在,我的问题是:有没有办法配置系统(例如通过sysctl.conf
)在遇到内核崩溃时自动重启?如果有这样的选项,但不建议使用它,请提供指示或信息,说明为什么不推荐使用它,以便我可以做出明智的决定,是使用它还是不使用它。
供您参考,以下是 syslog 的摘录:
BUG: unable to handle kernel NULL pointer dereference at (null)
IP: [<ffffffffa0339e6a>] gfn_to_rmap+0x2a/0x80 [kvm]
PGD 182eff067 PUD 2103cd067 PMD 0
Oops: 0000 [#1] SMP
last sysfs file: /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
CPU 2
Modules linked in: btrfs zlib_deflate crc32c libcrc32c ufs qnx4 hfsplus hfs minix ntfs vfat msdos fat jfs xfs exportfs reiserfs ksplice_a2zjpxfc ksplice_aeduoyr1 ksplice_ocpqubki ksplice_koav9q4r_vmlinux_new ksplice_koav9q4r ksplice_6rzac0n3_vmlinux_new ksplice_6rzac0n3 ksplice_sqv65gpe ksplice_74bgebjk ksplice_l13a9izo_vmlinux_new ksplice_l13a9izo ksplice_51l2thd5_vmlinux_new ksplice_51l2thd5 ksplice_mzqhwd6a ksplice_0k98nifa_vmlinux_new ksplice_0k98nifa ksplice_c0g8d8te_vmlinux_new ksplice_c0g8d8te ksplice_6jvv7tl8_vmlinux_new ksplice_6jvv7tl8 ksplice_o2xegqal ksplice_r7xdx1no ksplice_ly8vh9y3_vmlinux_new ksplice_ly8vh9y3 nls_cp437 ip6table_filter ip6_tables kvm_intel kvm bridge stp nls_utf8 cifs ipt_LOG ipt_MASQUERADE ipt_REJECT xt_recent xt_state xt_tcpudp iptable_filter iptable_nat nf_nat nf_conntrack_ipv4 nf_conntrack nf_defrag_ipv4 xt_multiport ip_tables x_tables fbcon tileblit font bitblit softcursor snd_hda_intel vga16fb vgastate snd_hda_codec snd_hwdep nouveau snd_pcm ttm snd_timer snd drm_kms_helper soundcore snd_page_alloc drm lp i2c_algo_bit parport multipath linear aacraid 3w_9xxx 3w_xxxx raid10 raid456 async_pq async_xor xor async_memcpy async_raid6_recov raid6_pq async_tx raid1 raid0 ahci r8169 mii sata_nv sata_sil sata_via [last unloaded: ksplice_a2zjpxfc_ocfs2_new]
Pid: 15483, comm: kvm Not tainted 2.6.32-30-server #59-Ubuntu MS-7522
RIP: 0010:[<ffffffffa0339e6a>] [<ffffffffa0339e6a>] gfn_to_rmap+0x2a/0x80 [kvm]
RSP: 0018:ffff88014ee4d828 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 400000000001ec15 RCX: ffff8801d5e28990
RDX: 0000000000000023 RSI: 0000000000000000 RDI: 0000000000000000
RBP: ffff88014ee4d838 R08: 0000000000000023 R09: 0000000000000100
R10: 0000000000000000 R11: 0000000000000007 R12: 0000000000000001
R13: 00000000000ba08a R14: ffff880032c0dbb0 R15: ffff88014ee4d928
FS: 00007f1b0d201700(0000) GS:ffff880008e40000(0000) knlGS:0000000000000000
CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033
CR2: 0000000000000000 CR3: 0000000158378000 CR4: 00000000000026f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process kvm (pid: 15483, threadinfo ffff88014ee4c000, task ffff88000d274500)
Stack:
ffff8800b418d0a8 ffff8801d5e28000 ffff88014ee4d868 ffffffffa0339f5f
<0> ffff8801d5e28000 ffffc90016afa8a8 fff0000000000fff 000000018849a000
<0> ffff88014ee4d8b8 ffffffffa033a4cf 0000000000000001 ffff8800b418d0a8
Call Trace:
[<ffffffffa0339f5f>] rmap_remove+0x9f/0x1c0 [kvm]
[<ffffffffa033a4cf>] kvm_set_pte_rmapp+0xff/0x170 [kvm]
[<ffffffffa033653d>] kvm_handle_hva+0x9d/0x120 [kvm]
[<ffffffffa033a3d0>] ? kvm_set_pte_rmapp+0x0/0x170 [kvm]
[<ffffffffa0336601>] kvm_set_spte_hva+0x21/0x30 [kvm]
[<ffffffff8155e2ce>] ? _spin_lock+0xe/0x20
[<ffffffffa0322aa4>] kvm_mmu_notifier_change_pte+0x44/0x60 [kvm]
[<ffffffff81130e3e>] __mmu_notifier_change_pte+0x3e/0x90
[<ffffffff811172a4>] do_wp_page+0x674/0x850
[<ffffffff81095228>] ? tick_dev_program_event+0x68/0xd0
[<ffffffff8108a059>] ? __hrtimer_start_range_ns+0x189/0x400
[<ffffffff81117c2c>] handle_mm_fault+0x2ec/0x3c0
[<ffffffff81113846>] ? follow_page+0x2d6/0x350
[<ffffffff81117e39>] __get_user_pages+0x139/0x480
[<ffffffffa033de1e>] ? T.1169+0x1fe/0x2e0 [kvm]
[<ffffffff81118219>] get_user_pages+0x49/0x50
[<ffffffff81045b27>] get_user_pages_fast+0x157/0x1c0
[<ffffffffa0323af1>] gfn_to_pfn+0x41/0x150 [kvm]
[<ffffffffa034026d>] tdp_page_fault+0x9d/0x140 [kvm]
[<ffffffff81195177>] ? mb_cache_entry_insert+0xb7/0x1d0
[<ffffffffa033cc2f>] kvm_mmu_page_fault+0x1f/0xa0 [kvm]
[<ffffffffa037dbf8>] handle_ept_violation+0x68/0x130 [kvm_intel]
[<ffffffffa0380a8a>] vmx_handle_exit+0xca/0x250 [kvm_intel]
[<ffffffffa032f997>] vcpu_enter_guest+0x227/0x4c0 [kvm]
[<ffffffffa032fcac>] __vcpu_run+0x7c/0x350 [kvm]
[<ffffffffa033621d>] kvm_arch_vcpu_ioctl_run+0x8d/0x1d0 [kvm]
[<ffffffffa03252e3>] kvm_vcpu_ioctl+0x473/0x5c0 [kvm]
[<ffffffff811567b2>] vfs_ioctl+0x22/0xa0
[<ffffffff81084fa6>] ? common_timer_set+0x116/0x1a0
[<ffffffff81156951>] do_vfs_ioctl+0x81/0x410
[<ffffffff81156d61>] sys_ioctl+0x81/0xa0
[<ffffffff810131b2>] system_call_fastpath+0x16/0x1b
Code: 00 55 48 89 e5 48 83 ec 10 48 89 1c 24 4c 89 64 24 08 0f 1f 44 00 00 41 89 d4 48 89 f3 e8 3f 9b fe ff 41 83 fc 01 48 89 c6 75 19 <48> 2b 18 48 c1 e3 03 48 03 58 18 48 89 d8 4c 8b 64 24 08 48 8b
RIP [<ffffffffa0339e6a>] gfn_to_rmap+0x2a/0x80 [kvm]
RSP <ffff88014ee4d828>
CR2: 0000000000000000
---[ end trace 18481f74af4eef67 ]---
答案1
您正在寻找的内核参数是kernel.panic=1
(其中 1 是重新启动之前的秒数)。
您可以将其添加到 sysctl.conf、sysctl.d、启动行或您通常设置的内核参数中。确保您有某种方式来监控正常运行时间,以便您知道何时发生内核崩溃。