我的GCP VM之一是在F1-Micro类型运行,只有内存有限,614MB。来自Syslog,我发现它有一个PHP调用了OOM Killer消息。这通常意味着这台服务器基本上没有内存和额外的内存应该根据在线的一些帖子添加到这个系统中,尤其是2010年  邮政 :

“如果应用程序要求它,Linux内核喜欢始终分配内存。默认情况下,它并没有真正检查是否有足够的内存可用。鉴于行为应用程序可以根据真正可用的内存分配更多内存。在某些时候,它肯定会导致错误的情况。结果,将调用Oom杀手并将杀死该过程:“

确定可用内存和交换活动

在开始优化服务器之前,让我们使用它来查看内存。您可以使用以下命令显示内存:
$ free -m
要查看按内存使用排序的运行进程列表:
$ ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | less

检查日志错误

更多/ var / log / syslog


Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315747] php-fpm7.2 invoked oom-killer: gfp_mask=0x15080c0(GFP_KERNEL_ACCOUNT|__GFP_ZERO), nodemask=(null), order=0, oom_score_adj=0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315750] php-fpm7.2 cpuset=/ mems_allowed=0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315758] CPU: 0 PID: 961 Comm: php-fpm7.2 Not tainted 4.15.0-1040-gcp #42-Ubuntu
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315759] Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315760] Call Trace:
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315774]  dump_stack+0x8e/0xcb
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315780]  dump_header+0x71/0x285
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315782]  oom_kill_process+0x220/0x440
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315784]  out_of_memory+0x2d1/0x4f0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315786]  __alloc_pages_slowpath+0xa53/0xe00
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315793]  ? memcg_kmem_charge_memcg+0x7d/0xb0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315795]  __alloc_pages_nodemask+0x29a/0x2c0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315800]  alloc_pages_current+0x6a/0xe0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315805]  pte_alloc_one+0x17/0x40
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315810]  __pte_alloc+0x1e/0x120
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315811]  copy_pte_range+0x535/0x7a0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315814]  copy_page_range+0x3ed/0x6a0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315819]  copy_process.part.35+0xe1e/0x1ba0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315822]  _do_fork+0xdf/0x400
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315826]  ? __do_page_fault+0x2aa/0x4c0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315828]  SyS_clone+0x19/0x20
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315834]  do_syscall_64+0x7b/0x150
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315840]  entry_SYSCALL_64_after_hwframe+0x42/0xb7

Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315844] RIP: 0033:0x7efcde571b1c
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315845] RSP: 002b:00007ffc4e3848c0 EFLAGS: 00000246 ORIG_RAX: 0000000000000038
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315847] RAX: ffffffffffffffda RBX: 00007ffc4e3848c0 RCX: 00007efcde571b1c
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315847] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000001200011
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315848] RBP: 00007ffc4e384970 R08: 00007efce0ceac00 R09: 0000000000000000
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315849] R10: 00007efce0ceaed0 R11: 0000000000000246 R12: 0000000000000000
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315850] R13: 0000000000000020 R14: 0000000000000000 R15: ffffffffffffffff
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315852] Mem-Info:
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315856] active_anon:105955 inactive_anon:8694 isolated_anon:0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315856]  active_file:69 inactive_file:144 isolated_file:0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315856]  unevictable:0 dirty:0 writeback:0 unstable:0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315856]  slab_reclaimable:4470 slab_unreclaimable:7737
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315856]  mapped:8482 shmem:8871 pagetables:2067 bounce:0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315856]  free:7589 free_pcp:94 free_cma:0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315860] Node 0 active_anon:423820kB inactive_anon:34776kB active_file:276kB inactive_file:576kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:33928kB dirty:0kB writeback:0kB shmem:35484kB shmem_thp: 0kB shmem_pmdmapped: 0kB anon_thp: 0kB writeback_tmp:0kB unstable:0kB all_unreclaimable? no
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315860] Node 0 DMA free:2948kB min:788kB low:984kB high:1180kB active_anon:8952kB inactive_anon:1892kB active_file:4kB inactive_file:0kB unevictable:0kB writepending:0kB present:15992kB managed:15908kB mlocked:0kB kernel_stack:32kB pagetables:156kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315865] lowmem_reserve[]: 0 540 540 540 540
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315867] Node 0 DMA32 free:27408kB min:27460kB low:34324kB high:41188kB active_anon:414868kB inactive_anon:32884kB active_file:276kB inactive_file:576kB unevictable:0kB writepending:0kB present:612340kB managed:579656kB mlocked:0kB kernel_stack:2492kB pagetables:8112kB bounce:0kB free_pcp:376kB local_pcp:376kB free_cma:0kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315870] lowmem_reserve[]: 0 0 0 0 0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315873] Node 0 DMA: 27*4kB (UME) 21*8kB (UME) 39*16kB (UME) 20*32kB (UME) 12*64kB (UME) 5*128kB (UM) 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB = 2948kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315882] Node 0 DMA32: 278*4kB (UMEH) 421*8kB (UMEH) 307*16kB (UMEH) 147*32kB (UMEH) 40*64kB (UME) 16*128kB (UME) 2*256kB (U) 2*512kB (UE) 1*1024kB (M) 1*2048kB (M) 1*4096kB (U) = 27408kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315894] Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=1048576kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315896] Node 0 hugepages_total=0 hugepages_free=0 hugepages_surp=0 hugepages_size=2048kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315896] 9092 total pagecache pages
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315898] 0 pages in swap cache
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315899] Swap cache stats: add 0, delete 0, find 0/0
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315900] Free swap  = 0kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315900] Total swap = 0kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315901] 157083 pages RAM
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315901] 0 pages HighMem/MovableOnly
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315902] 8192 pages reserved
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315902] 0 pages cma reserved
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315903] 0 pages hwpoisoned
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315903] [ pid ]   uid  tgid total_vm      rss pgtables_bytes swapents oom_score_adj name
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315908] [  396]     0   396    27480      230   200704        0             0 systemd-journal
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315909] [  400]     0   400    24427       44    90112        0             0 lvmetad
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315911] [  412]     0   412    10926      397   118784        0         -1000 systemd-udevd
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315913] [  726]   100   726    20011      182   176128        0             0 systemd-network
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315914] [  746]   101   746    17688      175   167936        0             0 systemd-resolve
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315916] [  870]   103   870    12525      182   135168        0          -900 dbus-daemon
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315918] [  885]     0   885   157192      186   147456        0             0 lxcfs
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315919] [  918]     0   918    17663      200   176128        0             0 systemd-logind
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315921] [  919]     0   919    72021      234   192512        0             0 accounts-daemon
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315922] [  920]     0   920   163116     3151   233472        0          -900 snapd
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315924] [  924]     0   924     7083       51   106496        0             0 atd
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315926] [  925]   102   925    66817      322   167936        0             0 rsyslogd
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315927] [  949]   111   949    25333       85    98304        0             0 chronyd
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315929] [  961]     0   961   115363     1861   602112        0             0 php-fpm7.2
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315930] [  972]     0   972    42721     1955   237568        0             0 networkd-dispat
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315932] [  977]     0   977     7937       75    98304        0             0 cron
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315933] [  987]     0   987     1157       16    57344        0             0 sshguard-journa
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315935] [  990]     0   990    28251      140   233472        0             0 journalctl
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315936] [  991]     0   991     4091       99    65536        0             0 sshguard
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315937] [ 1003]     0  1003     1157       16    57344        0             0 sshg-fw
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315939] [ 1006]     0  1006    35435      386   233472        0             0 nginx
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315940] [ 1007]    33  1007    36181      680   241664        0             0 nginx
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315942] [ 1137]    33  1137   153381    27842   835584        0             0 php-fpm7.2
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315943] [ 1169]     0  1169    72220      219   212992        0             0 polkitd
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315945] [ 1299]     0  1299    46931     1985   270336        0             0 unattended-upgr
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315946] [ 1362]     0  1362     4103       37    73728        0             0 agetty
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315947] [ 1405]   112  1405   372876    45749   753664        0             0 mysqld
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315949] [ 1455]     0  1455     3722       34    73728        0             0 agetty
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315950] [ 1456]     0  1456    18852     3644   196608        0             0 google_network_
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315952] [ 1469]     0  1469    18916     3687   192512        0          -999 google_accounts
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315953] [ 1472]     0  1472    18866     3606   192512        0             0 google_clock_sk
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315955] [ 1482]     0  1482    18074      189   180224        0         -1000 sshd
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315956] [ 2375]    33  2375   146970    21314   782336        0             0 php-fpm7.2

Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315957] [ 9304]     0  9304    10048      157   110592        0             0 monit
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315959] [20018]    33 20018   138997    13458   720896        0             0 php-fpm7.2
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315960] [22124]     0 22124   115363     1432   557056        0             0 php-fpm7.2
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.315961] Out of memory: Kill process 1405 (mysqld) score 308 or sacrifice child
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.324223] Killed process 1405 (mysqld) total-vm:1491504kB, anon-rss:182996kB, file-rss:0kB, shmem-rss:0kB
Sep  1 10:46:22 ubuntu18niginxmariadb2 kernel: [74395.389736] oom_reaper: reaped process 1405 (mysqld), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB
Sep  1 10:46:25 ubuntu18niginxmariadb2 systemd[1]: mariadb.service: Main process exited, code=killed, status=9/KILL
Sep  1 10:46:25 ubuntu18niginxmariadb2 systemd[1]: mariadb.service: Failed with result 'signal'.
Sep  1 10:46:28 ubuntu18niginxmariadb2 systemd[1]: mariadb.service: Service hold-off time over, scheduling restart.
Sep  1 10:46:28 ubuntu18niginxmariadb2 systemd[1]: mariadb.service: Scheduled restart job, restart counter is at 1.
Sep  1 10:46:28 ubuntu18niginxmariadb2 systemd[1]: Stopped MariaDB 10.4.7 database server.
Sep  1 10:46:28 ubuntu18niginxmariadb2 systemd[1]: Starting MariaDB 10.4.7 database server...
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] /usr/sbin/mysqld (mysqld 10.4.7-MariaDB-1:10.4.7+maria~bionic-log) starting as process 22301 ...
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: Using Linux native AIO
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: Uses event mutexes
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: Number of pools: 1
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: Using SSE2 crc32 instructions
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: Completed initialization of buffer pool
Sep  1 10:46:29 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:29 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=589758381
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: Last binlog file '/var/log/mysql/mariadb-bin.000014', position 22151790
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: Creating shared tablespace for temporary tables
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: Waiting for purge to start
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: 10.4.7 started; log sequence number 589758390; transaction id 501113
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] Plugin 'FEEDBACK' is disabled.
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Sep  1 10:46:30 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:30 0 [Note] Recovering after a crash using /var/log/mysql/mariadb-bin
Sep  1 10:46:31 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:31 0 [Note] Starting crash recovery...
Sep  1 10:46:31 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:31 0 [Note] Crash recovery finished.
Sep  1 10:46:31 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:31 0 [Note] Server socket created on IP: '127.0.0.1'.
Sep  1 10:46:31 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:31 0 [Note] Reading of all Master_info entries succeeded
Sep  1 10:46:31 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:31 0 [Note] Added new Master_info '' to hash table
Sep  1 10:46:31 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:31 0 [Note] /usr/sbin/mysqld: ready for connections.
Sep  1 10:46:31 ubuntu18niginxmariadb2 mysqld[22301]: Version: '10.4.7-MariaDB-1:10.4.7+maria~bionic-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
Sep  1 10:46:31 ubuntu18niginxmariadb2 /etc/mysql/debian-start[22342]: Upgrading MySQL tables if necessary.
Sep  1 10:46:31 ubuntu18niginxmariadb2 systemd[1]: Started MariaDB 10.4.7 database server.
Sep  1 10:46:32 ubuntu18niginxmariadb2 /etc/mysql/debian-start[22345]: Looking for 'mysql' as: /usr/bin/mysql
Sep  1 10:46:32 ubuntu18niginxmariadb2 /etc/mysql/debian-start[22345]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
Sep  1 10:46:32 ubuntu18niginxmariadb2 /etc/mysql/debian-start[22345]: This installation of MariaDB is already upgraded to 10.4.7-MariaDB, use --force if you still need to run mysql_upgrade
Sep  1 10:46:32 ubuntu18niginxmariadb2 /etc/mysql/debian-start[22354]: Checking for insecure root accounts.
Sep  1 10:46:32 ubuntu18niginxmariadb2 /etc/mysql/debian-start[22358]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables
Sep  1 10:46:32 ubuntu18niginxmariadb2 mysqld[22301]: 2019-09-01 10:46:32 0 [Note] InnoDB: Buffer pool(s) load completed at 190901 10:46:32

