添加安装源
Centos 默认官方源中没有nginx 和 php-fpm 所以必须添加第三方源,不然就只能自己编译了。
添加[CentALT]源
在/etc/yum.repo.d 目下创建 alt.ru.repo 文件内容如下:
[CentALT] name=CentALT Packages for Enterprise Linux 5 - $basearch baseurl=http://centos.alt.ru/repository/centos/5/$basearch/ enabled=1 gpgcheck=0
|
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
|
rpm -Uvhhttp://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
|
安装 nginx +PHP-FPM +eAccelerator +mysql
yum update yum install nginx php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator
|
配置优化Nginx
修改 /etc/nginx/nginx.conf,下面只列出修改的部分。
#根据CPU 核心processes,VPS下几个核心几个processes,独立服务器可x2 worker_processes 4; #启用epoll worker_rlimit_nofile 51200; events { worker_connections 51200; use epoll; } #参数调整 sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; keepalive_timeout 50; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; #fastcgi优化 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 256k; #开启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;
|
修改/etc/php-fpm.conf 将max_children 调为20
<value name="max_children">20</value>
|
mysql 调整
修改/etc/my.conf [mysqld] 段加入如下指令
skip-network skip-innodb skip-locking skip-bdb key_buffer = 16K max_allowed_packet = 3M thread_stack = 64K thread_cache_size = 8 table_cache = 3 query_cache_limit = 1M query_cache_size = 16M
|
系统内核调整
在/etc/sysctl.conf 加入
net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 300 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.ip_local_port_range = 5000 65000 net.ipv4.tcp_max_tw_buckets = 6000
|
echo “ulimit -SHn 65535” >> /etc/rc.local styctl -p
|
ulimit -SHn 65535 /etc/init.d/nginx start /etc/init.d/php-fpm start /etc/init.d/mysqld start chkconfig nginx on chkconfig php-fpm on chkconfig mysqld on
|