EC2实例 - Wordpress数据库不断崩溃

时间:2016-05-31 10:57:24

标签: mysql wordpress amazon-web-services amazon-ec2 connection

我不知道为什么会这样,但我的Wordpress网站一直在崩溃“建立数据库连接时出错”错误。

重新启动mysql服务似乎暂时解决了这个问题,但它不可避免地一次又一次崩溃。

我认为这可能是内存问题所以我将我的实例从1gb升级到2gb。但似乎没有任何改变......如果它与内存无关,我宁愿不为此付出巨大的额外费用。

以下是与崩溃相关的一些mysql日志文件。所有崩溃似乎都包含以下内容:

160519 13:03:21 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
160519 13:03:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160519 13:03:21 [Note] /usr/libexec/mysql55/mysqld (mysqld 5.5.46) starting as process 18275 ...
160519 13:03:21 [Note] Plugin 'FEDERATED' is disabled.
160519 13:03:21 InnoDB: The InnoDB memory heap is disabled
160519 13:03:21 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160519 13:03:21 InnoDB: Compressed tables use zlib 1.2.8
160519 13:03:21 InnoDB: Using Linux native AIO
160519 13:03:21 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
160519 13:03:21 InnoDB: Completed initialization of buffer pool
160519 13:03:21 InnoDB: Fatal error: cannot allocate memory for the buffer pool
160519 13:03:21 [ERROR] Plugin 'InnoDB' init function returned error.
160519 13:03:21 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160519 13:03:21 [ERROR] Unknown/unsupported storage engine: InnoDB
160519 13:03:21 [ERROR] Aborting

160519 13:03:21 [Note] /usr/libexec/mysql55/mysqld: Shutdown complete

**** **** UPDATE

所以我已经改变了innodb_buffer_pool_size的大小,如下所述,并且还创建了一个交换文件。我的网站每隔几个小时仍会崩溃,我正在慢慢失去生存意愿。

160507 16:28:20 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160507 16:28:20 [Note] /usr/libexec/mysql55/mysqld (mysqld 5.5.46) starting as process 26457 ...
160507 16:28:20 [Note] Plugin 'FEDERATED' is disabled.
160507 16:28:20 InnoDB: The InnoDB memory heap is disabled
160507 16:28:20 InnoDB: Mutexes and rw_locks use GCC atomic builtins
160507 16:28:20 InnoDB: Compressed tables use zlib 1.2.8
160507 16:28:20 InnoDB: Using Linux native AIO
160507 16:28:20 InnoDB: Initializing buffer pool, size = 128.0M
160507 16:28:20 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
160507 16:28:20  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
160507 16:28:21  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
160507 16:28:21  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
160507 16:28:21  InnoDB: Waiting for the background threads to start
160507 16:28:22 InnoDB: 5.5.46 started; log sequence number 0
160507 16:28:22 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
160507 16:28:22 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
160507 16:28:22 [Note] Server socket created on IP: '0.0.0.0'.
160507 16:28:22 [Note] Event Scheduler: Loaded 0 events
160507 16:28:22 [Note] /usr/libexec/mysql55/mysqld: ready for connections.
Version: '5.5.46'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
160507 17:56:05 [Note] /usr/libexec/mysql55/mysqld: Normal shutdown

160507 17:56:05 [Note] Event Scheduler: Purging the queue. 0 events
160507 17:56:05  InnoDB: Starting shutdown...
160507 17:56:06  InnoDB: Shutdown completed; log sequence number 2733606
160507 17:56:06 [Note] /usr/libexec/mysql55/mysqld: Shutdown complete

1 个答案:

答案 0 :(得分:0)

您的缓冲区大小太高。它可能不需要那么大,请参阅dba.stackexchange.com上的这个答案

https://dba.stackexchange.com/questions/27328/how-large-should-be-mysql-innodb-buffer-pool-size

如果你使用的是亚马逊Linux,根据mysql docs(https://dev.mysql.com/doc/refman/5.7/en/ha-vm-aws-setup.html),这个设置在/etc/my.cnf

将此文件中的设置改为innodb_buffer_pool_size = 10M可能会解决您的问题

以上修复了上述日志中显示的具体问题。如果记录了另一个涉及内存使用的问题,请使用这些命令添加4GiB交换文件

/bin/dd if=/dev/zero of=/swapfile bs=1M count=4096; /sbin/mkswap /swapfile; /sbin/swapon /swapfile

使用swap并不是魔法它会让你的系统运行缓慢而臃肿。但是,如果这让你过去了#34; blips"在内存使用方面,它可能是好的