一.Tengine是什么html
Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了不少高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等获得了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。
从2011年12月开始,Tengine成为一个开源项目,Tengine团队在积极地开发和维护着它。Tengine团队的核心成员来自于淘宝、搜狗等互联网企业。Tengine是社区合做的成果,咱们欢迎你们参与其中,贡献本身的力量。nginx
继承Nginx-1.6.2的全部特性,兼容Nginx的配置;c++
动态模块加载(DSO)支持。加入一个模块再也不须要从新编译整个Tengine;web
支持SO_REUSEPORT选项,建连性能提高为官方nginx的三倍;shell
流式上传到HTTP后端服务器或FastCGI服务器,大量减小机器的I/O压力;浏览器
更增强大的负载均衡能力,包括一致性hash模块、会话保持模块,还能够对后端的服务器进行主动健康检查,根据服务器状态自动上线下线,以及动态解析upstream中出现的域名;安全
输入过滤器机制支持。经过使用这种机制Web应用防火墙的编写更为方便;bash
支持设置proxy、memcached、fastcgi、scgi、uwsgi在后端失败时的重试次数服务器
动态脚本语言Lua支持。扩展功能很是高效简单;
支持按指定关键字(域名,url等)收集Tengine运行状态;
自动去除空白字符和注释从而减少页面的体积
自动根据CPU数目设置进程个数和绑定CPU亲缘性;
能够根据访问文件类型设置过时时间;
……
二. 安装 Tengine
2.1 编译环境准备
yum -y install gcc gcc-c++ autoconf automake wget yum -y install zlib zlib-devel openssl openssl-devel pcre-devel pcre gd-devel groupadd nginx useradd -g nginx -s/sbin/nologin -M nginx
zlib:nginx提供gzip模块,须要zlib库支持
openssl:nginx提供ssl功能
pcre:支持地址重写rewrite功能
concat:支持js,CSS的样式文件合并,减小nginx服务器请求连接数
安装jemalloc,优化nginx内存管理
wget http://www.canonware.com/download/jemalloc/jemalloc-4.0.4.tar.bz2 tar xjf jemalloc-4.0.4.tar.bz2 cd jemalloc-4.0.4 ./configure make && make install echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf ldconfig
2.2编译安装
cd /opt/ wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz tar zxvf tengine-2.1.2.tar.gz cd tengine-2.1.2 ./configure \ --user=nginx \ --group=nginx \ --with-jemalloc \ --prefix=/usr/local/nginx \ --with-http_ssl_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-http_concat_module \ --with-pcre \ --with-http_sysguard_module \ --with-http_realip_module \ --with-http_image_filter_module
make
make install
2.3启动Tengine
/usr/local/nginx/sbin/nginx
2.4设置Tengine开机启动
cat >> /etc/init.d/nginx <<EOF #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # 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 "nginx 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 EOF
授予执行权限
chmod +x /etc/init.d/nginx chkconfig nginx --level 345 on
三.测试
3.1 用浏览器访问主机80端口
出现如图所示界面即表示Tengine安装完成!