这两天抽时间重做了VPS。这个VPS因为用作个人站点,流量不大,于是当时就买了个很便宜的。(128M内存,XEN虚拟化技术)。
之前的VPS安装了Debian, LNMP做web server,L2TP,FTP,uTorrent For Linux,可谓早已超过负荷。删除了不少东西(服务)后,访问主页(With SSL)竟然要20+s。发Ticket,改驱动,仍然不理想。感觉不爽,不打算一点点优化了,遂备份网站数据后重做系统。
成果当然是有的!
顺便说一句,之前的VPS因为用过putty登陆,尽管我忘了当时用的是不是汉化版,而且貌似还是从Google上搜索到的,但也有sshd等文件被更改的风险。(现在都是控制台下直接ssh过去)
服务器系统仍然是Debian,LNMP,没有什么特别的,手动编译也可以。FTP、phpmyadmin正常安装。
PHP编译参数
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-discard-path –enable-magic-quotes –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-fpm –enable-force-cgi-redirect –enable-mbstring –with-mcrypt –enable-ftp –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –without-pear –with-gettext –with-mime-magic
MYSQL
./configure –prefix=/usr/local/mysql –with-extra-charsets=complex –enable-thread-safe-client –enable-assembler –with-mysqld-ldflags=-all-static –with-charset=utf8 –enable-thread-safe-client –with-big-tables –with-readline –with-ssl –with-embedded-server –enable-local-infile
NGINX
./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-ipv6
基本配置之后进行测试,发现速度并不是很快。在没有SSL的情况下,wordpress页面载入仍然需要10+s。
于是继续安装eaccelerator,小内存上用武之地也是很大的。修改php.ini,注意重启之后php探针应该显示启用了,并且设置的缓存文件夹下确实有文件(前面没有检查,以至于以为运行了,一看日志才发现.so文件路径打错了)。
顺便修改
max_execution_time = 300
max_input_time = 300
之后再次修改了php-fpm配置文件中的max_children,这一项对于小内存VPS不易设置过高。对于我的VPS,明显5就吃不消,于是改成3。
<value name=”max_children”>3</value>
顺便
<value name=”listen_address”>/tmp/php-cgi.sock</value>
<value name=”request_terminate_timeout”>300s</value>
<value name=”max_requests”>10240</value>
针对wordpress的优化,先顺手 OPTIMIZE TABLE 优化了一下数据表(phpmyadmin可)。页面缓存插件采用WP Super Cache,效果不错。
小结:以上设置主要针对内存和脚本执行超时的问题,默认0s可能会导致有效内存利用下降,设置太低php文件上传也可能会受影响。
进程数不易太多,否则性能会受到影响,并发链接处理效率都将下降,nginx进程一个即可,php进程3~4个即可。
以下是测试数据
webbench -t 30s -c 300 http://yuyii.com/
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.Benchmarking: GET http://yuyii.com/
300 clients, running 30 sec.Speed=181564 pages/min, 17534620 bytes/sec.
Requests: 90782 susceed, 0 failed.
gomez的数据
Los Angeles, CA – Verizon
Selected URL: http://yuyii.com
Total Response Time: 0.752
Total Bytes: 145588Selected URL: http://yuyii.com
Selected Node: Beijing China – Dnion
Total Response Time: 3.618
Total Bytes: 145588Selected URL: http://yuyii.com
Selected Node: Tokyo, Japan – NTT
Test Time: 2012-02-01 13:49:44.587
Total Response Time: 1.956
Total Bytes: 145588
这个是wordpress上的
Selected URL: https://airjcy.wordpress.com
Selected Node: Tokyo, Japan – NTT
Total Response Time: 12.546
Total Bytes: 284251 //首页内容似乎有点多,但响应明显长了
本机测试
14 个请求 ❘ 已传输 37.86KB ❘ 1.87秒 (onload: 1.77秒, DOMContentLoaded: 1.24秒)
9 requests ❘ 144.93KB transferred ❘ 3.40s (onload: 3.40s, DOMContentLoaded: 2.15s)
总之比之前好很多了 (ry。不足之处还请各位大神多多指教