Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。
编译安装可自定义安装目录,解决不必要的软件间依赖,最主要的是编译安装一般是用最新的版本。
系统环境:Centos 7.4 Tengine 2.2.2
安装必要的编译环境
1 |
yum -y install gcc gcc-c++ wget make autoconf automake |
下载pcre zlib openssl Tengine
1 2 3 4 |
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz wget http://www.zlib.net/zlib-1.2.11.tar.gz wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz wget http://tengine.taobao.org/download/tengine-2.2.2.tar.gz |
解压pcre zlib openssl Tengine
1 2 3 4 |
tar -xzvf pcre-8.42.tar.gz tar -xzvf zlib-1.2.11.tar.gz tar -xzvf openssl-1.1.0f.tar.gz tar -xzvf tengine-2.2.2.tar.gz |
创建Tengine运行用户
1 2 3 4 |
#新建www用户组 groupadd www #新建Tengine用户 useradd -g www Tengine -s /sbin/nologin |
编译Tengine
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
./configure \ --prefix=/data/apps/tengine \ //安装目录 --conf-path=/data/apps/conf/tengine/nginx.conf \ //配置文件目录 --lock-path=/dev/shm/nginx.lock \ //loc文件目录 --sbin-path=/data/apps/tengine/sbin/nginx \ //可执行文件目录 --error-log-path=/data/apps/log/tengine/error.log \ //错误日志 --http-log-path=/data/apps/log/tengine/access.log \ //访问日志 --http-client-body-temp-path=/data/apps/temp/tengine/client/ \ --http-proxy-temp-path=/data/apps/temp/tengine/proxy/ \ --http-fastcgi-temp-path=/data/apps/temp/tengine/fcgi/ \ --http-uwsgi-temp-path=/data/apps/temp/tengine/uwsgi/ \ --http-scgi-temp-path=/data/apps/temp/tengine/scgi/ \ --pid-path=/data/apps/temp/tengine/pid/nginx.pid \ //pid目录 --group=www \ //用户组 --user=Tengine \ //运行用户 --with-pcre=/root/pcre-8.42 \ //pcre目录 --with-zlib=/root/zlib-1.2.11 \ //zlib目录 --with-openssl=/root/openssl-1.1.0f \ //openssl目录 --with-http_ssl_module \ --with-http_realip_module \ --with-http_image_filter_module \ --with-http_sub_module \ --with-http_gzip_static_module \ --with-http_secure_link_module \ --with-http_stub_status_module \ --with-http_v2_module \ --with-http_slice_module |
安装
1 |
make && make install |
创建目录 pid目录 log目录 并更改所属用户
1 2 3 |
mkdir -p /data/apps/temp/tengine/pid /data/apps/log/tengine #更改文件夹所属用户为tengine chown -R tengine:www /data/apps/temp/tengine /data/apps/log/tengine data/apps/conf/tengine /data/apps/tengine |
启动tengine
1 |
/data/apps/tengine/sbin/nginx |
直接用IP地址访问 出现以下界面表示安装成功
或者用命令 curl -I http://127.0.0.1 出现HTTP/1.1 200 OK 表示成功
添加服务项 开机启动
创建启动脚本
1 |
vim /etc/rc.d/init.d/nginx |
写入以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#! /bin/bash # chkconfig: - 85 15 PATH=/data/apps/tengine DESC="nginx daemon" NAME=tengine DAEMON=$PATH/sbin/$NAME CONFIGFILE=/data/apps/conf/tengine/$NAME.conf PIDFILE=/data/apps/temp/tengine/pid/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME set -e [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON -c $CONFIGFILE || echo -n "nginx already running" } do_stop() { $DAEMON -s stop || echo -n "nginx not running" } do_reload() { $DAEMON -s reload || echo -n "nginx can't reload" } case "$1" in start) echo -n "Starting $DESC: $NAME" do_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" do_stop echo "." ;; reload|graceful) echo -n "Reloading $DESC configuration..." do_reload echo "." ;; restart) echo -n "Restarting $DESC: $NAME" do_stop do_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;; esac exit 0 |
给脚本添加执行权限
1 |
chmod +x nginx |
添加服务
1 |
chkconfig --add nginx |
加入开机启动
1 |
chkconfig nginx on |
启动、重启、停止命令
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#启动 service nginx start #重启 service nginx restart #重新加载配置文件 service nginx reload #停止 service nginx stop #也可以这样 /data/apps/tengine/sbin/nginx -s stop #停止服务 /data/apps/tengine/sbin/nginx -s quit #退出服务 /data/apps/tengine/sbin/nginx -s reopen #重新打开日志文件 /data/apps/tengine/sbin/nginx -s reload #重新加载配置文件 |