一、编译安装nginx,依赖libevent API
1、安装开发环境
yum groupinstall "Development Libraries" "Development Tools" yum install pcre-devel -y2、添加nginx的用户和组
groupadd -r nginx useradd -r -g nginx -s /bin/false -M nginx3、编译安装libevent
软件包:libevent-2.0.16-stable.tar.gz tar xf libevent-2.0.16-stable.tar.gz cd libevent-2.0.16-stable ./configure make && make install vim /etc/ld.so.conf.d/lib.local.conf /usr/local/lib ldconfig -v | grep libevent4、编译安装nginx
软件包:nginx-1.0.11.tar.gz tar xf nginx-1.0.11.tar.gz cd nginx-1.0.11 ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --with-pcre make && make install5、为nginx添加服务脚本,在/etc/init.d/nginx,并启动
chmod +x /etc/init.d/nginx chkconfig --add nginx service nginx start二、安装编译libiconv、libmcrypt、mhash,让php支持更强的功能
1、编译安装libiconv,将系统语言与用户语言更好的切换,是个库文件
软件包:libiconv-1.13.1.tar.gz
tar xf libiconv-1.13.1.tar.gz cd libiconv-1.13.1 ./configure make && make install2、编译安装libmcrypt,用于实现数据加密解密的库文件
软件包:libmcrypt-2.5.8.tar.gz
tar xf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make && make install ldconfig -v cd libltdl ./configure --with-gmetad --enable-gexec --enable-ltdl-install make && make install ldconfig -v3、编译安装mhash,计算数据hash算法
软件包:mhash-0.9.9.9.tar.bz2
tar xf mhash-0.9.9.9.tar.bz2 cd mhash-0.9.9.9 ./configure make && make install ln -sv /usr/local/lib/libmcrypt* /usr/lib/ ln -sv /usr/local/lib/libmhash.* /usr/lib/三、编译安装memcached
1、软件包:memcached-1.4.10.tar.gz
tar xf memcached-1.4.10.tar.gz cd memcached-1.4.10 ./configure make && make install2、添加memcached的服务脚本
vim /etc/init.d/memcached #!/bin/bash # # Init file for memcached # # chkconfig: - 86 14 # description: Distributed memory caching daemon # # processname: memcached # config: /etc/sysconfig/memcached. /etc/rc.d/init.d/functions
## Default variables
PORT="11211" USER="nobody" MAXCONN="1024" CACHESIZE="64" OPTIONS=""RETVAL=0
prog="/usr/local/bin/memcached" desc="Distributed memory caching" lockfile="/var/lock/subsys/memcached"start() {
echo -n $"Starting $desc (memcached): " daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $lockfile return $RETVAL }stop() {
echo -n $"Shutting down $desc (memcached): " killproc $prog RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $lockfile return $RETVAL }restart() {
stop start }reload() {
echo -n $"Reloading $desc ($prog): " killproc $prog -HUP RETVAL=$? echo return $RETVAL }case "$1" in
start) start ;; stop) stop ;; restart) restart ;; condrestart) [ -e $lockfile ] && restart RETVAL=$? ;; reload) reload ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=1 esacexit $RETVAL
3、chmod +x /etc/init.d/memcached
chkconfig --add memcached service memcached start netstat -tnlp查看是否有11211的端口四、编译安装MySQL
软件包:mysql-5.5.19-linux2.6-i686.tar.gz
tar xf mysql-5.5.19-linux2.6-i686.tar.gz -C /usr/local
groupadd -r -g 306 mysql useradd -r -g mysql -u 306 -s /sbin/nologin -M mysql cd /usr/local ln -sv mysql-5.5.19-linux2.6-i686 mysql cd mysql chown -R mysql:mysql . scripts/mysql_install_db --user=mysql chown -R root . 把data作为数据目录 chown -R mysql data/添加服务,并导出库
cd support-files/ cp my-large.cnf /etc/my.cnf cp mysql.server /etc/init.d/mysqld chkconfig --add mysqld service mysqld start vim /etc/ld.so.conf.d/mysqld.conf /usr/local/mysql/lib ldconfig -v创建头文件连接,添加PATH变量
ln -sv /usr/local/mysql/include /usr/include/mysql vim /etc/profile PATH=$PATH:/usr/local/mysql/bin . /etc/profile 用mysql连接看是否成功五、编译安装php
软件包:php-5.3.6.tar.bz2
tar xf php-5.3.6.tar.bz2
cd php-5.3.6 ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-iconv-dir=/usr/local make ZEND_EXTRA_LIBS='-liconv' make install启动fastcgi
cp php.ini-production /usr/local/php/etc/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf启用以下的选项(;表注释)
vim /usr/local/php/etc/php-fpm.conf pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35启用php-fpm
/usr/local/php/sbin/php-fpm netstat -tnlp查看是否有9000端口六、让nginx能利用fastcgi的功能
vim /etc/nginx/nginx.conf
启用location ~ \.php$ { root /web/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param ts$fastcgi_script_name; include fastcgi_params; } 添加支持php格式的网页 location / { root /web/html; index index.html index.php index.htm; }vim /etc/nginx/fastcgi_params
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的测试网页,测试是否成功
mkdir /web/html -pv vim /web/html/index.php <?php phpinfo(); ?>service nginx restart
在客户端测试看是否能打开测试也
七、安装编译配置memcache
软件包:memcache-2.2.5.tgz
tar xf 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 --enable-memcache make && make installcp /usr/local/php/etc/php.ini /usr/local/php/lib/php.ini
在“动态模块”相关的位置添加如下一行来载入memcache扩展
vim /usr/local/php/lib/php.ini extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so添加测试页面,对memcached功能测试
vim /web/html/test.php <?php $mem = new Memcache; $mem->connect("127.0.0.1", 11211); $mem->set('mykey', 'Hello World', 0, 600); $val = $mem->get('mykey'); echo "$val is from memcached."; ?>killall php-fpm
/usr/local/php/sbin/php-fpm service nginx restart在客户端测试:
如果有输出“Hello World is from memcached.”,则表明memcache已经能够正常工作。八、编译安装libmemcached
使用libmemcached的客户端工具:
软件包:libmemcached-1.0.2.tar.gz
tar xf libmemcached-1.0.2.tar.gz cd libmemcached-1.0.2 ./configure make && make install ldconfig客户端工具:
memcat --servers=127.0.0.1:11211 mykey 远程管理工具 memping测试服务器是否在线 memslap对服务器做压力测试 memstat服务器的命中率,缓存的条目等 该工具都可以使用--servers九、安装编译配置xcache,加速php(操作码)
软件包:xcache-1.3.2.tar.gz
tar xf xcache-1.3.2.tar.gz cd xcache-1.3.2 /usr/local/php/bin/phpize ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config make && make install安装结束时,会出现类似如下几行
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/cat xcache.ini >> /usr/local/php/lib/php.ini
编辑/usr/local/php/lib/php.ini,添加如下几行
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so zend_extension ts = /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xcache.so用ab压力测试验证下效果