• Tengine 是nginx的加强版,封装版,淘宝开源
– 官网http://tengine.taobao.org/
– 动态模块加载(DSO)支持。加入一个模块不再需要重新编译整个Tengine;
– 支持SO_REUSEPORT选项,建连性能提升为官方nginx的三倍;
– 支持SPDY v3协议,自动检测同一端口的SPDY请求和HTTP请求;
– 流式上传到HTTP后端服务器或FastCGI服务器,大量减少机器的I/O压力;
– 更加强大的负载均衡能力,包括一致性hash模块、会话保持模块,还可以对后端的服务器进行主动健康检查,根据服务器状态自动上线下线,以及动态解析upstream中出现的域名;
– 输入过滤器机制支持。通过使用这种机制Web应用防火墙的编写更为方便;
– 支持设置proxy、memcached、fastcgi、scgi、uwsgi在后端失败时的重试次数
– 动态脚本语言Lua支持。扩展功能非常高效简单;
– 支持管道(pipe)和syslog(本地和远端)形式的日志以及日志抽样;
– 支持按指定关键字(域名,url等)收集Tengine运行状态;
– 组合多个CSS、JavaScript文件的访问请求变成一个请求;
– 自动去除空白字符和注释从而减小页面的体积
安装之前准备
• • • • • • •
1、依赖 gcc openssl-devel pcre-devel zlib-devel
# yum install gcc openssl-devel pcre-devel zlib-devel
2、创建用户和用户组。为了方便nginx运行而不影响linux安全
创建组:# groupadd -r nginx
创建用户:# useradd -r -g nginx -M nginx
-M 表示不创建用户的家目录
下面介绍3种安装方式
简洁方式:
# ./configure --prefix=/usr/tengine
# make && make install
自定义方式1(非root用户下运行,即nginx用户,建议使用这套):
./configure\
--prefix=/usr/nginx\
--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/\
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\
--http-scgi-temp-path=/var/tmp/nginx/scgi\
--with-pcre
自定义方式2(root用户下运行):
./configure\
--prefix=/opt/soft/tengine-2.1.0/\
--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\
--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/\
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\
--http-scgi-temp-path=/var/tmp/nginx/scgi\
--with-pcre
完成了以上方式,下一步就添加安装的tengine到注册表,进入到/etc/init.d目录里
# cd /etc/init.d
在/etc/init.d目录下新建nginx文件
# vi nginx
在nginx文件拷贝以下内容全部,注意nginx的安装路径
#!/bin/bash
#
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/nginx/conf/nginx.conf"
#[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
#make_dirs() {
# # make required directories
# user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
# options=`$nginx -V 2>&1 | grep 'configure arguments:'`
# for opt in $options; do
# if [ `echo $opt | grep '.*-temp-path'` ]; then
# value=`echo $opt | cut -d "=" -f 2`
# if [ ! -d "$value" ]; then
# # echo "creating" $value
# mkdir -p $value && chown -R $user $value
# fi
# fi
# done
#}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
# make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
# -HUP是nginx平滑重启参数
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
下一步修改nginx文件的执行权限 :
# chmod +x nginx
添加该文件到系统服务中去
# chkconfig --add nginx
查看是否添加成功
# chkconfig --list nginx
开启时启动nginx
# chkconfig nginx on
启动,停止,重新装载(start|stop|reload),示例:
# service nginx start
如若出现“/var/tmp/nginx/client/ ”目录不存在,则创建即可:
# mkdir -p /var/tmp/nginx/client/