歡迎您光臨本站 註冊首頁

MySQL自動停機的問題處理實戰記錄

←手機掃碼閱讀     wooen @ 2020-06-08 , reply:0

最近幫別人做的一個項目機器上面跑MySQL老是隔一段時間就自動停了。剛開始以為是以外停止,也沒注意,就手動再啟動。可是過了沒兩天又停止了。

後來仔細查了查mysqld的日誌:

2020-05-27T10:15:12.569342Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.17) starting as process 19493
 2020-05-27T10:15:14.448256Z 0 [System] [MY-010229] [Server] Starting crash recovery...
 2020-05-27T10:15:14.475411Z 0 [System] [MY-010232] [Server] Crash recovery finished.
 2020-05-27T10:15:14.691345Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
 2020-05-27T10:15:15.677386Z 0 [System] [MY-010931] [Server] /usr/libexec/mysqld: ready for connections. Version: '8.0.17'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution.
 2020-05-27T10:15:15.951210Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/lib/mysql/mysqlx.sock' bind-address: '::' port: 33060
 2020-05-27T11:26:19.955004Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.17) starting as process 19757
 2020-05-27T11:26:20.181302Z 0 [ERROR] [MY-012681] [InnoDB] mmap(137363456 bytes) failed; errno 12
 2020-05-27T11:26:20.181360Z 1 [ERROR] [MY-012956] [InnoDB] Cannot allocate memory for the buffer pool
 2020-05-27T11:26:20.181379Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
 2020-05-27T11:26:20.181401Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
 2020-05-27T11:26:20.181543Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
 2020-05-27T11:26:20.183642Z 0 [ERROR] [MY-010119] [Server] Aborting
 2020-05-27T11:26:20.184163Z 0 [System] [MY-010910] [Server] /usr/libexec/mysqld: Shutdown complete (mysqld 8.0.17)  Source distribution.

上面顯示是Cannot allocate memory for the buffer pool,無法分配內存給緩存池。馬上想到是內存不足,這臺機器是1GB的內存,還跑著 Nginx 和 PHP-FPM 。

使用 top 看了看 mysqld 佔用的內存達到了48% 。內存佔用還是蠻高的。

當然了升級機器配置是比較好的辦法,但是畢竟經費有限。所以我們先給它加個swap交換空間:

  dd if=/dev/zero of=/swapfile bs=1M count=2048  mkswap /swapfile  swapon /swapfile  systemctl restart mysqld

 

上面我們加了2GB的交換空間給機器。然後重啟 mysqld。再使用top看了看,發現交換空間漸漸被使用了。

睡了一覺起來一看,mysqld服務沒有再自動停止,內存佔用已經下降到22%,看了看錯誤日誌,也是空的。

嗯,看來還不錯嘛。再觀察個幾天看看,沒問題的話應該就好了。



[wooen ] MySQL自動停機的問題處理實戰記錄已經有255次圍觀

http://coctec.com/docs/mysql/show-post-237505.html