build议为Apache / MySQL设置

我有一个专用的服务器,有1GB内存服务于一些WordPress站点,但是当执行一些testing时(ab:apache benmark,-n 100 -c 10),服务器开始交换,然后就像是死去。 ..

所以,我的问题是,如何调整Apache和MySQL为此目的? 我在php5中使用Apache的mpm_worker

任何关于调整apache.conf和my.cnf文件的build议?

编辑:我试图收集更多的数据发布在这里,但作为我的服务器继续死于交换,我会发布whatevery我现在:

apache2.conf

<IfModule mpm_worker_module> StartServers 2 MinSpareThreads 20 MaxSpareThreads 50 ThreadLimit 64 ThreadsPerChild 25 MaxClients 75 MaxRequestsPerChild 0 </IfModule> 

my.cnf(在[mysqld]中)

 key_buffer_size = 32M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 join_buffer_size = 128K myisam-recover = BACKUP max_connections = 120 table_cache = 128 max_heap_table_size = 32M tmp_table_size = 32M table_open_cache = 128 query_cache_limit = 1M query_cache_size = 16M log_slow_queries = /var/log/mysql/mysql-slow.log long_query_time = 2 log_queries_not_using_indexes = 1 expire_logs_days = 10 max_binlog_size = 100M 

ps aux –sort -pcpu,-rss | 头-30

 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND www-data 11558 13.0 1.9 173280 20112 ? R 13:59 0:00 /usr/lib/cgi-bin/php5 www-data 11529 14.0 3.6 190352 37192 ? R 13:59 0:00 /usr/lib/cgi-bin/php5 www-data 11528 14.0 3.7 190784 37628 ? R 13:59 0:00 /usr/lib/cgi-bin/php5 www-data 11526 16.5 3.9 192836 39580 ? R 13:59 0:00 /usr/lib/cgi-bin/php5 svn 1909 4.2 0.3 91780 3628 ? S 12:49 3:01 /usr/bin/svnserve --daemon --foreground -T -r /home/svn mysql 7780 1.1 6.4 263812 64816 pts/1 Sl 13:43 0:11 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 root 856 1.1 0.0 0 0 ? D 12:48 0:49 [md3_resync] root 325 0.5 0.0 0 0 ? S 12:48 0:22 [md3_raid1] www-data 1731 0.3 1.1 449516 11232 ? Sl 12:49 0:13 /usr/sbin/apache2 -k start www-data 1732 0.2 1.0 383548 10408 ? Sl 12:49 0:12 /usr/sbin/apache2 -k start bind 1244 0.0 1.0 125576 11096 ? Ssl 12:48 0:02 /usr/sbin/named -u bind root 1235 0.0 0.0 3864 300 ? SNs 12:48 0:02 /usr/sbin/powernowd -q postgres 1420 0.0 0.6 105560 6764 ? S 12:48 0:01 /usr/lib/postgresql/8.4/bin/postgres -D /var/lib/postgresql/8.4/main -c config_file=/etc/postgresql/8.4/main/postgresql.conf danikaze 5068 0.0 0.4 24512 4112 pts/1 Ss 13:17 0:00 -bash root 1 0.0 0.0 8356 788 ? Ss 12:48 0:00 init [2] root 1143 0.0 0.2 41148 2636 ? Sl 12:48 0:00 /usr/sbin/monit -c /etc/monit/monitrc -s /var/lib/monit/monit.state danikaze 2778 0.0 0.4 24632 4216 pts/0 Ss 12:49 0:00 -bash postgres 1535 0.0 0.2 105668 2860 ? Ss 12:49 0:00 postgres: writer process root 56 0.0 0.0 0 0 ? S 12:48 0:00 [kswapd0] danikaze 2777 0.0 0.1 70496 1816 ? S 12:49 0:00 sshd: danikaze@pts/0 postgres 1536 0.0 0.1 105560 1584 ? Ss 12:49 0:00 postgres: wal writer process root 2529 0.0 0.0 0 0 ? S 12:49 0:00 [flush-253:2] root 1627 0.0 0.5 90628 5360 ? Ss 12:49 0:00 /usr/sbin/apache2 -k start root 1689 0.0 0.0 16780 804 ? S 12:49 0:00 /usr/sbin/rotatelogs -l /home/***.com.log.%Y-%m-%d 86400 postgres 1538 0.0 0.1 77108 1516 ? Ss 12:49 0:00 postgres: stats collector process root 968 0.0 0.0 0 0 ? S 12:48 0:00 [flush-253:1] root 7639 0.0 0.1 13940 1484 pts/1 S 13:43 0:00 /bin/sh/usr/bin/mysqld_safe ntp 1237 0.0 0.2 38340 2148 ? Ss 12:48 0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 105:106 

免费-m

  total used free shared buffers cached Mem: 986 769 216 0 37 532 -/+ buffers/cache: 199 787 Swap: 3827 0 3827 

我将尝试在服务器交换时再次获取数据,但我不知道这个原因,即使我用ab强调服务器,只有我得到的东西是使用CPU和MEM,但现在没有交换我已经安装了caching对于WordPress的…仍然我得到的服务器交换和挂在一些时刻: – /

其他的事情:服务器基本上使用apache + mysql,即使还有svnserver,proftpd和pgsql,它们几乎没有用过。

由于您使用的是mpm_worker,我强烈推荐使用php5-fpm over mod_php。

另外,即使是一个稍微忙碌的WordPress站点,1GB也不会运行很多内存。 如果可能的话,你当然应该增加你的RAM,因为这样可以提供最好的性能提升。 随着更多的内存,你可以确保你的MySQL索引caching,使用APC等

运行MySQL Tuning Primer脚本还将有助于为您的MySQL设置良好的基本configuration,以确保您不会浪费宝贵的资源。

还要考虑在/etc/sysctl.conf中设置vm.swappiness = 10或20,以防止发生早期交换。