VPS 内存之优化 

最近VPS的内存的确很吃紧,在浏览网站的时候很能看出来.后台升级一个插件居然能导致 php "out of memery" 囧阿,看来不得不有所行动了..

登录vps shell,top 了一下,我靠,509k free.彻底杯具了.

按照内存占用排列,varnishd 以14% 雄踞第一,其后就是10个php-fpm 进程,平均0.8% - 1% 左右,再者就是 mysqld,也很惊人.

一个个来吧,本来我不太喜欢手动指定内存的大小,一般采用默认。

先缓存服务器 varnish,仔细阅读了 varnishd 启动参数手册(http://www.varnish-cache.org/docs/2.1/reference/varnishd.html),不看不知道,看了吓一条.

默认日志文件大小 shmlogsize 居然是500MB,我擦~ 还有默认后置服务器缓存体积居然是磁盘空闲大小的50%,不能这样浪费吧~

经过修改后,生成了适合本人实际情况的启动命令:

/usr/local/sbin/varnishd \
-a :80,:81,:82 \
-f /etc/sysconfig/varnish/varnish/default.vcl \
-i Power_Cache \
-l 10m \
-s file,/tmp/varnish,500m \
-w 1,3 \
-u cache \
-g web


接下来 php-fpm,像我这样的vps,php-fpm 开10个真是太浪费了。5个应该差不多.
修改php-fpm.conf,如下

; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 4
; The desired minimum number of idle server processes.
pm.min_spare_servers = 1
; The desired maximum number of idle server processes.
pm.max_spare_servers = 10


至于mysql,我用的5.5.8 版本默认启用了innodb,而默认的缓冲池居然是几百Mb,这个必须要改,如下

# Uncomment the following if you are using InnoDB tables

# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 16M


这些改好后,重启以上服务.

再看看内存使用情况,

[root@PowerPC ~]# ps -e v |grep -e php -e varnish -e mysql
1693 ? Ss 0:00 0 8989 55434 2996 0.5 php-fpm: master process (/etc/sysconfig/php/php-fpm.conf)

1696 ? S 0:02 4 8989 60814 21572 4.1 php-fpm: pool www

1697 ? S 0:01 3 8989 61034 25276 4.8 php-fpm: pool www

6043 ? S 0:01 1 8989 61282 22080 4.2 php-fpm: pool www

6077 ? S 0:01 1 8989 61234 22264 4.2 php-fpm: pool www

14066 ? Ss 0:00 0 387 85440 924 0.1 varnishd -a :80,:81,:82 -f default.vcl -i Power_Cache -l 10m -s file,/tmp/varnish,500m -w 1,3 -u cache

14067 ? Sl 0:00 3 387 680640 2572 0.4 varnishd -a :80,:81,:82 -f default.vcl -i Power_Cache -l 10m -s file,/tmp/varnish,500m -w 1,3 -u cache

15545 ? S 0:00 0 691 3008 1336 0.2 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql

15816 ? Sl 0:46 17 8747 200940 30464 5.8 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/run/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/run/mysql/PowerPC.err --pid-file=/var/run/mysql/PowerPC.pid --socket=/tmp/mysql.sock --port=3306


再top 一下,
Mem: 524800k total, 418784k used, 106016k free, 0k buffers

情绪稳定.恩~
[ ] ( 2144 次浏览 ) 永久链接 ( 3 / 2495 )

<< <上一页 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 下一页> >>