• tomcat正常运行一段时间后,tomcat异常停,进程被killed


    tomcat异常停,进程被killed

    对应tomcat日志如下:

    /application/tomcat-service-8080/bin/catalina.sh: line 386: 4370 Killed "/usr/local/jdk/bin/java" "-Djava.util.logging.config.file=/application/tomcat-service-8080/conf/logg
    ing.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xms4096m -Xmx4096m -XX:PermSize=128M -XX:MaxNewSize=512m -XX:MaxPermSize=256m -Djava.awt.headless=tr
    ue -Djava.endorsed.dirs="/application/tomcat-service-8080/endorsed" -classpath

    日志中没有报错,没有内存溢出OutOfMemoryError

    Google之后了解到一个Linux OOM Killer

    Linux 内核根据应用程序的要求分配内存,通常来说应用程序分配了内存但是并没有实际全部使用,为了提高性能,这部分没用的内存可以留作它用,这部分内存是属于每个进程的,内核直接回收利用的话比较麻烦,所以内核采用一种过度分配内存(over-commit memory)的办法来间接利用这部分 “空闲” 的内存,提高整体内存的使用效率。一般来说这样做没有问题,但当大多数应用程序都消耗完自己的内存的时候麻烦就来了,因为这些应用程序的内存需求加起来超出了物理内存(包括 swap)的容量,内核(OOM killer)必须杀掉一些进程才能腾出空间保障系统正常运行。用银行的例子来讲可能更容易懂一些,部分人取钱的时候银行不怕,银行有足够的存款应付,当全国人民(或者绝大多数)都取钱而且每个人都想把自己钱取完的时候银行的麻烦就来了,银行实际上是没有这么多钱给大家取的。

    内核检测到系统内存不足、挑选并杀掉某个进程的过程可以参考内核源代码 linux/mm/oom_kill.c,当系统内存不足的时候,out_of_memory() 被触发,然后调用 select_bad_process() 选择一个 “bad” 进程杀掉,如何判断和选择一个 “bad” 进程呢,总不能随机选吧?挑选的过程由 oom_badness() 决定,挑选的算法和想法都很简单很朴实:最 bad 的那个进程就是那个最占用内存的进程。

    查看/var/log/messages

    Aug 2 20:01:03 iZ25crr8mcwZ systemd: Started Session 65527 of user root.
    Aug 2 20:10:14 iZ25crr8mcwZ systemd: Created slice user-0.slice.
    Aug 2 20:10:25 iZ25crr8mcwZ systemd: Starting Session 65528 of user root.
    Aug 2 20:10:53 iZ25crr8mcwZ systemd: Started Session 65528 of user root.
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: java invoked oom-killer: gfp_mask=0x201da, order=0, oom_score_adj=0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: java cpuset=/ mems_allowed=0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU: 0 PID: 4385 Comm: java Tainted: GF O-------------- 3.10.0-123.9.3.el7.x86_64 #1
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: ffff880008bf0b60 00000000f4c1c64c ffff880230453938 ffffffff815e239b
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: ffff8802304539c8 ffffffff815dd372 ffffffff810b69b8 ffff880036a9a050
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: 0000000000000202 ffff880008bf0b60 ffff8802304539b0 ffffffff811030af
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Call Trace:
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff815e239b>] dump_stack+0x19/0x1b
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff815dd372>] dump_header+0x8e/0x214
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff810b69b8>] ? ktime_get_ts+0x48/0xe0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff811030af>] ? delayacct_end+0x8f/0xb0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff8114526e>] oom_kill_process+0x24e/0x3b0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff81144dd6>] ? find_lock_task_mm+0x56/0xc0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff81145a96>] out_of_memory+0x4b6/0x4f0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff8114b5d9>] __alloc_pages_nodemask+0xa09/0xb10
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff81188349>] alloc_pages_current+0xa9/0x170
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff81141a67>] __page_cache_alloc+0x87/0xb0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff81143da8>] filemap_fault+0x188/0x430
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff81167e9e>] __do_fault+0x7e/0x520
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff8116c1e5>] handle_mm_fault+0x3e5/0xd90
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff815edb06>] __do_page_fault+0x156/0x540
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff810c2be2>] ? do_futex+0x172/0x5b0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff8109b836>] ? __dequeue_entity+0x26/0x40
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff81011619>] ? __switch_to+0x179/0x490
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff815edf0a>] do_page_fault+0x1a/0x70
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff810b6769>] ? do_gettimeofday+0x29/0x70
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff815ed599>] do_async_page_fault+0x29/0xe0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [<ffffffff815ea178>] async_page_fault+0x28/0x30
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Mem-Info:
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 DMA per-cpu:
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 0: hi: 0, btch: 1 usd: 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 1: hi: 0, btch: 1 usd: 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 2: hi: 0, btch: 1 usd: 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 3: hi: 0, btch: 1 usd: 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 DMA32 per-cpu:
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 0: hi: 186, btch: 31 usd: 84
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 1: hi: 186, btch: 31 usd: 113
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 2: hi: 186, btch: 31 usd: 109
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 3: hi: 186, btch: 31 usd: 45
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 Normal per-cpu:
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 0: hi: 186, btch: 31 usd: 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 1: hi: 186, btch: 31 usd: 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 2: hi: 186, btch: 31 usd: 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: CPU 3: hi: 186, btch: 31 usd: 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: active_anon:1714079 inactive_anon:38316 isolated_anon:0
    active_file:106 inactive_file:169 isolated_file:0
    unevictable:0 dirty:0 writeback:0 unstable:0
    free:25831 slab_reclaimable:17057 slab_unreclaimable:6114
    mapped:3441 shmem:96445 pagetables:4873 bounce:0
    free_cma:0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 DMA free:15900kB min:132kB low:164kB high:196kB active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB isolated(anon):
    0kB isolated(file):0kB present:15992kB managed:15908kB mlocked:0kB dirty:0kB writeback:0kB mapped:0kB shmem:0kB slab_reclaimable:0kB slab_unreclaimable:8kB kernel_stack:0kB pagetables:0kB uns
    table:0kB bounce:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? yes
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: lowmem_reserve[]: 0 2801 7792 7792
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 DMA32 free:44996kB min:24252kB low:30312kB high:36376kB active_anon:2645684kB inactive_anon:86640kB active_file:352kB inactive_file:608kB unevictab
    le:0kB isolated(anon):0kB isolated(file):0kB present:3129216kB managed:2869240kB mlocked:0kB dirty:0kB writeback:0kB mapped:10716kB shmem:230460kB slab_reclaimable:35324kB slab_unreclaimable:
    8996kB kernel_stack:2048kB pagetables:9864kB unstable:0kB bounce:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:1747 all_unreclaimable? yes
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: lowmem_reserve[]: 0 0 4990 4990
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 Normal free:42428kB min:43192kB low:53988kB high:64788kB active_anon:4210632kB inactive_anon:66624kB active_file:72kB inactive_file:68kB unevictabl
    e:0kB isolated(anon):0kB isolated(file):0kB present:5242880kB managed:5110124kB mlocked:0kB dirty:0kB writeback:0kB mapped:3048kB shmem:155320kB slab_reclaimable:32904kB slab_unreclaimable:15
    452kB kernel_stack:3408kB pagetables:9628kB unstable:0kB bounce:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:347 all_unreclaimable? yes
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: lowmem_reserve[]: 0 0 0 0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 DMA: 1*4kB (U) 1*8kB (U) 1*16kB (U) 0*32kB 2*64kB (U) 1*128kB (U) 1*256kB (U) 0*512kB 1*1024kB (U) 1*2048kB (R) 3*4096kB (M) = 15900kB
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 DMA32: 1204*4kB (UEMR) 950*8kB (UEM) 1208*16kB (UEM) 252*32kB (UEM) 72*64kB (UEM) 6*128kB (UE) 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 45184kB
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 Normal: 400*4kB (UEM) 326*8kB (UEM) 543*16kB (UEM) 237*32kB (EM) 145*64kB (UEM) 61*128kB (UEM) 15*256kB (UEM) 0*512kB 1*1024kB (M) 0*2048kB 0*4096k
    B = 42432kB
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: 96713 total pagecache pages
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: 0 pages in swap cache
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Swap cache stats: add 0, delete 0, find 0/0
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Free swap = 0kB
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Total swap = 0kB
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: 2097151 pages RAM
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: 94167 pages reserved
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: 274302 pages shared
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: 1961600 pages non-shared
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ pid ] uid tgid total_vm rss nr_ptes swapents oom_score_adj name
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 338] 0 338 14844 3705 33 0 0 systemd-journal
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 354] 0 354 26113 61 20 0 0 lvmetad
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 357] 0 357 10509 149 22 0 -1000 systemd-udevd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 510] 0 510 164576 2774 152 0 0 rsyslogd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 513] 81 513 7158 101 20 0 -900 dbus-daemon
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 515] 0 515 31583 163 17 0 0 crond
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 519] 28 519 363742 743 61 0 0 nscd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 609] 0 609 1621 25 8 0 0 iprupdate
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 612] 0 612 1621 25 9 0 0 iprinit
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 649] 0 649 9781 23 9 0 0 iprdump
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 850] 38 850 7399 155 19 0 0 ntpd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 895] 0 895 386 45 4 0 0 aliyun-service
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [19586] 0 19586 20697 210 44 0 -1000 sshd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [22773] 996 22773 21196 206 42 0 0 zabbix_agentd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [22774] 996 22774 21196 285 42 0 0 zabbix_agentd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [22775] 996 22775 21226 238 43 0 0 zabbix_agentd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [22776] 996 22776 21226 238 43 0 0 zabbix_agentd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [22777] 996 22777 21226 254 43 0 0 zabbix_agentd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [22778] 996 22778 21196 237 44 0 0 zabbix_agentd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [13392] 0 13392 59021 2804 68 0 0 salt-minion
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [13395] 0 13395 170977 5407 110 0 0 salt-minion
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 1901] 0 1901 30507 151 11 0 0 wrapper
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 1911] 0 1911 627491 17315 90 0 0 java
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 5580] 0 5580 6338 162 16 0 0 AliYunDunUpdate
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 7267] 0 7267 48303 1580 91 0 0 AliYunDun
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 4955] 0 4955 27501 34 10 0 0 agetty
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [18909] 1000 18909 28313 73 11 0 0 catalina.sh
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [18910] 1000 18910 1077 38 8 0 0 cronolog
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [18911] 1000 18911 1245006 596619 1349 0 0 java
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [19657] 0 19657 8671 80 22 0 0 systemd-logind
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 4368] 1000 4368 28313 73 10 0 0 catalina.sh
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 4369] 1000 4369 1077 38 7 0 0 cronolog
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [ 4370] 1000 4370 1796041 1028084 2224 0 0 java              
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [30951] 0 30951 33414 294 66 0 0 sshd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [31046] 1000 31046 33447 311 65 0 0 sshd
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: [31047] 1000 31047 29136 402 13 0 0 bash
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Out of memory: Kill process 4370 (java) score 514 or sacrifice child
    Aug 2 20:12:24 iZ25crr8mcwZ kernel: Killed process 4370 (java) total-vm:7184164kB, anon-rss:4112336kB, file-rss:0kB
    Aug 2 20:12:25 iZ25crr8mcwZ systemd-logind: Removed session 65322.
    Aug 2 20:20:01 iZ25crr8mcwZ systemd: Created slice user-0.slice.
    Aug 2 20:20:01 iZ25crr8mcwZ systemd: Starting Session 65529 of user root.

    服务杀死了大的内存进程 4370 ,所以tomcat进程异常消失

  • 相关阅读:
    关掉firefox(火狐)和palemoon地址栏自动加www.前缀功能【转】
    Maven入门指南(一)
    Linux 常用命令
    maven-编译速度优化
    monkeyscript
    GIT
    maven简介及基础使用
    使用xcrun打包iOS应用
    Mac系统下STF的环境搭建和运行
    npm介绍与cnpm介绍
  • 原文地址:https://www.cnblogs.com/asia90li/p/7280169.html
Copyright © 2020-2023  润新知