我刚刚购买了2GB内存的第一个VPS。 我已经安装了Apache + MySQL和1个主要是静态网站和2个WordPress网站(用于testing)。 起初,我的内存峰值在1GB,这表明它需要进一步的configuration。
Here is the result for running ps -ylC httpd --sort:rss S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD S 0 20729 1 0 80 0 10032 69902 poll_s ? 00:00:00 httpd S 48 20770 20729 0 80 0 22768 73372 inet_c ? 00:00:00 httpd S 48 20735 20729 0 80 0 24020 73897 inet_c ? 00:00:00 httpd S 48 20740 20729 0 80 0 26524 74302 inet_c ? 00:00:00 httpd S 48 20733 20729 0 80 0 27792 74831 inet_c ? 00:00:00 httpd
这里使用命令顶部的结果
top - 15:42:01 up 18 days, 15:45, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 26 total, 1 running, 24 sleeping, 0 stopped, 1 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 2097152k total, 837604k used, 1259548k free, 0k buffers Swap: 4194304k total, 15836k used, 4178468k free, 679184k cached 1 root 20 0 19208 416 292 S 0.0 0.0 0:00.01 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd/179 3 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper/179 491 root 20 0 80300 776 468 S 0.0 0.0 0:18.75 sendmail 540 smmsp 20 0 76024 388 260 S 0.0 0.0 0:00.08 sendmail 556 root 20 0 114m 368 284 S 0.0 0.0 0:02.47 crond 726 root 16 -4 10660 8 4 S 0.0 0.0 0:00.00 udevd 876 root 20 0 64272 8 4 S 0.0 0.0 0:00.00 saslauthd 877 root 20 0 64272 8 4 S 0.0 0.0 0:00.00 saslauthd 908 root 20 0 181m 864 416 S 0.0 0.0 0:00.04 rsyslogd 928 root 20 0 22092 8 4 S 0.0 0.0 0:00.00 xinetd 2100 root 20 0 105m 1180 1176 S 0.0 0.1 0:00.00 mysqld_safe 2189 mysql 20 0 679m 19m 3888 S 0.0 0.9 0:41.22 mysqld 18759 root 20 0 94084 4772 3420 S 0.0 0.2 0:01.03 sshd 18761 root 20 0 105m 1952 1488 S 0.0 0.1 0:00.16 bash 20729 root 20 0 273m 9.8m 5124 S 0.0 0.5 0:00.04 httpd 20733 apache 20 0 292m 27m 4804 S 0.0 1.3 0:00.54 httpd
这里是我在httpd.conf中所做的更改
# KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On # # MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 15 # # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. # KeepAliveTimeout 5
这是我的prefork-MPM设置
# prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare # ServerLimit: maximum value for MaxClients for the lifetime of the server # MaxClients: maximum number of server processes allowed to start # MaxRequestsPerChild: maximum number of requests a server process serves <IfModule prefork.c> StartServers 2 MinSpareServers 3 MaxSpareServers 3 ServerLimit 35 MaxClients 35
我最初只想在这里有MongoDB。 但我正在计划从共享主机移动我的WP安装。 总而言之,我将拥有2-5 wp的站点,1个CodeIgniter Web应用程序(无数据库),2个将来运行MongoDB的fuelphp Web应用程序。
如果可能的话,我喜欢保持最高1.2GB的内存。 任何build议进一步调整在Apache端? 我会看看如果我可以减lessMySQL的足迹。
“如何让我的网站更快”是一个非常复杂的问题,在这个论坛上回答。 但是有一些注意事项:
我做了一些testing后,转向了Nginx。 性能现在好多了(Amazon EC2微型实例,在Java上运行613MB +多重层)。
我想保持Apache,我会build议投资于这些好的书籍之一,例如这一个 。
第一次提高MaxKeepAliveRequests。 MaxKeepAliveRequests数量less导致每次MaxKeepAliveRequests达到时,都会重新启动apache2子项。
第二禁用未使用的Apache模块,像一个LDAPauthentication(如果你不需要它)