买了VPS(debian 6.0系统),把之前的日志都搬过来了,博客程序也一起升级了下。
由于购买的VPS内存只有128M,做了一些优化,优化后的内存使用效果:
推荐有Money的购买更大内存的VPS
一、增加256M的swap交换文件
1、创建并激活swap交换文件
cd /var/
dd if=/dev/zero of=swapfile bs=1024 count=262144
/sbin/mkswap swapfile
/sbin/swapon swapfile
2、加到fstab文件中让系统引导时自动启动
echo /var/swapfile swap swap defaults 0 0 >> /etc/fstab
二、系统默认为美国东部时间,修改Linux时区为东八区
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
三、安装lnmp环境
echo deb http://packages.dotdeb.org stable all >> /etc/apt/sources.list
wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | apt-key add -
apt-get update
apt-get install php5 php5-fpm php5-common php5-mcrypt php5-mysql php5-cli php5-gd
apt-get install nginx
apt-get install mysql-server
四、优化内存使用
1、PHP (FastCGI)的配置优化
cat /etc/php5/fpm/pool.d/www.conf |grep -v ';'
[www]
listen = /tmp/php-fcgi.sock
user = www-data
group = www-data
pm = dynamic
pm.max_children = 25
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 10
request_terminate_timeout = 30s
chdir = /
/etc/init.d/php5-fpm restart
2、Nginx的主配置文件(nginx.conf)优化
cat /etc/nginx/nginx.conf |grep -v '#'
user www-data;
#Nginx每个进程耗费10M~12M内存,这里只开启一个Nginx进程,节省内存。
worker_processes 1;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;
events {
use epoll;
#值不要太大
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
types_hash_max_size 2048;
#增加的优化
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 20M;
client_body_buffer_size 128k;
include /etc/nginx/mime.types;
default_type application/octet-stream;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
#对网页文件、CSS、JS、XML等启动gzip压缩,减少数据传输量,提高访问速度。
gzip on;
gzip_disable "msie6";
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
3、优化Mysql配置
cat /etc/mysql/my.cnf |grep -v '#'
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
skip-external-locking
#优化开始
skip-bdb
skip-innodb
skip-networking
server-id = 1
key_buffer = 256K
max_allowed_packet=1M
thread_stack = 64K
thread_cache_size = 8
table_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
query_cache_limit=256K
query_cache_size = 2M
max_connections = 16
thread_concurrency = 5
#优化结束
bind-address = 127.0.0.1
myisam-recover = BACKUP
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 16M
!includedir /etc/mysql/conf.d/