首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> MySQL 資料庫 >> MariaDB 資料庫

低配 VPS 拯救指南:MariaDB OOM 崩潰添加 Swap 文件解決

     編輯:MariaDB 資料庫

故障日誌

InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137756672 bytes) failed; errno 12
InnoDB: Fatal error: cannot allocate memory for the buffer pool
[ERROR] Out of memory (Needed 128917504 bytes)

free -m 顯示 Swap = 0,物理內存不足且無交換分區是直接原因。

添加 1GB Swap 文件 (SSD 適用)

  1. 創建文件:
    dd if=/dev/zero of=/swapfile bs=1024 count=1048576
    
  2. 格式化並啟用:
    mkswap /swapfile
    swapon /swapfile
    
  3. 永久生效:編輯 /etc/fstab 追加
    /swapfile  swap  swap  defaults  0  0
    
  4. 驗證:free -m 或 cat /proc/swaps 顯示 1023M Swap 可用。

優化 MariaDB 內存佔用

在 /etc/my.cnf [mysqld] 區添加:

innodb_buffer_pool_size = 64M
performance_schema = OFF
table_open_cache = 200

重啟服務驗證

systemctl start httpd.service
systemctl start mariadb.service

網站恢復正常訪問。

總結

  • 低配 VPS 必加 Swap,SSD 下性能損失極小
  • 崩潰優先看日誌,tail -f 定位 OOM/權限/磁盘滿等硬傷
  • WordPress 較佔資源,低配機建議啟用緩存插件、禁用無用外掛
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved