Amazon EC2 Linux AMI MySQL 问题

Amazon EC2 Linux AMI MySQL 问题

我正在 Amazon EC2 实例上运行 Web 服务器,并使用 Amazon Linux AMI 作为我的实例操作系统(我认为是 CentOS 或类似的)。

无论如何,在过去的一个月左右,MySQL 出现了一些奇怪的问题。大约每周一次,MySQL 似乎会随机关闭,然后我会收到错误“无法通过套接字 mysql.sock 连接到本地 MySQL 服务器。”

我设法修复此错误的唯一方法是重新启动 EC2 实例,这意味着我几乎每周都要手动重新启动实例一次。我想知道为什么 MySQL 每周都会随机停止工作一次。

任何帮助将不胜感激。

内容/var/log/mysqld.log

30414 20:03:45 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
130414 20:03:45 [Note] Plugin 'FEDERATED' is disabled.
130414 20:03:45 InnoDB: The InnoDB memory heap is disabled
130414 20:03:45 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130414 20:03:45 InnoDB: Compressed tables use zlib 1.2.5
130414 20:03:45 InnoDB: Using Linux native AIO
130414 20:03:45 InnoDB: Initializing buffer pool, size = 128.0M
130414 20:03:45 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
130414 20:03:45  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
130414 20:03:46  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...
130414 20:03:46  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
130414 20:03:47  InnoDB: Waiting for the background threads to start
130414 20:03:48 InnoDB: 5.5.30 started; log sequence number 0
130414 20:03:48 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
130414 20:03:48 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
130414 20:03:48 [Note] Server socket created on IP: '0.0.0.0'.
130414 20:03:48 [Note] Event Scheduler: Loaded 0 events
130414 20:03:48 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.30'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
130519 22:55:03 [Note] /usr/libexec/mysqld: Normal shutdown

130519 22:55:03 [Note] Event Scheduler: Purging the queue. 0 events
130519 22:55:03  InnoDB: Starting shutdown...
130519 22:55:04  InnoDB: Shutdown completed; log sequence number 1595675
130519 22:55:04 [Note] /usr/libexec/mysqld: Shutdown complete

130519 22:55:04 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
130519 22:55:05 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
130519 22:55:05 [Note] Plugin 'FEDERATED' is disabled.
130519 22:55:05 InnoDB: The InnoDB memory heap is disabled
130519 22:55:05 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130519 22:55:05 InnoDB: Compressed tables use zlib 1.2.5
130519 22:55:05 InnoDB: Using Linux native AIO
130519 22:55:05 InnoDB: Initializing buffer pool, size = 128.0M
130519 22:55:05 InnoDB: Completed initialization of buffer pool
130519 22:55:05 InnoDB: highest supported file format is Barracuda.
130519 22:55:06  InnoDB: Waiting for the background threads to start
130519 22:55:07 InnoDB: 5.5.31 started; log sequence number 1595675
130519 22:55:07 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
130519 22:55:07 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
130519 22:55:07 [Note] Server socket created on IP: '0.0.0.0'.
130519 22:55:07 [Note] Event Scheduler: Loaded 0 events
130519 22:55:07 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.31'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
130602 19:10:33 mysqld_safe Number of processes running now: 0
130602 19:10:33 mysqld_safe mysqld restarted
130602 19:10:33 [Note] Plugin 'FEDERATED' is disabled.
130602 19:10:33 InnoDB: The InnoDB memory heap is disabled
130602 19:10:33 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130602 19:10:33 InnoDB: Compressed tables use zlib 1.2.5
130602 19:10:33 InnoDB: Using Linux native AIO
130602 19:10:33 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
130602 19:10:33 InnoDB: Completed initialization of buffer pool
130602 19:10:33 InnoDB: Fatal error: cannot allocate memory for the buffer pool
130602 19:10:33 [ERROR] Plugin 'InnoDB' init function returned error.
130602 19:10:33 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
130602 19:10:33 [ERROR] Unknown/unsupported storage engine: InnoDB
130602 19:10:33 [ERROR] Aborting

130602 19:10:33 [Note] /usr/libexec/mysqld: Shutdown complete

130602 19:10:33 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
130602 19:15:23 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
130602 19:15:23 [Note] Plugin 'FEDERATED' is disabled.
130602 19:15:23 InnoDB: The InnoDB memory heap is disabled
130602 19:15:23 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130602 19:15:23 InnoDB: Compressed tables use zlib 1.2.5
130602 19:15:23 InnoDB: Using Linux native AIO
130602 19:15:23 InnoDB: Initializing buffer pool, size = 128.0M
130602 19:15:23 InnoDB: Completed initialization of buffer pool
130602 19:15:24 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 129807478
130602 19:15:24  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Doing recovery: scanned up to log sequence number 129809289
130602 19:15:24  InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
130602 19:15:24  InnoDB: Waiting for the background threads to start
130602 19:15:25 InnoDB: 5.5.31 started; log sequence number 129809289
130602 19:15:25 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
130602 19:15:25 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
130602 19:15:25 [Note] Server socket created on IP: '0.0.0.0'.
130602 19:15:25 [Note] Event Scheduler: Loaded 0 events
130602 19:15:25 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.31'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
130604 12:07:41 mysqld_safe Number of processes running now: 0
130604 12:07:41 mysqld_safe mysqld restarted
130604 12:07:41 [Note] Plugin 'FEDERATED' is disabled.
130604 12:07:41 InnoDB: The InnoDB memory heap is disabled
130604 12:07:41 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130604 12:07:41 InnoDB: Compressed tables use zlib 1.2.5
130604 12:07:41 InnoDB: Using Linux native AIO
130604 12:07:41 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
130604 12:07:41 InnoDB: Completed initialization of buffer pool
130604 12:07:41 InnoDB: Fatal error: cannot allocate memory for the buffer pool
130604 12:07:41 [ERROR] Plugin 'InnoDB' init function returned error.
130604 12:07:41 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
130604 12:07:41 [ERROR] Unknown/unsupported storage engine: InnoDB
130604 12:07:41 [ERROR] Aborting

130604 12:07:41 [Note] /usr/libexec/mysqld: Shutdown complete

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

130604 12:10:47 [Note] /usr/libexec/mysqld: Shutdown complete

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

答案1

检查 /var/lib/mysql/mysql.sock 的所有权和权限。收到此错误消息时,请尝试检查该文件是否存在。如果不存在,请创建它并重新启动服务以查看它是否有效。

我猜是你的虚拟机内存不足。我建议使用像 Nginx 这样的轻量级 Web 服务器,并禁用 MySQL 中所有不使用的后端。我知道 MariaDB 会消耗大量内存,因为它使用了很多后端。

相关内容