基本上,PHP-FPM7.2调用OOM杀手杀死此VM的MySQL进程。这次能够成功地重新启动MariaDB。但很多次,整个系统也变得不入侵甚至是SSH会话。

GCP监控显示CPU,网络流量和磁盘IO在杀死MySQL进程期间增加。

有几种方法可以做到。我尝试的一种肮脏方式是使用Monit监控系统资源或这些关键进程和重启机器。另一种好方法是遵循帖子的建议,更改内核行为,该行为停止超越内存以获取应用程序请求,例如PHP-FPM7.2。需要将两个值包含在/etc/sysctl.conf中,这将自动应用于启动时:

vm.overcommit_memory = 2
vm.overcommit_ratio = 90

此overcommit_Memory Switch知道3种不同的设置:
  • 0:Linux内核可以自由地过度使用内存(这是默认值),如果有足够的内存,则应用启发式算法。
  • 1:Linux内核将始终过度使用内存,并不检查是否有足够的内存。这增加了内存失控的风险,而且还提高了内存密集型工作负载。
  • 2:Linux内核不会过度使用内存,只能将与定义的内存分配相同 过度组织_ratio.

过度组织, 此设置仅在OverCommit_Memory = 2时使用,并定义使用的物理RAM的百分比。交换空间取决于它的顶部。默认值为“50”,或50%。我尝试了75,80,90的不同价值,为您的VM。最终我发现90对我的VM获得MariaDB启动的最佳价值。

sysctl vm.overcommit_memory = 2 : 这将使此会话中活动的值在不需要重新启动的情况下。

您还可以将服务器配置为在基于此基础上的/etc/sysctl.conf中使用以下值发生oom-killer事件时重新启动 邮政:

vm.panic_on_oom = 1
kernel.panic = 5

或来自命令行,键入:
sysctl vm.panic_on_oom = 1
sysctl kernel.panic = 5


参考:

经过 jonny.

发表评论