编译安装tengine和热升级nginx

一、编译安装tengine

增加一个三方模块,能够统计Nginx中请求的状态信息

1.下载nginx源码包
[root@slb1 ~]# wget https://tengine.taobao.org/download/tengine-2.3.2.tar.gz
2.下载三方模块包
[root@slb1 ~]# wget https://github.com/zls0424/ngx_req_status/archive/master.zip -O ngx_req_status.zip
3.解压到同级目录下
[root@slb1 ~]# tar -xf tengine-2.3.2.tar.gz 

[root@slb1 ~]# unzip ngx_req_status.zip
4.安装环境和依赖包
[root@slb1 ~]# yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++   zlib zlib-devel  patch.x86_64
5.创建用户
[root@slb1 ~]# useradd  nginx
[root@slb1 ~]# passwd nginx
6.创建头文件
[root@slb1 ~]# patch -p1 < ../ngx_req_status-master/write_filter-1.7.11.patch
7.配置
[root@slb1 tengine-2.3.2]# ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream  --add-module=/usr/local/ngx_req_status-master
8.编译
[root@slb1 tengine-2.3.2]# make -j 4
9.安装
[root@slb1 tengine-2.3.2]# make install
10.检测配置文件
[root@slb1 ~]# /usr/local/nginx/sbin/nginx -t

[root@slb1 ~]# mkdir /tmp/nginx
11.启动nginx服务
[root@slb1 ~]# /usr/local/nginx/sbin/nginx
12.修改配置文件
[root@slb1 ~]# vi /etc/nginx/nginx.conf
#在http配置块第一行插入
	req_status_zone server_name $server_name 256k;
    req_status_zone server_addr $server_addr 256k;
    req_status_zone server_url  $server_name$uri 256k;
#在server配置块添加
    req_status server_name server_addr server_url;
    location /req-status {
    req_status_show on;
    }
13.重新加载配置文件
[root@slb1 ~]# /usr/local/nginx/sbin/nginx -s reload
14.nginx状态查看
[root@slb1 ~]# curl slb1/req-status

zone_name       key     max_active      max_bw  traffic requests        active  bandwidt
h
server_addr     172.18.0.6      2        336    24K     8       1        0
server_name     localhost       2        336    24K     8       1        0
server_url      localhost/      1        0       0      3       0        0
server_url      localhost/index.html    1        336    19K     3       0        0
server_url      localhost/nginx-status  1        0       5800   1       0        0
server_url      localhost/req-status    1        0       0      1       1        0

二、tengine热升级

增加一个三方模块,实现对后端的服务器进行主动健康检查

1.下载三方模块包
 [root@slb1 ~]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/mas
2.解压到与nginx源码同级目录
[root@slb1 ~]# unzip master.zip
3.清除之前编译的可执行文件及配置文件
[root@slb1 tengine-2.3.2]# make clean
4.配置
./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream  --add-module=/usr/local/ngx_req_status-master --add-module=/usr/local/nginx_upstream_check_module-master/
5.编译
[root@slb1 tengine-2.3.2]# make -j 4
6.备份原来的nginx
[root@slb1 tengine-2.3.2]# cp /usr/local/nginx/sbin/nginx{,.back}
7.覆盖原来的nginx
[root@slb1 tengine-2.3.2]# cp objs/nginx /usr/local/nginx/sbin/nginx
#失败执行 pkill nginx 重新执行
8.修改配置文件
[root@slb1 tengine-2.3.2]# vi /etc/nginx/nginx.conf
#在http配置块中添加
upstream c1 {
    server 127.0.0.1:80;
    server static:80;
    server phpserver:80;
        check interval=3000 rise=2 fall=5 timeout=1000 type=http;
        check_http_send "HEAD / HTTP/1.0\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
}
#在server配置块添加
    location /status {
        check_status;
        access_log   off;
    }
9.重新加载配置文件
 [root@slb1 tengine-2.3.2]# /usr/local/nginx/sbin/nginx -s reload
10.查看自主检查结果
[root@slb1 tengine-2.3.2]# curl slb1/status?format=json

{"servers": {
  "total": 3,
  "generation": 4,
  "server": [
    {"index": 0, "upstream": "c1", "name": "127.0.0.1:80", "status": "up", "rise": 610, "fall": 0, "type": "http", "port": 0},
    {"index": 1, "upstream": "c1", "name": "172.18.0.2:80", "status": "up", "rise": 137, "fall": 0, "type": "http", "port": 0},
    {"index": 2, "upstream": "c1", "name": "172.18.0.3:80", "status": "up", "rise": 136, "fall": 0, "type": "http", "port": 0}
  ]
}}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值