构建高性能Web环境(linux/nginx/mysql/php-fastcgi)

  开始之前先介绍一下nginx

Nginx(engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,最初供俄国大型的入口网站及搜寻引擎Rambler(俄文:Рамблер)使用。  其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页伺服器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯,另外知名的微网志Plurk也使用nginx。

下面开始叙述详细配置过程:

一、Centos系统安装完毕之后,关闭不需要的服务优化系统,安装系统更新和所需软件支持。

关闭不需要的服务

chkconfig --level 3 acpid off
chkconfig --level 3 anacron off
chkconfig --level 3 apmd off
chkconfig --level 3 mdmonitor off
chkconfig --level 3 xinetd off
chkconfig --level 3 sendmail off
chkconfig --level 3 rpcgssd off
chkconfig --level 3 rawdevices off
chkconfig --level 3 messagebus off
chkconfig --level 3 atd off
chkconfig --level 3 gpm off
chkconfig --level 3 autofs off
chkconfig --level 3 cpuspeed off
chkconfig --level 3 haldaemon off
chkconfig --level 3 nfslock off
chkconfig --level 3 portmap off
chkconfig --level 3 xfs off
chkconfig --level 3 netfs off
chkconfig --level 3 smartd off
chkconfig --level 3 ip6tables off
chkconfig --level 3 isdn off
chkconfig --level 3 rpcidmapd off
chkconfig --level 3 microcode_ctl offservice acpid stop
service anacron stop
service apmd stop
service mdmonitor stop
service xinetd stop
service sendmail stop
service rpcgssd stop
service rawdevices stop
service messagebus stop
service atd stop
service gpm stop
service autofs stop
service cpuspeed stop
service haldaemon stop
service nfslock stop
service portmap stop
service xfs stop
service netfs stop
service smartd stop
service ip6tables stop
service isdn stop
service rpcidmapd stop
service microcode_ctl stop

安装系统更新和所需软件支持

yum -y update
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 ntp rar

下载需要用到的软件包(以下地址都是官方下载、也可以自己查找)

【下载PHP需要的库】

wget
wget
wget
wget

【下载mysqlphp、nginx】

wget
wget
wget
wget
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz

【下载php扩展】

wget
wget
wget
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.7.0-8.tar.gz
wget

二、安装PHP需要的库程序

tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/ && ./configure --prefix=http://down.chinaz.com/usr/local
make && make install && cd ..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 && cd ../..tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/ && ./configure
make && make install && cd ..ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-configtar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/ && /sbin/ldconfig
./configure && make && make install && cd ..

三、编译安装 MySQL

tar zxvf mysql-5.1.57.tar.gz && cd mysql-5.1.57
./configure --prefix=http://down.chinaz.com/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile
make && make install && cd ..

创建mysql用户组,创建数据库、日志等存储目录并赋予权限

mkdir -p /data/mysqldata
mkdir -p /data/mysqldata/database
mkdir -p /data/mysqldata/log
mkdir -p /data/mysqldata/pid
groupadd mysql
useradd -g mysql -d /data/mysqldata/database -s /sbin/nologin mysql
chgrp -R mysql /usr/local/webserver/mysql/.
chown -R root:mysql /usr/local/webserver/mysql/*
chown -R mysql:mysql /data/mysqldata/*

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/10999.html