zoukankan      html  css  js  c++  java
  • nginx源码安装添加模块和秒级升级

    nginx源码安装添加模块和秒级升级

    nginx源码安装

    # nginx -V 检查nginx的安装模板
    configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
    # 停止nginx的服务
    [root@lb01 ~]# systemctl stop nginx
    # 删除yum安装的nginx
    [root@lb01 ~]# yum remove nginx
    # 进人nginx的官网,nginx.org,下载nginx-1.14.2版本
    [root@lb01 ~]# # wget http://nginx.org/download/nginx-1.14.2.tar.gz
    [root@lb01 ~]# echo $?
    0
    # 下载nginx的第三方模块
    [root@lb01 nginx-1.14.2]#  wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
    # 下载nginx打补丁模块
    [root@lb01 ~]# yum install -y patch
    #下载nginx的依赖
    [root@lb01 ~]#  yum install -y openssl-devel patch
    # 解压nginx
    [root@lb01 ~]#  tar xf nginx-1.14.2.tar.gz
    
    # 解压master.zip
    [root@lb01 ~]# unzip master.zip 
    # 进入nginx目录打补丁
    [root@lb01 ~]# cd nginx-1.14.2/
    [root@lb01 nginx-1.14.2]# patch -p1 < /root/nginx_upstream_check_module-master/check_1.14.0+.patch 
    
    # 生成 ./configure
    [root@lb01 nginx-1.14.2]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/root/nginx_upstream_check_module-master --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
    #  编译和安装
    [root@lb01 nginx-1.14.2]# make && make install
    # 编辑nginx.conf配置文件
    [root@lb01 nginx]# vim nginx.conf
    user  www; 修改用户
    
     include conf.d/*.conf; 添加include
     # 编辑nginx的自定义配置文件,添加模块
    upstream blog {
            server 172.16.1.7;
            server 172.16.1.8;
            server 172.16.1.9;
            check interval=3000 rise=2 fall=3 timeout=1000 type=tcp;
    }
    server {
            listen  80;
            server_name blog.test.com;
            location / {
                    proxy_pass http://blog;
                               include proxy_params;
            }
            location /uc {
                    check_status;
             }
    }
    # 启动nginx
    [root@lb01 nginx]# nginx
    # 检测语法
    [root@lb01 nginx]# nginx -t
    
    #域名解析
    
    

    # 另外两个配置文件也加上检查模块
    [root@lb01 conf.d]# vim zh.wzh.com.conf
    
    upstream zh {
            server 172.16.1.7 down;
            server 172.16.1.8;
            server 172.16.1.9;
             check interval=3000 rise=2 fall=3 timeout=1000 type=tcp;
    
    }
    server {
            listen  80;
            server_name zh.test.com;
            location / {
                    proxy_pass http://zh;
                    include proxy_params;
            }
             location /uc {
                    check_status;
             }
    
    }
    [root@lb01 conf.d]# vim phpmyadmin.com.conf 
    
    upstream phpmyadmin {
            server 172.16.1.7:80;
            server 172.16.1.8:80;
            check interval=3000 rise=2 fall=3 timeout=1000 type=tcp;
    }
    
    server {
            listen  80;
            server_name phpmyadmin.com;
            location / {
                    proxy_pass http://phpmyadmin;
                               include proxy_params;
            }
             location /uc {
                    check_status;
            }
    }
    # 检测语法
    
    

    # 检查模块的好处就是可以清楚的看到哪台服务器的nginx出问题,方便及时处理
    

    nginx源码安装,添加模块和升级

    # 安装nginx的依赖
    [root@web01 ~]# yum install -y pcre-devel openssl-devel zlib-devel patch
    # 下载nginx的源码包
    [root@web01 ~]#  wget http://nginx.org/download/nginx-1.14.2.tar.gz
    # 解压
    [root@web01 ~]# tar xf nginx-1.14.2.tar.gz
    # 生成
    [root@web01 nginx-1.14.2]# ./configure --prefix=/app/nginx-1.14.2 --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
    
    # 编译和安装
    [root@lb01 nginx-1.14.2]# make && make install
    # 做软链接
    [root@web01 app]# ln -s /app/nginx-1.14.2 /app/nginx
    [root@web01 app]# ll
    total 0
    lrwxrwxrwx 1 root root 17 May 29 05:24 nginx -> /app/nginx-1.14.2
    drwxr-xr-x 6 root root 54 May 29 05:23 nginx-1.14.2
    
    # 创建用户组和用户
    [root@web01 app]# groupadd www -g 666
    [root@web01 app]# useradd www -u 666 -g 666 -s /sbin/nologin -M
    # 修改nginx主配置文件
    [root@web01 app]# vim /app/nginx/conf/nginx.conf
    user  www; 修改用户
    
     include /app/nginx/conf.d/*.conf; 添加include
     # 创建目录
    [root@web01 app]# mkdir /app/nginx/conf.d
    # 添加环境变量
    [root@web01 ~]# vim /etc/profile.d/nginx.sh
    [root@web01 ~]# source /etc/profile
    [root@web01 ~]# cat /etc/profile.d/nginx.sh 
    export PATH="/app/nginx/sbin:$PATH"
    # 编辑配置文件
    [root@web01 app]# cat /app/nginx/conf.d/wzh.conf 
    server {
    	listen 80;
    	server_name wzh.com;
    
    	location / {
    		root html/zh;
    		index index.html;
    	}
    }
    # 创建站点目录并写入内容
    [root@web01 ~]# cd /app/nginx
    [root@web01 nginx]# mkdir html/zh
    [root@web01 nginx]# echo 123 > html/zh/index.html
    # 检测语法
    [root@web01 nginx]# nginx -t
    # 启动nginx
    [root@web01 nginx]# nginx
    # 域名解析
    
    
    

    添加模块

    # 记录以安装模块
    [root@web01 nginx]# nginx -V
    
    --prefix=/app/nginx-1.14.2 --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
    #添加新模块
    --prefix=/app/nginx-1.14.2_new --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module
    
    
    # 进入nginx源码包目录
    [root@web01 ~]# cd nginx-1.14.2
    # 生成
    [root@web01 nginx-1.14.2]# ./configure --prefix=/app/nginx-1.14.2_new --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module
    
    # 编译和安装
    [root@web01 nginx-1.14.2]# make && make install
    # 拷贝配置文件
    [root@web01 app]# cp /app/nginx-1.14.2/conf/nginx.conf /app/nginx-1.14.2_new/conf/nginx.conf
    [root@web01 app]# mkdir /app/nginx-1.14.2_new/conf.d
    [root@web01 app]# cp /app/nginx-1.14.2/conf.d/wzh.conf /app/nginx-1.14.2_new/conf.d/
    
    # 拷贝pid文件
    [root@web01 app]# cp -a /app/nginx-1.14.2/logs/nginx.pid /app/nginx-1.14.2_new/logs/
    # 拷贝站点目录
    [root@web01 app]# cp -a /app/nginx-1.14.2/html/* /app/nginx-1.14.2_new/html/
    [root@web01 app]# cp -a /app/nginx-1.14.2/html/* /app/nginx-1.14.2_new/html/
    # 删除原有软连接做新连接
    [root@web01 app]# rm -f /app/nginx && ln -s /app/nginx-1.14.2_new/ /app/nginx
    # 编辑nginx的配置文件
    [root@web01 app]# vim nginx/conf.d/wzh.conf 
    
    server {
            listen 80;
            server_name wzh.com;
    
            location / {
                    root html/zh;
                    index index.html;
            }
            location = /zh {
                    stub_status;
    
            }
    }
    # 检查语法
    [root@web01 app]# nginx -t
    # 重新加载nginx
    [root@web01 app]# nginx -s reload
    # 访问浏览器
    

    nginx秒级升级

    # 保存原有的模块
    configure arguments: --prefix=/app/nginx-1.14.2_new --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module
    # 去nginx官网下载新版本nginx(nginx.org)
    [root@web01 ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
    
    # 解压
    [root@web01 ~]# tar xf nginx-1.16.1.tar.gz
    # 生成
    [root@web01 ~]# cd nginx-1.16.1
    [root@web01 nginx-1.16.1]# ./configure  --prefix=/app/nginx-1.16.1_new --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module
    # 编译安装
    [root@web01 nginx-1.14.2]# make && make install
    #拷贝配置文件
    [root@web01 nginx-1.16.1]# cp /app/nginx-1.14.2_new/conf/nginx.conf /app/nginx-1.16.1_new/conf/
    [root@web01 nginx-1.16.1]# mkdir /app/nginx-1.16.1_new/conf.d
    [root@web01 nginx-1.16.1]# cp /app/nginx-1.14.2_new/conf.d/* /app/nginx-1.16.1_new/conf.d/
    # 拷贝pid文件
    [root@web01 nginx-1.16.1]# cp /app/nginx-1.14.2_new/logs/nginx.pid /app/nginx-1.16.1_new/logs/
    
    # 拷贝站点目录
    [root@web01 nginx-1.16.1]# cp -a /app/nginx-1.14.2_new/html/* /app/nginx-1.16.1_new/html/
    
    # 秒级升级
    [root@web01 nginx-1.16.1]# rm -rf /app/nginx && ln -s /app/nginx-1.16.1_new /app/nginx
    [root@web01 nginx-1.16.1]# cd /nginx && ll
    -bash: cd: /nginx: No such file or directory
    [root@web01 nginx-1.16.1]# cd /app && ll
    total 0
    lrwxrwxrwx  1 root root  21 May 29 07:21 nginx -> /app/nginx-1.16.1_new
    # 检测语法
    [root@web01 app]# nginx -t
    # 秒级重启
    [root@web01 app]# nginx -s stop && nginx
    
    

    添加检查模块

    # 下载
    [root@web01 ~]# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
    # 解压
    [root@web01 ~]# unzip master.zip
    # 安装依赖
    [root@web01 ~]# yum install -y openssl-devel patch
    # 进入nginx目录打补丁
    [root@web01 ~]# cd nginx-1.16.1/
    [root@web01 nginx-1.16.1]#  patch -p1 < /root/nginx_upstream_check_module-master/check_1.14.0+.patch 
    # 生成添加检查模块
    [root@web01 nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1_new1 --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module --add-module=/root/nginx_upstream_check_module-master
    
    
    # 编译并安装
    [root@web01 nginx-1.16.1]# make && make install
    # 创建目录
    [root@web01 app]# mkdir /app/nginx-1.16.1_new1/conf.d
    
    # 拷贝配置文件
    [root@web01 app]# cp /app/nginx-1.16.1_new/conf/nginx.conf /app/nginx-1.16.1_new1/conf/
    [root@web01 app]# cp /app/nginx-1.16.1_new/conf.d/wzh.conf /app/nginx-1.16.1_new1/conf.d/
    
    # 拷贝pid文件
    [root@web01 app]# cp /app/nginx-1.16.1_new/logs/nginx.pid /app/nginx-1.16.1_new1/logs/
    
    # 拷贝站点目录
    [root@web01 app]# cp -a /app/nginx-1.16.1_new/html/* /app/nginx-1.16.1_new1/html/
    
    # 编辑配置文件
    upstream hh {
            server 172.16.1.7;
             check interval=3000 rise=2 fall=3 timeout=1000 type=tcp;
    }
    server {
            listen 80;
            server_name wzh.com;
            location / {
                    root html/zh;
                    index index.html;
            }
            location = /zh {
                    stub_status;
    
            }
             location /hh {
                    check_status;
    
            }
    }
    
    
    # 检查语法
    [root@web01 app]# nginx -t
    # 做软链接
    [root@web01 app]# rm  -rf /app/nginx && ln -s /app/nginx-1.16.1_new1 /app/nginx
    [root@web01 app]# ll
    total 0
    lrwxrwxrwx  1 root root  22 May 29 08:40 nginx -> /app/nginx-1.16.1_new1
    
    # 重新加载nginx
    [root@web01 app]# nginx -s reload
    # 浏览器访问
    
    

    # 检查参数详解
    upstream web {
        server 172.16.1.7:80 max_fails=2 fail_timeout=10s;
        server 172.16.1.8:80 max_fails=2 fail_timeout=10s;
        check interval=3000 rise=2 fall=3 timeout=1000 type=tcp;
        #interval  检测间隔时间,单位为毫秒
        #rise      表示请求2次正常,标记此后端的状态为up
        #fall      表示请求3次失败,标记此后端的状态为down
        #type      类型为tcp
        #timeout   超时时间,单位为毫秒
    }
    
  • 相关阅读:
    114. Flatten Binary Tree to Linked List 把二叉树变成链表
    426. Convert Binary Search Tree to Sorted Doubly Linked List把bst变成双向链表
    微服务之如何建模微服务
    我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=3t37r4hauhq8c
    剑指offer之面试题2:实现Singleton模式
    微服务之演化式架构师(二)
    ASP.NET Core 框架本质学习
    java之maven之maven的使用
    java之maven之初识maven
    java之mybatis整合spring
  • 原文地址:https://www.cnblogs.com/zabcd/p/13367047.html
Copyright © 2011-2022 走看看