在瑞豪开源(RASHOST)128M小内存VPS服务器上架LNMP的配置和优化

原来一直用的国外的虚拟主机,由于IP是共用的,经常自己都访问不了。给生活造成很大的不便,最近
买了VPS(debian 6.0系统),把之前的日志都搬过来了,博客程序也一起升级了下。
该VPS是从瑞豪开源(RASHOST)(http://rashost.com/)购买的,电信、网通访问速度都不错,稳定性也非常好。

由于购买的VPS内存只有128M,做了一些优化,优化后的内存使用效果:
freem.jpg

大小: 9.25 K
尺寸:  x 
浏览: 55 次
点击打开新窗口浏览全图
推荐有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/

 

备注:
瑞豪开源(RASHOST)VPS重新系统也是很容易的,全部是自助式傻瓜操作,赞一个。
自主重装VPS操作系统 http://rashost.com/blog/rebuild-vps-howto

参考网站
http://www.webhostingtalk.com/showthread.php?t=1025286
http://blog.licess.cn/lnmp/
http://blog.s135.com/post/375/
http://www.vpsee.com/2009/06/64mb-vps-optimize-mysql/
lamp.rar (2.33 K, 下载次数:53, 上传时间:2011-10-11 17:18)

Tags: vps

上一篇: apt-cache搜索包过滤   下一篇: LNMP+phpMyAdmin+eAcelerator一键安装包

相关文章

提交疑问

回顶部