参考网站:http://www.centos.bz/2012/05/centos-5-yum-mysql-5-5-1/
导入第三方源webtatic
rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
安装MySQL client
yum install libmysqlclient15 --enablerepo=webtatic
删除存在的mysql
yum remove mysql mysql-*
安装mysql
yum install mysql55 mysql55-server --enablerepo=webtatic
yum install mysql51 mysql51-server --enablerepo=webtatic
启动并升级mysql
service mysqld start
mysql_upgrade
同样在此下面安装php5.3:
首先直接用 yum install php 安装原版php 然后再进行升级
相关php 5.3的文件都在:http://repo.webtatic.com/yum/centos/5/i386/
安装参照:http://www.webtatic.com/packages/php53/
yum --enablerepo=webtatic install php
yum --enablerepo=webtatic update php
php 相关安装的很多重要类库:
yum --enablerepo=webtatic install php-bcmath php-dba php-devel php-fpm php-imap php-intl php-mbstring php-mcrypt php-mhash php-odbc php-pdo php-pear php-pecl-apc php-pecl-memcache php-pecl-xdebug php-process php-pspell php-recode php-snmp php-soap php-tidy php-xml php-xmlrpc php-zts
nginx 安装:
通过
yum --enablerepo=webtatic install nginx
service nginx start
cd
/etc/nginx/
nginx 安装完成之后,php使用fastcgi启动需要配置 spawn-fcgi
1.参考网站:http://bbs.linuxtone.org/thread-4908-1-1.html (基于CentOS 5.4搭建nginx+php+spawn-fcgi+mysql高性能php平台)
spawn-fcgi下载地址: 下载地址:http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
#tar zvxf spawn-fcgi-1.6.3.tar.gz
#cd spawn-fcgi-1.6.3
#./configure && make && make install
安装完成后会在 /usr/local/bin/spawn-fcgi
完成之后 使用 ln -s /usr/local/bin/spawn-fcgi /usr/bin/ 创建软链
-----------------------------------------
2.除了使用fastcgi方式 php如果单个程序的话可以直接进行挂载使用以下方法
参考网站:http://www.cnblogs.com/jsckdao/archive/2011/05/05/2038265.html
使用 nohup ./php-cgi -b 9000 直接进行挂载
-----------------------------------------
3.通过nginx配置多个 fastcgi_pass 做负责均衡
参考网站:http://hi.baidu.com/ylj798/item/f8aad0dfd9ee9916e0f46ffc (一个简单的nginx加多个fastcgi的负载均衡配置过程)
先在http段中加入下面一段
upstream fastcgi {
server 127.0.0.1:9000 weight=1;
server 192.168.0.2:9000 weight=2;
}
然后把原来的 fastcgi_pass 127.0.0.1:9000;
改为 fastcgi_pass fastcgi;
重启nginx,看看服务器B的状态,cpu的使用率马上就上来了,而服务器A的cpu使用率和负载都下降了不少。
做这样的负载均衡,不需要什么复杂的配置,不影响原站点的访问。速度快,工作量少。还是有些可取之处的。
------------------------------------------------
4.nginx的配置方式:
nginx 可以在 nginx.conf 中配置
也可以在 conf.d 中虚拟目录中配置:
server { listen 80; server_name test.com; server_name www.test.com; location / { root /var/www/html; index index.html index.htm index.php; } location ~ \.php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; } }
#如果有多个,增加多个php的相关节点
nginx 通过 nginx -t
nginx reload
service nginx start/stop/restart 来进行操作
--------------------------------------------------------------------------------
5.配置自动启动nginx+fastcgi-spwan 的shell脚本:
参考网站:http://club.topsage.com/thread-522550-1-1.html (Nginx、php-cgi启动停止脚本) 主要
http://forum.ubuntu.org.cn/viewtopic.php?t=323830(自启动脚本参考)
为了方便Nginx和php-cgi的启动停止写了一个脚本,将下面脚本保存为/etc/init.d/nginxd,支持
service nginxd start|stop|restart|reload|status
添加了chkconfig和des 就可以使用 chkconfig --add 名称 来添加服务 ,来进行开机指定项的启动~~~~~
这边参考:http://hi.baidu.com/jcy168/item/ba8a141bd29c10436826bb74
#!/bin/sh # nginxd - this script starts and stops the nginx and php-cgi daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginxd # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # source function library . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 RETVAL=0 prog="nginx" nginxDir=/etc/nginx nginxd=/usr/sbin/nginx nginxConf=$nginxDir/nginx.conf nginxPid=$nginxDir/logs/nginx.pid nginx_check() { if [[ -e $nginxPid ]]; then ps aux |grep -v grep |grep -q nginx if (( $? == 0 )); then echo "$prog already running..." exit 1 else rm -rf $nginxPid &> /dev/null fi fi } phpcgi_check() { netstat -tunlp |grep -q php-cgi if (( $? == 0 )); then echo "php-cgi already running..." return 1 fi } phpcgi_start() { phpcgi_check if (( $? == 0 )); then echo -n $"Starting php-cgi:" daemon /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nobody -g nobody -C 64 -f /usr/bin/php-cgi RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/php-cgi return $RETVAL fi } phpcgi_stop() { echo -n $"Stopping php-cgi:" phpcgi_pid=`netstat -tnlp |grep php-cgi |awk '{print $7}' |awk -F'/' '{print $1}'` kill -9 $phpcgi_pid &>/dev/null RETVAL=$? killall -9 php-cgi &>/dev/null RETVAL=$RETVAL+$? if (( $RETVAL == 0 )); then echo_success else echo_failure fi echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/php-cgi } start() { nginx_check if (( $? != 0 )); then true else echo -n $"Starting $prog:" daemon $nginxd -c $nginxConf RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL fi } stop() { echo -n $"Stopping $prog:" killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginxPid } reload() { echo -n $"Reloading $prog:" killproc $nginxd -HUP RETVAL=$? echo } case "$1" in start) phpcgi_start start ;; stop) phpcgi_stop stop ;; restart) phpcgi_stop stop phpcgi_start start ;; reload) reload ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|reload|status}" RETVAL=1 esac exit $RETVAL
改脚本完全可以ok~
---------------------------------------------------
6.另一则 CentOS+nginx+spawn-fcgi+php5.3配置记录
参考网站:http://dev.yidianhulian.com/2011/01/19/how-to-install-php53-on-centos/ (下载源进行安装的过程)
http://dev.yidianhulian.com/2011/03/05/centosnginxspawn-fcgiphp5-3%E9%85%8D%E7%BD%AE%E8%AE%B0%E5%BD%95/ (nginx和fastcgi配置 不错)
7 php-fpm 启动PHP
安装:
yum -y install nginx mysql-server 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
启动:
/etc/rc.d/init.d/php-fpm start
参考网站:
centos 6.4使用yum安装nginx + php + mysql
http://www.openfans.org/forum.php?mod=viewthread&tid=3619