当前位置 主页 > 服务器问题 > win服务器问题汇总 >

    mariadb 在低配 VPS 上崩溃问题处理方案

    栏目:win服务器问题汇总 时间:2019-10-08 10:22

    引言

    最近博客又抽风了,打开主页后提示 Error Establishing a Database Connection 。仔细想想,应该就是数据库服务器 mariadb 挂了;以前也遇到过类似的问题。经过分析日志,并结合网上的资料最终解决了问题。

    日志

    以下是 mariadb 服务器挂掉时的比较关键的日志信息,从下面的日志信息中,我们可以很容易地看出由于内存不足,从而导致数据库服务器启动时崩溃。

    InnoDB: Starting crash recovery.
    InnoDB: Reading tablespace information from the .ibd files...
    InnoDB: Restoring possible half-written data pages from the doublewrite
    InnoDB: buffer...
    160919  2:47:12  InnoDB: Waiting for the background threads to start
    160919  2:47:13 Percona XtraDB (http://www.percona.com) 5.5.46-MariaDB-37.6 started; log sequence number 352718445
    160919  2:47:13 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
    160919  2:47:13 [Note] Plugin 'FEEDBACK' is disabled.
    160919  2:47:13 [Note] Server socket created on IP: '0.0.0.0'.
    160919  2:47:13 [Note] Event Scheduler: Loaded 0 events
    160919  2:47:13 [Note] /usr/libexec/mysqld: ready for connections.
    Version: '5.5.47-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
    160919 02:47:35 mysqld_safe Number of processes running now: 0
    160919 02:47:35 mysqld_safe mysqld restarted
    160919  2:47:35 [Note] /usr/libexec/mysqld (mysqld 5.5.47-MariaDB) starting as process 28614 ...
    160919  2:47:35 InnoDB: The InnoDB memory heap is disabled
    160919  2:47:35 InnoDB: Mutexes and rw_locks use GCC atomic builtins
    160919  2:47:35 InnoDB: Compressed tables use zlib 1.2.7
    160919  2:47:35 InnoDB: Using Linux native AIO
    160919  2:47:35 InnoDB: Initializing buffer pool, size = 128.0M
    InnoDB: mmap(137756672 bytes) failed; errno 12
    160919  2:47:35 InnoDB: Completed initialization of buffer pool
    160919  2:47:35 InnoDB: Fatal error: cannot allocate memory for the buffer pool
    160919  2:47:35 [ERROR] Plugin 'InnoDB' init function returned error.
    160919  2:47:35 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    160919  2:47:35 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
    160919  2:47:35 [ERROR] mysqld: Out of memory (Needed 96681984 bytes)
    160919  2:47:35 [ERROR] mysqld: Out of memory (Needed 72499200 bytes)
    160919  2:47:35 [Note] Plugin 'FEEDBACK' is disabled.
    160919  2:47:35 [ERROR] Unknown/unsupported storage engine: InnoDB
    160919  2:47:35 [ERROR] Aborting

    解决

    在使用 free -m 查看内存信息时,发现 swap 分区大小为 0。难怪说数据库服务器无法启动呢,在内存不够用的情况下,又无法使用 swap 分区,自然崩溃了。由于 VPS 使用了 SSD,性能自然不错。下面我们给服务器系统 CentOS 7 添加 1024M 的 swap 分区,采用的方法是创建一个 swap 文件:

    使用下面的命令创建 swapfile :