一、安装所需软件包 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl
一、安装所需软件包
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
二、安装扩展库
1、下载libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
下载完成后
tar -zxvf libiconv-1.14.tar.gz && cd libiconv-1.14
./configure --prefix=/usr/local
make && make install
2、安装libmcrypt
wget http://downloads.sourceforge.net/project/mcrypt/libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?r=http://sourceforge.net/projects/mcrypt/files/libmcrypt/2.5.8/&ts=1304912647&use_mirror=nchc
下载完成后
tar -zxvf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8
./configure && make && make install
/sbin/ldconfig && cd libltdl
./configure --enable-ltdl-install
make && make install
3、安装mhash
wget http://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gz
完成后
tar -zxvf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9
./configure && make && make install
4、软链接
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
5、安装mcrypt
wget http://vps.googlecode.com/files/mcrypt-2.6.8.tar.gz
现在完成后tar -zxvf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8/
./configure && make && make install
三、安装mysql
wget http://downloads.skysql.com/archives/mysql-5.5/mysql-5.5.25.tar.gz
tar -zxvf mysql-5.5.25.tar.gz
cd mysql-5.5.25
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql -m -s /sbin/nologin mysql
为防止出现下面的报错:
could not find curses (missing: curses_library curses_include_path)
cmake error at cmake/readline.cmake:83 (message):
curses library not found. please install appropriate package,
remove cmakecache.txt and rerun cmake.on debian/ubuntu, package name is libncurses5-dev, on redhat and derivates it is ncurses-devel.
首先安装:
yum -y install ncurses-devel
cmake -dcmake_install_prefix=/your_path/mysql/ \
-dmysql_datadir=/yourpath/mysqldata/ \
-dsysconfdir=/etc/mysqld/ \
-ddefault_charset=utf8\
-dextra_charsets=all\
-ddefault_collation=utf8_general_ci\
-dwith_extra_charsets:string=utf8,gbk,all\
-dwith_myisam_storage_engine=1\
-dwith_innobase_storage_engine=1\
-dwith_archive_storage_engine=1\
-dwith_memory_storage_engine=1\
-dwith_blackhole_storage_engine=1 \
-dwith_federated_storage_engine=1 \
-dwith_partition_storage_engine=1 \
-dwith_perfschema_storage_engine=1\
-dwith_readline=1\
-denabled_local_infile=1\
-dmysql_user=mysql\
-dmysql_tcp_port=3306\
-dmysql_unix_addr=/yourpath/mysql/run/mysql.sock
make && make install
chmod +w /usr/local/mysql/
chown -r mysql.mysql /usr/local/mysql/
cd ..
/your_install_path/mysql/bin/mysql_install_db --basedir=/your_path/mysql --datadir=/your_path/data --user=mysql
cp ./support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chmod u+x /etc/init.d/mysqld
vi /etc/init.d/mysqld
basedir=
datadir=
更改为:
basedir=/your_path/mysql
datadir=/your_path/data
conf=/etc/my.cnf
更改为:
conf=/your_conf_path/my.cnf
vi /usr/local/mysql/my.cnf
#增加以下内容
[client]
character-set-server = utf8
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = false
max_allowed_packet = 32m
sort_buffer_size = 1m
join_buffer_size = 1m
thread_cache_size = 300
#thread_concurrency = 8
query_cache_size = 512m
query_cache_limit = 2m
query_cache_min_res_unit = 2k
default-storage-engine = myisam
thread_stack = 192k
transaction_isolation = read-committed
tmp_table_size = 246m
max_heap_table_size = 246m
long_query_time = 3
log-slave-updates
log-bin = /data0/mysql/3306/binlog/binlog
binlog_cache_size = 4m
binlog_format = mixed
max_binlog_cache_size = 8m
max_binlog_size = 1g
relay-log-index = /data0/mysql/3306/relaylog/relaylog
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256m
read_buffer_size = 1m
read_buffer_size = 1m
read_rnd_buffer_size = 16m
bulk_insert_buffer_size = 64m
myisam_sort_buffer_size = 128m
myisam_max_sort_file_size = 10g
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#master-host = 192.168.1.2
#master-user = username
#master-password = password
#master-port = 3306
server-id = 1
innodb_additional_mem_pool_size = 16m
innodb_buffer_pool_size = 512m
innodb_data_file_path = ibdata1:256m:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16m
innodb_log_file_size = 128m
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
#log-slow-queries = /data0/mysql/3306/slow.log
#long_query_time = 10
[mysqldump]
quick
max_allowed_packet = 32m
启动mysql
service mysqld start
四、安装php及扩展
1、安装php
64位操作系统先拷贝一下ldap,执行以下命令:
cp /usr/lib64/libldap* /usr/lib/
tar jxvf php-5.3.14.tar.bz2 && cd cd php-5.3.14
./configure --prefix=/usr/local/php \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-mhash \
--enable-sockets \
--enable-ftp \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization --with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--enable-fpm \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear
make zend_extra_libs='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini
2、安装php扩展模块
wget http://vps.googlecode.com/files/memcache-2.2.5.tgz
tar zxvf memcache-2.2.5.tgz && cd memcache-2.2.5
/usr/local/php/bin/phpize
./configure - --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../
wget http://acelnmp.googlecode.com/files/eaccelerator-0.9.6.1.tar.bz2
tar jxvf eaccelerator-0.9.6.1.tar.bz2 && cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../
wget http://vps.googlecode.com/files/pdo_mysql-1.0.2.tgz
tar zxvf pdo_mysql-1.0.2.tgz && cd pdo_mysql-1.0.2
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make && make install
cd ../
#先安装perl-cpan,为防止出现以下错误:
yum -y install yum -y install perl-cpan
错误如下:
perl /usr/lib/perl5 /usr/share/perl5 .) at makefile.pl line 24.
begin failed--compilation aborted at makefile.pl line 24.
make[1]: *** [perlmagick/makefile] 错误 2
make[1]: leaving directory `/data0/software/imagemagick-6.5.1-2'
make: *** [all] 错误 2
wget ftp://ftp.imagemagick.org/pub/imagemagick/imagemagick.tar.gz
tar zxvf imagemagick.tar.gz && cd imagemagick-6.5.1-2
./configure
make && make install
cd ../
wget http://pecl.php.net/get/imagick-3.1.0rc2.tgz
tar zxvf imagick-3.1.0.tgz && cd imagick-3.1.0
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd ../
3、修改php.ini文件
sed -i 's#extension_dir = ./#extension_dir = /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/\nextension = memcache.so\nextension = pdo_mysql.so\nextension = imagick.so\n#' /usr/local/php/etc/php.ini
sed -i 's#output_buffering = off#output_buffering = on#' /usr/local/php/etc/php.ini
sed -i s#; always_populate_raw_post_data = on#always_populate_raw_post_data = on#g /usr/local/php/etc/php.ini
sed -i s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g /usr/local/php/etc/php.ini
4、配置eaccelerator加速
mkdir /your/path/
vi /usr/local/php/etc/php.ini
在最后增加以下内容:
[eaccelerator]
zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so
eaccelerator.shm_size=64
eaccelerator.cache_dir=/data0/mysql/3306/eaccelerator_cache
eaccelerator.enable=1
eaccelerator.optimizer=1
eaccelerator.check_mtime=1
eaccelerator.debug=0
eaccelerator.filter=
eaccelerator.shm_max=0
eaccelerator.shm_ttl=3600
eaccelerator.shm_prune_period=3600
eaccelerator.shm_only=0
eaccelerator.compress=1
eaccelerator.compress_level=9
5、创建用户及组和虚拟目录
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir /data0/www/html -p
chmod +w /data0/www/html/ && chown www.www /data0/www/html/ -r
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
去掉下面的注释
pm.max_children = 64
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 1024
user = www
group = www
测试
/usr/local/php/sbin/php-fpm -t
如出现以下就代表成功
notice: configuration file /usr/local/php/etc/php-fpm.conf test is successful
启动
/usr/local/php/sbin/php-fpm &
五、安装nginx
1、安装pcre
wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.tar.gz
tar zxvf pcre-8.10.tar.gz && cd pcre-8.10
./configure
make && make install
cd ..
wget http://nginx.org/download/nginx-0.8.46.tar.gz
tar zxvf nginx-0.8.46.tar.gz && cd nginx-0.8.46
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../
创建日志存放目录
mkdir /data0/logs
chmod +w /data0/logs/ && chown www.www /data0/logs/
vi /usr/local/nginx/conf/nginx.conf
#增加以下内容
user www www;
worker_processes 8;
error_log /data0/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
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;
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;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80;
server_name test.com;
index index.html index.htm index.php;
root /data0/www/html;
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
log_format access '$remote_addr - $remote_user [$time_local] $request '
'$status $body_bytes_sent $http_referer '
'$http_user_agent $http_x_forwarded_for';
access_log /data0/logs/access.log access;
}
server
{
listen 80;
server_name status.test.com;
location / {
stub_status on;
access_log off;
}
}
}
vi /usr/local/nginx/conf/fcgi.conf
fastcgi_param gateway_interface cgi/1.1;
fastcgi_param server_software nginx;
fastcgi_param query_string $query_string;
fastcgi_param request_method $request_method;
fastcgi_param content_type $content_type;
fastcgi_param content_length $content_length;
fastcgi_param script_filename $document_root$fastcgi_script_name;
fastcgi_param script_name $fastcgi_script_name;
fastcgi_param request_uri $request_uri;
fastcgi_param document_uri $document_uri;
fastcgi_param document_root $document_root;
fastcgi_param server_protocol $server_protocol;
fastcgi_param remote_addr $remote_addr;
fastcgi_param remote_port $remote_port;
fastcgi_param server_addr $server_addr;
fastcgi_param server_port $server_port;
fastcgi_param server_name $server_name;
# php only, required if php was built with --enable-force-cgi-redirect
fastcgi_param redirect_status 200;
启动nginx
/usr/local/nginx/sbin/nginx
添加到自启动
/usr/local/nginx/sbin/nginx
/usr/local/php/sbin/php-fpm
六、优化内核
vi /etc/sysctl.conf
#################################################################
#
#优化内核参数
#
#################################################################
# 增加以下:
##每个网络接口接收数据包的速率比内核处理这些包的速度快时,允许送到队列的数据包的最大数目;
net.core.netdev_max_backlog = 32768
#web应用中linten函数的backlog默认会给我们内核参数的net.core.somaxconn限制到128,而nginx定义的
#ngx_listen_backlog默认为511,所以有必要调整这个值;
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
#时间戳可以避免序列号的卷绕.一个1gbps的链路肯定会遇到以前用过的序列号.时间戳能够让内核接受这种异常
#的数据包.这里需要将其关掉.
net.ipv4.tcp_timestamps = 0
#为了打开对端的连接,内核需要发送一个syn并附带一个回应前面一个syn的ack,也就是三次握手中的第二次握手
#,这个设置决定了内核放弃连接之前发送syn+ack包的数量;
net.ipv4.tcp_synack_retries = 2
#在内核放弃建立之前发送syn包数量;
net.ipv4.tcp_syn_retries = 2
#当出现syn等待队列溢出时,启用cookies来处理,可防范少量syn攻击,默认为0,表示关闭;
net.ipv4.tcp_syncookies = 1
#开启tcp连接中time_wait scokets的快速回收,默认为0,表示关闭;
net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
#允许time-wait sockets重新用于新的tcp连接,默认为0,表示关闭;
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
#系统默认的timeout时间;
#net.ipv4.tcp_fin_timeout = 30
#当keeplive起用的时候,tcp发送keeplive消息的频度.缺省2小时,可以更改为2分钟;
#net.ipv4.tcp_keepalive_time = 1200
#表示用于向外连接的端口范围,缺省32768--61000,改为1024--65000
net.ipv4.ip_local_port_range = 1024 65535
#表示syn队列的长度,默认1024,加大到65536,可容纳更多等待连接的网络连接数;
net.ipv4.tcp_max_syn_backlog = 65536
#系统同时保持time_wait的最大数量,如果超过这个数字,time_wait将立刻被清除并打印警告信息,
#默认180000,现更改为5000,对于apache、nginx等服务器,上几行的参数可以很好地减少time_wait套接字数量,但
#对于squid,效果却不大.此项参数可以控制time_wait的最大数量,避免squid服务器被大量的time_
#wait拖死;
net.ipv4.tcp_max_tw_buckets = 5000
vi /etc/security/limits.conf
#增加以下内容
* soft nofile 65536
* hard nofile 65536