系统环境:Centos6.4X64
安装方式:yum安装
tengine是由淘宝网发起的Web服务器项目。它在tengine的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。
tengine不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。FastCGI接口在Linux下是socket,(这个socket可以是文件socket,也可以是ip socket)。为了调用CGI程序,还需要一个FastCGI的wrapper(wrapper可以理解为用于启动另一个程序的程序),这个wrapper绑定在某个固定socket上,如端口或者文件socket。当tengine将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接纳到请求,然后派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本并读取返回数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socket传递给tengine;最后,tengine将返回的数据发送给客户端,这就是tengine+FastCGI的整个运作过程。
1.安装MariaDB
由于Oracle进一步对mysql闭源的举措让人难以安心,众多互联网公司纷纷开始寻求MySQL的替代方案。而MariaDB是一个向后兼容、替代MySQL的数据库服务器。它包含所有主要的开源存储引擎。所以建议使用MariaDB
1.先卸载系统中mysql数据库
[root@tengine ~]#yum remove mysql mysql-*
2.配置Mariadb安装源
在 /etc/yum.repos.d/ 下建立 MariaDB.repo,内容如下:
[root@tengine ~]# vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl =http://yum.mariadb.org/10.0.4/centos6-amd64/
gpgkey=http://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
3.使用YUM安装MariaDB
[root@tengine ~]#yum -y install MariaDB-client MariaDB-server MariaDB-devel
4.启动数据库
[root@tengine ~]#service mysql start
5.修改Root的密码
[root@tengine ~]# mysqladmin -uroot password 'password'
2.关闭selinux和设置iptable防火墙
1.关闭selinux
[root@tengine ~]# vi /etc/selinux/config
把SELINUX= enforcing更改为SELINUX=disable
[root@tengine ~]#setenforce 0
2.设置iptable
[root@tengine ~]# vi /etc/sysconfig/iptables
增加
-AINPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
3.添加一个nginx用户
[root@tengine ~]#groupadd nginx
[root@tengine ~]#useradd -s /sbin/nologin -g nginx nginx
4.安装pcre
1.下载pcre
[root@tengine ~]#wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
2.安装pcre用于支持tengine伪静态
[root@tengine ~]#tar -zxvf pcre-8.33.tar.gz
[root@tengine ~]#mkdir /usr/local/pcre
[root@tengine ~]#cd pcre-8.33
[root@tengine pcre-8.33]#./configure --prefix=/usr/local/pcre
[root@tengine pcre-8.33]#make
[root@tengine pcre-8.33]#make install
5.安装tengine
1.下载tengine1.51
[root@tenginepcre-8.33]#cd ~
[root@tengine ~]#yum install openssl openssl-devel
[root@tengine ~]#wget http://tengine.taobao.org/download/tengine-1.5.1.tar.gz
2.安装tengine
[root@tengine ~]#mkdir /usr/local/nginx
[root@tengine ~]#tar -zxvf tengine-1.5.1.tar.gz
[root@tengine ~]#cd tengine-1.5.1
[root@tengine tengine-1.5.1]# ./configure--prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=/root/pcre-8.33
注:--with-pcre=/root/pcre-8.33指向的是源码包解压的路径,而不是安装的路径,否则会报错。
[root@tenginetengine-1.5.1]#make
[root@tenginetengine-1.5.1]#make install
[root@tengine~]#chown nginx.nginx -R /usr/local/nginx/html
[root@tengine~]#chmod 700 -R /usr/local/nginx/html
6.设置tengine服务
[root@tengine ~]# vi /etc/rc.d/init.d/nginx
#!/bin/bash
# Tengine Startup script# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "tengine already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
[root@tengine ~]# chmod 775 /etc/rc.d/init.d/nginx
[root@tengine ~]# chkconfig nginx on
[root@tengine ~]# service nginx start
7.安装PHP及相关组件
1.安装PHP
[root@tengine ~]#yum -y install php
2.安装PHP组件,使PHP支持FastCGI模式
[root@tengine ~]#yum -y install php-mysql php-gd libjpeg* php-imap php-ldap php-odbcphp-pear php-xml php-xmlrpc php-mbstring php-bcmath php-fpm
8.整合Nginx与PHP
[root@tengine ~]#vi /usr/local/nginx/conf/nginx.conf
把第二行注释去掉并把nobody更改为nginx
worker_processes 根据cpu个数进行设置
把71行到77行的注释去掉,并把/scripts替换为/usr/local/nginx/html
注:上面的/usr/local/nginx/html 是我们PHP网站放置的路径
[root@tengine ~]#vi /etc/php-fpm.d/www.conf
把39行和41行的apache更改为nginx
9.下载Discuz测试tengine、php和Mariadb
1.测试tengine
在浏览器输入http://175.102.13.55
2.测试php
[root@tengine ~]#vi /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
在浏览器输入http://175.102.13.55/index.php
3.下载DiscuzX测试Mariadb
[root@tengine~]#wget http://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_SC_UTF8.zip
[root@tengine~]# unzip Discuz_X3.1_SC_UTF8.zip
[root@tengine~]# mv upload/* /usr/local/nginx/html
[root@tengine~]# chown nginx.nginx -R /usr/local/nginx/html