• Tengine安装(阿里baba的)-Nginx


    在先前的文章中介绍过Tengine,先前只是使用了运维人员配置好的内容,未自己进行过安装配置。周末闲来无事,对于Tengine进行了尝试性的安装。记录下面方便以后再做改进。

    Tengine官网上有个非常简单的教程,中间并未涉及到一些常用的设置,所以仅供参考。一下午为本人的安装步骤及过程。

    1、安装必要的编译环境好

    由于Tengine安装需要使用源代码自行编译,所以在安装前需要安装必要的编译工具:

     

    # yum update
    # yum install gcc gcc-c++ autoconf automake

    2、安装需要的组件

    A、PCRE

    PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx rewrite依赖于PCRE库,所以在安装Tengine前一定要先安装PCRE,最新版本的PCRE可在官网(http://www.pcre.org/)获取。具体安装流程为:

    :

    cd /usr/local/src
    wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
    tar zxvf pcre-8.36.tar.gz
    cd pcre-8.36
    ./configure --prefix=/usr/local/pcre
    make && make install

    附加信息:

    :

    源码的安装一般由3个步骤组成:配置(configure)、编译(make)、安装(make install)。
    Configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./configure –help输出详细的选项列表。其中–prefix选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr /local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr /local/share,比较凌乱。
    如果配置–prefix,如:./configure –prefix=/usr/local/test,可以把所有资源文件放在/usr/local/test的路径中,不会杂乱。
    用了—prefix选项的另一个好处是卸载软件或移植软件。当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。当然要卸载程序,也可以在原来的make目录下用一次make uninstall,但前提是make文件指定过uninstall。

    B、OpenSSL

    OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。,安装OpenSSL(http://www.openssl.org/source/)主要是为了让tengine支持Https的访问请求。具体是否安装看需求。

    复制代码 代码如下:

    cd /usr/local/src
    wget http://www.openssl.org/source/openssl-1.0.2.tar.gz
    tar zxvf openssl-1.0.2.tar.gz
    cd openssl-1.0.2.tar.gz
    ./configure --prefix=/usr/local/openssl
    make && make install

    C、Zlib

    Zlib是提供资料压缩之用的函式库,当Tengine想启用GZIP压缩的时候就需要使用到Zlib(http://www.zlib.net/)。

     

    cd /usr/local/src
    wget http://zlib.net/zlib-1.2.8.tar.gz
    tar zxvf zlib-1.2.8.tar.gz
    cd zlib-1.2.8.tar.gz
    ./configure --prefix=/usr/local/zlib
    make && make install

    D、jemalloc

    jemalloc(http://www.canonware.com/jemalloc/)是一个更好的内存管理工具,使用jemalloc可以更好的优化Tengine的内存管理。

    :

    cd /usr/local/src
    wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
    tar jxvf jemalloc-3.6.0.tar.bz2
    cd jemalloc-3.6.0.tar.bz2
    ./configure --prefix=/usr/local/jemalloc
    make && make install

    3、安装Tengine

    在主要核心的组件安装完毕以后就可以安装Tegine了,最新版本的Tegine可从官网(http://tengine.taobao.org/)获取。
    在编译安装前还需要做的一件事是添加一个专门的用户来执行Tengine。当然你也可以用root(不建议)。

    复制代码 代码如下:

    groupadd www-data
    useradd -s /sbin/nologin -g www-data www-data

    接下来才是进行安装:

     

    cd /usr/local/src
    wget http://tengine.taobao.org/download/tengine-2.1.0.tar.gz
    tar -zxvf tengine-2.1.0.tar.gz
    cd tengine-2.1.0
    ./configure --prefix=/usr/local/nginx
    --user=www-data
    --group=www-data
    --with-pcre=/usr/local/src/pcre-8.36
    --with-openssl=/usr/local/src/openssl-1.0.2
    --with-jemalloc=/usr/local/src/jemalloc-3.6.0
    --with-http_gzip_static_module
    --with-http_realip_module
    --with-http_stub_status_module
    --with-http_concat_module
    --with-zlib=/usr/local/src/zlib-1.2.8
    make && make install

    注意配置的时候 –with-pcre 、–with-openssl、–with-jemalloc、–with-zlib的路径为源文件的路径。

    4、配置Tengine,设置tengine自动启动

     
    #vim /etc/rc.d/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 /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

    保存退出

    复制代码 代码如下:

    chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限
    chkconfig nginx on #设置开机启动
    service nginx restart #启动服务

     

     

     

     

     

     

     

     

     

    //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    简介

    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执行文件

    [root@localhost]/usr/local/nginx/sbin# ./nginx 
    [root@localhost]/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 指定配置文件

    [root@localhost]/usr/local/nginx# sbin/nginx -c conf/nginx.conf
    [root@localhost]/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 待当前工作做完再停止

    [root@localhost]/usr/local/nginx/sbin# ./nginx -s quit
    [root@localhost]/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中查看

    [root@localhost]/usr/local/nginx/sbin# ./nginx -s stop
    [root@localhost]/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
    [root@localhost]/usr/local/nginx/sbin# 
    [root@localhost]/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
    [root@localhost]/usr/local/nginx/logs# kill $(cat nginx.pid)
    [root@localhost]/usr/local/nginx/logs# ps -ef|grep nginx
    root      38298   2255  0 13:48 pts/1    00:00:00 grep nginx
    

     

    4.重新加载配置

    [root@localhost]/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.控制台操作方法

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

      

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

  • 相关阅读:
    排序算法研究
    SqlParameters参数
    winfrom项目
    方法参数中有out和in关键字是什么意思?
    在C#中使用存储过程
    11Book系列多表群操作
    7drf过滤排序分页异常处理
    12RBAC基于角色的访问控制
    5drf路由组件
    8drf自动生成接口文档
  • 原文地址:https://www.cnblogs.com/chenjian/p/7628311.html
Copyright © 2020-2023  润新知