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

引言

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

日志

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

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 (
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 :

使用下面的命令配置 swap 文件:

mkswap /swapfile

接下来,使用下面的命令立即启用 swapfile ,这样就不用等到下次重启时自动启用:

swapon /swapfile

最后,我们在 /etc/fstab 中添加下面一行,这样可以在系统下次重启时自动生效创建的 swapfile :

/swapfile swap swap defaults 0 0

使用 cat /proc/swaps 或 free -m 查看 swapfile 的生效情况,如下图所示:

在完成上面的步骤后,我们还可以在 /etc/my.cnf 配置文件中添加一些配置信息,降低 mariadb 资源需求,具体的配置请参考文末给出的链接。

启动

启动 apache 服务器: systemctl start httpd.service ;
启动 mariadb 服务器: systemctl start mariadb.service 。
启动完成后,再次打开网站主页,bingo,问题解决了!

总结

低配 VPS 最好还是要多增加 swap 分区大小,尤其对于使用 SSD 的 VPS 而言, swap 分区的性能也非常不错;
数据库服务器崩溃后,一定要记得学会分析日志。最简单的做法就是使用 tail 命令看看最近的崩溃日志,并根据崩溃信息寻找解决问题的办法;

WordPress 程序本身比较占资源,所以运行在低配的 VPS 时,还是需要做些优化工作。具体请参考文末给出的链接。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


安装开始...1.打开“https://dev.mysql.com/downloadsepo/yum/”下载Mysql源      将下载好的mysql源上传linux服务器 2.yumlocalinstallmysql80*#安装源 centos7中默认安装的是mariadb数据库,如果想要安装mysql,首先要移除mariadb;
安装Helm3#官网下载慢#wgethttps://get.helm.sh/helm-v3.5.4-linux-amd64.tar.gzwgethttp://qiniu.dev-share.top/helm-v3.5.4-linux-amd64.tar.gztar-zxvfhelm-v3.5.4-linux-amd64.tar.gzcplinux-amd64/helm/usr/local/bin#查看helmclient版本helmversion
通过Linux命令行启动用的指令:systemctlstartmariadb.service反馈:Failedtostartmariadb.service:Unitmariadb.servicenotfound.MariaDB简介MariaDB是MySQL的一个分支,MariaDB打算保持与MySQL的高度兼容性,确保具有库二进制奇偶校验的直接替换功能,以及与MySQLAPI和命令
InstallingMariaDBServer10.4TodeployMariaDBCommunityServer10.4onRHEL7orCentOS7,firstdownloadandusethe mariadb_repo_setup scripttoconfiguretheMariaDBrepositoriesforYUM:$sudoyuminstallwget$wgethttps://downloads.mariadb.com/
阅读目录一什么是存储引擎二mysql支持的存储引擎三使用存储引擎一什么是存储引擎mysql中建立的库--> 文件夹库中建立的表--> 文件现实生活中我们用来存储数据的文件有不同的类型,每种文件类型对应各自不同的处理机制:比如处理文本用txt类型,处理表格用excel,处理图片
1、安装MariaDB安装命令yum-yinstallmariadbmariadb-server安装完成MariaDB,首先启动MariaDBsystemctlstartmariadb设置开机启动systemctlenablemariadb[root@node1~]#systemctlenablemariadbCreatedsymlinkfrom/etc/systemd/system/multi-user.target.wants/m
Centos7.5 刚安装的mariadb数据库报错报错:ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:NO)原因一:没有启动数据库解决方法:systemctlstartmariadbsystemctlenablemariadb原因二:未知解决方法:[root@db01~]#
基于YUM安装的mariadb多实例.=================================================================1.yum安装mariadb-server包#yuminstallmariadb-server2.创建多实例对应的目录结构#mkdir/mysql/{3306,3307,3308}/{data,etc,socket,log,bin,pid}-pv#tree/mysql//mysql/
一、系统环境[root@localhost~]#cat/etcedhat-releaseCentOSLinuxrelease7.6.1810(Core)二、mysql安装#yuminstallmysqlmysql-servermysql-devel安装mysql-server失败,如下图:[root@localhost~]#yuminstallmysql-serverLoadedplugins:fastestmirrorLoadingm
数据库的选择两大点是:开源和跨平台,满足这三点MySQL、MongoDB和MariaDB。其中MariaDB是MySQL的分支,也是它的进阶产品,未来很有可能替代MySQL。与MySQL相比较,MariaDB更强的地方在于:Maria 存储引擎PBXT存储引擎XtraDB 存储引擎FederatedX 存储引擎更快的复制查询处理线
使用Navicat连接数据库时出现了 HostxxxisnotallowedtoconnecttothisMariaDbserver的情况。发现了是因为授权的问题,使得连接权限受阻。所以,只需要进入数据库中,给予其权限即可。具体解决代码如下:[root@localhost~]#mysql-uroot-pEnterpassword:#首先进入mys
1.临时表当绘画结束时,临时表会自动销毁,无法用showtables查看临时表。MariaDB[jason]>createtemporarytabletmp(prochar(30),citychar(30));QueryOK,0rowsaffected(0.01sec)MariaDB[jason]>insertintotmpvalues('shanghai','shanghai');QueryOK,1
为了看阳光我来到世上数据库介绍数据库是一个存放数据的仓库,目前市面上最流行的数据库大致氛围的两种,一种叫做关系型数据库,一种叫做非关系型数据库,而关系型数据库近期流行的即为mysql,mysql原本是一个开源的数据库后被oracle公司收购,开始进行服务收费,因此,市面上大多数免费
1,Linux上的mysql MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松
启动Mariadb前提需安装mariadb-server-安装mariadb-serveryuminstall-ymariadb-server-启动服务systemctlstartmariadb.service-添加到开机启动systemctlenablemariadb.service-安全设置,以及修改数据库管理员密码mysql_secure_installation-启
1、查看是否安装及可用安装:yumlist|grepmaria2、安装maria(依赖其他几个安装包):yuminstallmariadb-server.x86_64输入'y'继续安装直到安装结束3、检查是否安装:4、安装完后登录提示错误:mysql-uroot-p是由于安装完但是并未启动maria服务5、启动maria有以下几种方法:system
通过yum安装mariadb,并配置MySQL主从服务器主服务器:192.168.10.11从服务器:192.168.10.12#!/bin/bash#====================================================#Author:Mr.Song#CreateDate:2019-02-21#Description:autoconfigMySQLmaster&slave#=====================
实验:实现基于SSL加密的主从复制实验步骤:环境:三台主机,一台CA:200,一台master:150,一台slave:100平时都是在CA上帮用户生成私钥,在服务器上做的1CA,master,slave的证书相关文件mkdir/etc/my.cnf.d/sslcd/etc/my.cnf.d/sslopensslgenrsa2048>cakey.pemopensslreq-new-x509-k
MariaDB[db1]>select*fromstudent;+----+------+-----+--------+-------+|id|name|age|gender|phone|+----+------+-----+--------+-------+|1|a|20|m|119||2|b|20|m|120||3|c|20|m|110
过年了,在老家闲余时间想敲敲代码,发现在安装mariaDb的时候一直报错错误信息:Service‘MySQL’(MySQL)Faildtostart,Verifythatyouhavesuffcientprivilegestostartsystemservices.服务的MySQL(MySQL)启动错误,确认你有权限启动系统服务。记得多年前在使用sqlserver数