Centos 128m小内存VPS 优化

删除垃圾

yum remove Deployment_Guide-en-US finger cups-libs cups bluez-libs desktop-file-utils ppp rp-pppoe wireless-tools irda-utils nfs-utils nfs-utils-lib rdate fetchmail eject ksh mkbootdisk mtools syslinux tcsh startup-notification talk apmd rmt dump setserial portmap yp-tools ypbind

yum remove telnet rsh ftp rcp

更换

yum install postfix
yum remove sendmail
/sbin/chkconfig postfix off

不需要的 xinetd 服务。

/sbin/service xinetd stop; /sbin/chkconfig xinetd off
rm -rf /etc/xinetd.d

Nginx配置

user www www

worker_processes 1;

events {
worker_connections 1024;
use epoll; #使用高效率的epool模式
}

http {
include mime.types;
default_type application/octet-stream;

sendfile on;
keepalive_timeout 65

# 下面是配置缓存
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 32k;
fastcgi_buffers 4 32k;
fastcgi_busy_buffers_size 32k;
fastcgi_temp_file_write_size 32k;

# 下面是弃用gzip压缩缓存
gzip on;
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;

Mysql

[mysql]
no-auto-rehash

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

open_files_limit = 600
back_log = 20
max_connections = 100
max_connect_errors = 200
table_cache = 60
external-locking = FALSE
max_allowed_packet = 16M
sort_buffer_size = 128K
join_buffer_size = 128K
thread_cache_size = 10
thread_concurrency = 8
query_cache_size = 0M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-UNCOMMITTED
tmp_table_size = 512K
max_heap_table_size = 32M
long_query_time = 1
log_long_format
server-id = 1
binlog_cache_size = 2M
max_binlog_cache_size = 4M
max_binlog_size = 512M
expire_logs_days = 7
key_buffer_size = 4M
read_buffer_size = 1M
read_rnd_buffer_size = 2M
bulk_insert_buffer_size = 2M
myisam_sort_buffer_size = 4M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

skip-innodb #禁用innodb数据库引擎

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqldump]
quick
max_allowed_packet = 16M

PHP
listen = /var/run/php-cgi.sock #使用socket监听,不用端口监听
pm.max_children = 2 #默认是50
pm.start_servers = 2 #默认是20
pm.min_spare_servers = 2 #默认是5
pm.max_spare_servers = 2 #默认是35