Nginx安装-Tengine(阿里baba的)

Posted chenjian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx安装-Tengine(阿里baba的)相关的知识,希望对你有一定的参考价值。

简介

Tengine是由淘宝网发起的Web服务器项目。它在nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫网等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。

Tengine完全兼容Nginx,因此可以参照Nginx的方式来配置Tengine。


一、获取安装包

wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz

二、安装依赖包

yum install pcre pcre-devel zlib zlib-devel open openssl-devel gcc gcc-c++

三、配置Nginx

   ./configure     --prefix=/usr/local/nginx     --pid-path=/usr/local/nginx/logs/nginx.pid     --error-log-path=/usr/local/logs/error.log     --http-log-path=/usr/local/logs/access.log     --with-http_gzip_static_module     --http-client-body-temp-path=/var/temp/nginx/client     --http-proxy-temp-path=/var/temp/nginx/proxy     --http-fastcgi-temp-path=/var/temp/nginx/fastcgi     --http-uwsgi-temp-path=/var/temp/nginx/uwsgi     --http-scgi-temp-path=/var/temp/nginx/scgi     --prefix=/usr/local/nginx     --pid-path=/usr/local/nginx/logs/nginx.pid     --error-log-path=/usr/local/logs/error.log     --http-log-path=/usr/local/logs/access.log     --with-http_gzip_static_module 部分模块配置安装在/var/temp/nginx,所以事先要在创建/var/temp/nginx目录

 

四、编译&安装

make;make install

五、启动,停止,重新加载配置文件命令

1.启动:直接运行nginx执行文件

[[email protected]]/usr/local/nginx/sbin# ./nginx 
[[email protected]]/usr/local/nginx/sbin# ps -aux|grep nginx
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root      38247  0.0  0.1  46836  1124 ?        Ss   13:40   0:00 nginx: master process ./nginx
nobody    38248  0.0  0.1  47276  1768 ?        S    13:40   0:00 nginx: worker process
root      38251  0.0  0.0 103260   848 pts/1    S+   13:40   0:00 grep nginx

  

启动时可以使用 -c 指定配置文件

[[email protected]]/usr/local/nginx# sbin/nginx -c conf/nginx.conf
[[email protected]]/usr/local/nginx# ps -aux|grep nginx
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root      38450  0.0  0.1  46836  1124 ?        Ss   14:02   0:00 nginx: master process sbin/nginx -c conf/nginx.conf
nobody    38451  0.0  0.1  47276  1768 ?        S    14:02   0:00 nginx: worker process        
root      38453  0.0  0.0 103260   848 pts/1    S+   14:02   0:00 grep nginx

 

2.平缓停止:./nginx -s quit 待当前工作做完再停止

[[email protected]]/usr/local/nginx/sbin# ./nginx -s quit
[[email protected]]/usr/local/nginx/sbin# ps -aux|grep nginx
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root      38258  0.0  0.0 103260   844 pts/1    S+   13:43   0:00 grep nginx

 

3.暴力停止:./nginx -s stop 或者直接 kill nginxPid nginxPid为nginx的进程号,可在nginx/logs/nginx.pid中查看

[[email protected]]/usr/local/nginx/sbin# ./nginx -s stop
[[email protected]]/usr/local/nginx/sbin# ps -aux |grep nginx
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root      38272  0.0  0.0 103260   848 pts/1    S+   13:46   0:00 grep nginx
[[email protected]]/usr/local/nginx/sbin# 
[[email protected]]/usr/local/nginx/logs# ps -aux|grep nginx
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root      38287  0.0  0.1  46836  1124 ?        Ss   13:47   0:00 nginx: master process ../sbin/nginx
nobody    38288  0.0  0.1  47276  1768 ?        S    13:47   0:00 nginx: worker process
root      38294  0.0  0.0 103260   848 pts/1    S+   13:48   0:00 grep nginx
[[email protected]]/usr/local/nginx/logs# kill $(cat nginx.pid)
[[email protected]]/usr/local/nginx/logs# ps -ef|grep nginx
root      38298   2255  0 13:48 pts/1    00:00:00 grep nginx

 

4.重新加载配置

[[email protected]]/usr/local/nginx/sbin# ./nginx -s reload

六、设置开机启动

1. vi /etc/init.d/nginx (输入下面的代码)

#!/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  /var/run/nginx.pid
}
# reload nginx service functions.
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

 

2. 更改执行权限

chmod a+x /etc/init.d/nginx(a+x ==> all user can execute 所有用户可执行)

3.加入到/etc/rc.local中,实现开机自启动

vi /etc/rc.local 
任意行加入:/etc/init.d/nginx start 
保存退出: wq

4.控制台操作方法

[[email protected]]/usr/local/nginx# service nginx start
正在启动 nginx:                                           [确定]
[[email protected]]/usr/local/nginx# service nginx restart
停止 nginx:                                               [确定]
正在启动 nginx:                                           [确定]
[[email protected]]/usr/local/nginx# service nginx reload
重新载入 nginx:                                           [确定]
[[email protected]]/usr/local/nginx# service nginx stop
停止 nginx:                                               [确定]

  

原文链接:http://blog.csdn.net/KingBoyWorld/article/details/62888918

以上是关于Nginx安装-Tengine(阿里baba的)的主要内容,如果未能解决你的问题,请参考以下文章

Nginx/Tengine 服务器安装 SSL 证书

QPS比Nginx提升60%,阿里Tengine负载均衡算法揭秘

技术干货听阿里云CDN安防技术专家金九讲tengine+lua开发

Gateway技术革命 - Tengine开源Dubbo功能

安装nginx后,怎么安装/升级到tengine

Tengine,轻量级Web服务器