在512MB的Debian服务器上的MySQL崩溃(内存问题?)如何解决?

我在一台512MB的Debian 7.5服务器上。 我醒来发现mysqld没有运行, syslog显示如下行:

 Aug 9 09:00:58 web kernel: [1086155.903755] Out of memory: Kill process 2669 (m ysqld) score 139 or sacrifice child Aug 9 09:00:58 web kernel: [1086155.903920] Killed process 2669 (mysqld) total- vm:448964kB, anon-rss:70396kB, file-rss:0kB Aug 9 09:00:59 web mysqld_safe: Number of processes running now: 0 Aug 9 09:00:59 web mysqld_safe: mysqld restarted [...] Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: The InnoDB memory heap is disabled Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Mutexes and rw_locks use GCC atomic builtins Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Compressed tables use zlib 1.2.7 Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Using Linux native AIO Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Initializing buffer pool, size = 128.0M Aug 9 09:01:01 web mysqld: InnoDB: mmap(137363456 bytes) failed; errno 12 Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Completed initialization of buffer pool Aug 9 09:01:01 web mysqld: 140809 9:01:01 InnoDB: Fatal error: cannot allocate memory for the buffer pool Aug 9 09:01:01 web mysqld: 140809 9:01:01 [ERROR] Plugin 'InnoDB' init function returned error. Aug 9 09:01:01 web mysqld: 140809 9:01:01 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. Aug 9 09:01:01 web mysqld: 140809 9:01:01 [ERROR] Unknown/unsupported storage engine: InnoDB Aug 9 09:01:01 web mysqld: 140809 9:01:01 [ERROR] Aborting Aug 9 09:01:01 web mysqld: Aug 9 09:01:01 web mysqld: 140809 9:01:01 [Note] /usr/sbin/mysqld: Shutdown complete Aug 9 09:01:01 web mysqld: Aug 9 09:01:02 web mysqld_safe: mysqld from pid file /var/run/mysqld/mysqld.pid ended Aug 9 11:08:44 web mysqld_safe: Starting mysqld daemon with databases from /var/lib/mysql [...] Aug 9 11:08:44 web mysqld: 140809 11:08:44 InnoDB: Database was not shut down normally! Aug 9 11:08:44 web mysqld: InnoDB: Starting crash recovery. Aug 9 11:08:44 web mysqld: InnoDB: Reading tablespace information from the .ibd files... Aug 9 11:08:44 web mysqld: InnoDB: Restoring possible half-written data pages from the doublewrite Aug 9 11:08:44 web mysqld: InnoDB: buffer... 

然后一堆警告说不同的表被标记为崩溃。 然而,当我进入mysql并运行check table <table name>; ,它说没关系。

它看起来像内存错误的configuration。 这是我的/etc/mysql/my.cnf文件,它几乎是开箱即用的:

 # # The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html # This will be passed to all mysql clients # It has been reported that passwords should be enclosed with ticks/quotes # escpecially if they contain "#" chars... # Remember to edit /etc/mysql/debian.cnf when changing the socket location. [client] port = 3306 socket = /var/run/mysqld/mysqld.sock # Here is entries for some specific programs # The following values assume you have at least 32M ram # This was formally known as [safe_mysqld]. Both versions are currently parsed. [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking # # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 127.0.0.1 # # * Fine Tuning # key_buffer_size = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover-options = BACKUP #max_connections = 100 #table_cache = 64 #thread_concurrency = 10 # # * Query Cache Configuration # query_cache_limit = 1M query_cache_size = 16M # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! #general_log_file = /var/log/mysql/mysql.log #general_log = 1 # # Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf. # # Here you can see queries with especially long duration #log_slow_queries = /var/log/mysql/mysql-slow.log #long_query_time = 2 #log-queries-not-using-indexes # # The following can be used as easy to replay backup logs or for replication. # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. #server-id = 1 #log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 10 max_binlog_size = 100M #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer_size = 16M # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # !includedir /etc/mysql/conf.d/ 

任何帮助将非常感激! 这是一个生产服务器,我无法负担MySQL服务器刚起来,随机死亡。 谢谢!

这里是my.cnf[mysqld]部分,没有注释和空行

 [mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking bind-address = 127.0.0.1 key_buffer_size = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 myisam-recover-options = BACKUP query_cache_limit = 1M query_cache_size = 16M expire_logs_days = 10 max_binlog_size = 100M 

您已经在运行mysqld,只有基本的连接,InnoDB存储引擎和每连接内存设置(sort_buffer_size,join_buffer_size,read_buffer_size,read_rnd_buffer_size),因为没有设置这些选项。 因此,它们使用默认值运行。

您从系统日志中发布的内容不能明确指向操作系统中的其他进程(某些其他进程)。 尽pipe如此,你只需要更多的内存。 我有信心排除mysqld的原因。 它只是内存不足情况的受害者。

如果您觉得mysqld涉及更深入的内容,请查看错误日志。 如果内存泄漏是问题的一部分,它应该抛弃内存跟踪。 由于您没有在my.cnf设置错误日志文件,因此您应该能够以hostname作为错误日志文件的前缀在/var/log/mysqlfind错误日志。