zoukankan      html  css  js  c++  java
  • Tengine安装配置

    为了加快网站的大流量访问速度,公司要求把Nginx更换为Tengine,下面记录下整个安装配置过程:

    #安装必要依赖

    yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel glibc-headers gcc-c++

    #安装google-perftools支持依赖

    wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.98.tar.gz

    tar xf libunwind-0.98.tar.gz

    cd libunwind-0.98

    ./configure && make && make install

    #安装google-perftools

    wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.4/gperftools-2.4.tar.gz

    tar xf gperftools-2.4.tar.gz 

    cd gperftools-2.4

    ./configure  --enable-frame-pointers

    make && make install

    #为google-perftools添加线程目录

    mkdir /tmp/tcmalloc

    chmod 0777 /tmp/tcmalloc

    #下载Tengine最新稳定版本

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

    #解压

    tar xf tengine-2.1.2.tar.gz

    cd tengine-2.1.2

    #修改nginx.h,以隐藏版本信息

    sed -i "12 s/1006002/1000001/g" src/core/nginx.h

    sed -i "13 s/1.6.2/1.0.0/g" src/core/nginx.h

    sed -i "14 s/nginx/webserver/g" src/core/nginx.h

    sed -i "16 s/"Tengine"/"X"/g" src/core/nginx.h

    sed -i "17 s/2001002/2000000/g" src/core/nginx.h

    sed -i "18 s/2.1.2/2.0.0/g" src/core/nginx.h

    sed -i "21 s/"NGINX"/"X"/g" src/core/nginx.h

    sed -i "s//usr/local//usr/local/gacp/gperftools/g" auto/lib/google-perftools/conf

    #添加运行用户

    useradd -s /sbin/nologin  apache

    #创建相应目录

    mkdir -p /usr/local/gacp/nginx
    mkdir -p /data/logs/nginx/{access,error}

    #编译安装

    ./configure
    --user=apache
    --group=users
    --prefix=/usr/local/gacp/nginx
    --error-log-path=/data/logs/nginx/error/error.log
    --http-log-path=/data/logs/nginx/access/access.log
    --pid-path=/usr/local/gacp/nginx/conf/nginx.pid
    --lock-path=/var/lock/nginx.lock
    --with-http_flv_module
    --with-http_stub_status_module
    --with-http_ssl_module
    --with-pcre
    --with-http_realip_module
    --with-http_gzip_static_module
    --with-google_perftools_module
    --with-file-aio
    make
    make install

    #配置文件nginx.conf

    user apache;
    worker_processes 12;
    worker_rlimit_nofile 65535;
    pid conf/nginx.pid;
    google_perftools_profiles /tmp/tcmalloc;

    error_log /data/logs/nginx/error/error.log crit;

    events {
    use epoll;
    worker_connections 20960;
    }

    http {
    include mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for" '
    '$upstream_addr $upstream_response_time $upstream_status';

    access_log off;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    server_tokens off;
    keepalive_timeout 60;

    include gzip.types;
    include server.types;
    include upstream.conf;
    include vhosts.d/*.conf;

    }

    #配置文件gzip.types

    zip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 5;
    gzip_types text/plain application/x-javascript text/css text/xml image/jpeg image/gif image/png;
    gzip_vary on;

    #配置文件server.types

    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;

    server_names_hash_bucket_size 128;
    client_max_body_size 8m;

    open_file_cache max=10240 inactive=60s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;

    proxy_headers_hash_max_size 512;
    proxy_headers_hash_bucket_size 64;

    #配置文件flb_params

    proxy_redirect          off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_next_upstream error timeout invalid_header http_502 http_504;
    client_max_body_size    10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout   300;
    proxy_send_timeout      300;
    proxy_read_timeout      300;
    proxy_buffer_size       64k;
    proxy_buffers           4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    #配置文件upstream.conf

    #负载均衡
    #1、轮询(默认)
    #每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
    #2、weight
    #指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
    #例如:
    #upstream bakend {
    #server 192.168.0.1 weight=10;
    #server 192.168.0.2 weight=10;
    #}
    #3、ip_hash
    #每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器。
    #例如:
    #upstream bakend {
    #ip_hash;
    #server 192.168.0.1:88;
    #server 192.168.0.2:80;
    #}
    #每个设备的状态设置为:
    #1.down 表示单前的server暂时不参与负载
    #2.weight 默认为1.weight越大,负载的权重就越大。
    #3.max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误
    #4.fail_timeout:max_fails次失败后,暂停的时间。
    #5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
    #6.check interval=3000 rise=2 fall=2 timeout=1000 type=http;用于自动判断后端是否可用。
    #####
    upstream web_server
    {
    check interval=3000 rise=2 fall=2 timeout=1000 type=http;
    server 1.1.1.1 max_fails=2 fail_timeout=30s;
    server 2.2.2.2 max_fails=2 fail_timeout=30s;
    ip_hash;
    }

    #配置文件proxy.vipbet.com.conf

    server {
    listen 58080;
    server_name proxy.vipbet.com;
    access_log /data/logs/nginx/access/proxy.vipbet.com.access.log main;
    error_log /data/logs/nginx/error/proxy.vipbet.com.error.log;

    location /
    {
    proxy_pass http://web_server;
    include flb_params;
    }
    }

    #更改目录用户组

    chown -R apache.apache /usr/local/gacp/nginx

    #启动脚本:cat /etc/init.d/nginx

    #!/bin/bash
    #
    # nginx - this script starts and stops the nginx daemon

    #
    # chkconfig: - 85 15
    # description: Nginx is an HTTP(S) server, HTTP(S) reverse
    # proxy and IMAP/POP3 proxy server
    # processname: nginx
    # config: /etc/nginx/nginx.conf
    # config: /etc/sysconfig/nginx
    # pidfile: /var/run/nginx.pid

    # Source function library.
    . /etc/rc.d/init.d/functions

    # Source networking configuration.
    . /etc/sysconfig/network

    # Check that networking is up.
    [ "$NETWORKING" = "no" ] && exit 0

    TENGINE_HOME="/usr/local/gacp/nginx/"

    #这里修改nginx的路径


    nginx=$TENGINE_HOME"sbin/nginx"
    prog=$(basename $nginx)

    NGINX_CONF_FILE=$TENGINE_HOME"conf/nginx.conf"

    [ -f /etc/sysconfig/nginx ] && /etc/sysconfig/nginx

    lockfile=/var/lock/subsys/nginx

    start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    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
    killall -9 nginx
    }

    restart() {
    test || return $?
    stop
    sleep 1
    start
    }

    reload() {
    test || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
    }

    force_reload() {
    restart
    }

    test() {
    $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|test)
    $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|test}"
    exit 2
    esac

    #chmod +x /etc/init.d/nginx

    #service nginx start

    #报错/lib/lsb/init-functions: No such file or directory

    yum install redhat-lsb

    #报错error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory

        查看libprofiler.so.0是否存在:whereis libprofiler.so.0

        libprofiler.so: /usr/local/lib/libprofiler.so /usr/local/lib/libprofiler.so.0

        添加动态库路径: vi /etc/ld.so.conf.d/extend.conf

                                /usr/local/lib

        装载动态库:ldconfig

    #service nginx start

    #####查看nginx进程

    ps aux|grep nginx

    #####查看google_perftools_profiles

     lsof -n | grep tcmalloc

  • 相关阅读:
    [Linux Sets] hosts, wlan and other net-rele
    [Source] 温柔的图片
    [CATARC_2017] 第三周 & 残四周
    [CATARC_2017] 第二周
    ubuntu 安装
    知规矩者混天下言。
    python+selenium的web自动化测试之二(Jenkins自动执行)
    python+selenium的web自动化测试之一(手工执行)
    Python 入门小实例笔记
    Web安全测试工具 Burp Suit 使用简介
  • 原文地址:https://www.cnblogs.com/zhaojonjon/p/5700408.html
Copyright © 2011-2022 走看看