我是小型虚拟服务器的初学者系统管理员。服务器的主要功能是运行用PHP编写的开源Moodle课程管理系统软件。它依赖于数据库(在本例中为MySQL)和Web服务器(在本例中为Apache)。
该服务器运行64位CentOS 5.8版(最终版),具有1 GB内存和200 GB磁盘,内核版本2.6.18-308.8.2.el5xen。 MySQL版本是使用readline 5.1的Linux(x86_64)版本14.14 Distrib 5.5.25。
我不认为Moodle软件是MySQL的沉重用户。当前,只有大约十个老师可以访问它,而当我使用bzip2转储并压缩整个数据库时,生成的转储大小小于1 MB。
我几个月前就建立了系统。 Apache服务器一直保持稳定,但是MySQL崩溃了好几次。我尝试从Web上了解最佳配置,并且上次更改
/etc/my.cnf
文件时,我以MySQL随附的文件/usr/share/doc/mysql55-server-5.5.25/my-large.cnf
为例。该文件说,它用于具有512 MB内存的系统,因此我认为使用与内存相关的配置参数对该系统而言是安全的。 (我之前用较小的数字配置了MySQL的与内存相关的参数,我认为这可能导致崩溃。虽然仍然发生崩溃,但现在系统至少要快一些。)这些是/etc/my.cnf
的当前内容: br /> # /etc/my.cfg
# The main and only MySQL configuration file on [WEBSITE ADDRESS REDACTED].
# Last updated 2012-09-23 by Teemu Leisti.
# Most of the memory settings are set to be the same as the example setting file
# /usr/share/doc/mysql55-server-5.5.25/my-large.cnf, which is meant for systems
# with 512M of memory. This server currently has twice that, i.e. 1G of memory,
# which should make these settings safe.
[client]
default_character_set = utf8
port = 3306
socket = /var/lib/mysql/mysql.sock
[mysqld]
character_set_filesystem = utf8
character_set_server = utf8
datadir = /var/lib/mysql
innodb_additional_mem_pool_size = 20M
innodb_buffer_pool_size = 256M # You can set .._buffer_pool_size up to
# 50..80% of RAM, but beware of setting
# memory usage too high
innodb_data_file_path = ibdata1:10M:autoextend
innodb_data_home_dir = /var/lib/mysql
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_log_buffer_size = 8M
innodb_log_file_size = 64M # Set .._log_file_size to 25% of buffer
# pool size
innodb_log_group_home_dir = /var/lib/mysql
interactive_timeout = 60
key_buffer_size = 256M
long_query_time = 10
max_allowed_packet = 1M
max_connections = 30
port = 3306
query_cache_limit = 2M # see http://emergent.urbanpug.com/?p=61
query_cache_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
skip_networking # Only local processes need to use MySQL
skip_symbolic_links # Disabling symbolic_links is recommended to
# prevent assorted security risks
slow_query_log_file = /var/log/mysql-slow-queries.log
socket = /var/lib/mysql/mysql.sock
sort_buffer_size = 1M
table_open_cache = 256
thread_cache_size = 8
thread_concurrency = 2 # = number of CPUs * 2
user = mysql
wait_timeout = 10
[mysqld_safe]
log_error = /var/log/mysqld.log
open_files_limit = 4096
pid_file = /var/run/mysqld/mysqld.pid
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
如您在配置中看到的,安装程序使用InnoDB引擎,并且仅处理来自本地主机的请求。除了系统管理员(me)外,Moodle是MySQL的唯一用户。有时,我可以通过命令q4312079q重新启动MySQL,但有时该命令将失败,并显示以下输出:
/var/log/mysqld.log
。在这些情况下,我唯一能想到的恢复情况是重启服务器,然后再重启MySQL。在这些情况下,输出如下所示:120926 08:00:51 mysqld_safe Number of processes running now: 0
120926 08:00:51 mysqld_safe mysqld restarted
120926 8:00:53 [Note] Plugin 'FEDERATED' is disabled.
120926 8:00:53 InnoDB: The InnoDB memory heap is disabled
120926 8:00:53 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120926 8:00:53 InnoDB: Compressed tables use zlib 1.2.3
120926 8:00:53 InnoDB: Using Linux native AIO
120926 8:00:53 InnoDB: Initializing buffer pool, size = 256.0M
InnoDB: mmap(274726912 bytes) failed; errno 12
120926 8:00:53 InnoDB: Completed initialization of buffer pool
120926 8:00:53 InnoDB: Fatal error: cannot allocate memory for the buffer pool
120926 8:00:53 [ERROR] Plugin 'InnoDB' init function returned error.
120926 8:00:53 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
120926 8:00:53 [ERROR] Unknown/unsupported storage engine: InnoDB
120926 8:00:53 [ERROR] Aborting
120926 8:00:53 [Note] /usr/libexec/mysqld: Shutdown complete
120926 08:00:53 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
以下是
service mysqld restart
命令当前输出的内容:120926 11:43:48 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120926 11:43:48 [Note] Plugin 'FEDERATED' is disabled.
120926 11:43:48 InnoDB: The InnoDB memory heap is disabled
120926 11:43:48 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120926 11:43:48 InnoDB: Compressed tables use zlib 1.2.3
120926 11:43:48 InnoDB: Using Linux native AIO
120926 11:43:48 InnoDB: Initializing buffer pool, size = 256.0M
120926 11:43:48 InnoDB: Completed initialization of buffer pool
120926 11:43:48 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
120926 11:43:48 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...
120926 11:43:51 InnoDB: Waiting for the background threads to start
120926 11:43:52 InnoDB: 1.1.8 started; log sequence number 466807107
120926 11:43:52 [Note] Event Scheduler: Loaded 0 events
120926 11:43:52 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.25' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Server (GPL)
通常,“免费”列的大小在50到100 MB之间。
命令
mysqld dead but subsys locked
的输出:# free -m
total used free shared buffers cached
Mem: 1024 869 154 0 70 153
-/+ buffers/cache: 644 379
Swap: 0 0 0
我还没有更改了Moodle的任何设置或代码文件,但
free -m
除外(看起来像这样(删除注释行以节省空间)):# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 8192
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 8192
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
(但是,我已经安装了两个Moodle插件,即Attendance模块和模块,但是我看不到它们如何与这个问题有关。)一个星期前,MySQL因上述症状而崩溃了几次。作为数据库管理的初学者,并且在对此问题进行了大量的搜索之后,我对下一步的工作一无所知。有什么建议?我是否应该发布更多配置数据?
编辑上的附加内容:
文件
ulimit -a
的内容为:<?php
unset($CFG); // Ignore this line
global $CFG; // This is necessary here for PHPUnit execution
$CFG = new stdClass();
$CFG->dbtype = 'mysqli'; // 'pgsql', 'mysqli', 'mssql', 'sqlsrv' or 'oci'
$CFG->dblibrary = 'native'; // 'native' only at the moment
$CFG->dbhost = 'localhost'; // eg 'localhost' or 'db.isp.com' or IP
$CFG->dbname = 'moodle'; // database name, eg moodle
$CFG->dbuser = 'moodleuser'; // your database username
$CFG->dbpass = '[REDACTED]'; // your database password
$CFG->prefix = 'moodle_'; // prefix to use for all table names
$CFG->dboptions = array(
'dbpersist' => false, // should persistent database connections be
// used? set to 'false' for the most stable
// setting, 'true' can improve performance
// sometimes
'dbsocket' => true, // should connection via UNIX socket be used?
// if you set it to 'true' or custom path
// here set dbhost to 'localhost',
// (please note mysql is always using socket
// if dbhost is 'localhost' - if you need
// local port connection use '127.0.0.1')
'dbport' => '', // the TCP port number to use when connecting
// to the server. keep empty string for the
// default port
);
$CFG->passwordsaltmain = '[REDACTED]';
$CFG->wwwroot = 'http://[REDACTED]';
$CFG->dataroot = '/var/moodledata';
$CFG->directorypermissions = 02777;
$CFG->admin = 'admin';
date_default_timezone_set('Europe/Helsinki');
$CFG->disableupdatenotifications = true;
require_once(dirname(__FILE__) . '/lib/setup.php'); // Do not edit
,然后在11:42重新启动相关的行。
编辑#2的附加内容:
我试图评论Michael的答案,但我对这个角色不满意评论数量有限,所以我在这里回答。
Michael,谢谢您的回答。我刚刚编辑了问题,以包含崩溃时计算机系统日志的内容。 (CentOS似乎将其系统日志称为
/var/www/html/moodle/config.php
。)是的,MySQL和系统日志看起来都与您链接的问题中的日志几乎相同。现在,您提到它了,很明显
/etc/my.cnf
消息意味着MySQL已经崩溃。系统日志指示是什么原因引起的。在您先前的答案中,您写道:“第一个猜测:apache子进程运行amok。”在我看来,Apache在这里也是显而易见的嫌疑人。 Apache,我的第一句话是,如果可以避免的话,请尝试。Lighttpd和thttpd都是非常不错的Web服务器,并且可以使用PHP运行lighttpd。通过将静态内容(通常是图像和javascript文件)传递到轻量级,超快速的HTTPd服务器(例如Lighttpd),可以提高性能。“ 我正在考虑采纳作者的建议,并已与我的客户达成协议,下周末,我将在服务器上用Lighttpd替换Apache。我希望能解决问题。不可能使用两个虚拟服务器。
我没有想到在同一台计算机上使用两个稳定,成熟的开源服务器(例如MySQL和Apache),并具有合理的内存量,会很麻烦。
#1 楼
请查看我对最近这个问题的回答。我相信情况是相同的。此时不要更改MySQL配置,因为MySQL并不是问题,这只是问题的征兆...这似乎是您有具有少量内存和零交换空间的系统。
您的服务器没有崩溃,因为无法为缓冲池分配内存。您的服务器崩溃了……然后由于系统内存不可用而无法随后重新启动。在mysql启动时,系统会请求为InnoDB缓冲池配置的所有内存。
看到此日志消息时...
120926 08:00:51 mysqld_safe Number of processes running now: 0
...您的服务器已死。如果在此之前未记录任何内容,则不会记录有关第一次崩溃的任何内容。后续的日志来自自动尝试重新启动之后。
如果可能的话,第1步可能是添加一些交换空间和/或分配RAM。
如果不可能,您实际上可以考虑减少innodb配置中的-buffer-pool大小。 (我从没想过我会听到自己这么说)。只要您的数据库很小并且流量很小,您可能就不需要那么大的缓冲池...并且由于InnoDB缓冲池内存在启动时是否全部分配了,是否需要,这将释放您的一些内存。系统的内存,以满足其他需求。 (仅当整个服务器专用于MySQL时,才建议将RAM占总内存的75%至80%设置为true。)
第2步将检查Apache的派生模型,以及您可能需要在配置中进行不同的操作以防止它淹没您的服务器。 Apache子进程的数量或内存需求的不受控制的增长很可能会引发一系列事件,导致内核杀死MySQL,从而试图避免整个服务器完全崩溃。
根据您的灵活性,您甚至可以考虑为Apache和MySQL使用两个单独的虚拟机。