• nginx平滑升级


    #平滑升级

    kill -USR2

     //查看nginx版本
     
    
    1. [root@l1 logs]# nginx -v //查看nginx版本

    2. nginx version: nginx/1.26.0

    3. [root@l1 logs]#

    安装一个1.25版本实验一下 
     
    
    1. [root@l2 ~]# cd /opt/

    2. [root@l2 opt]#

    1. [root@l2 opt]# ls
    2. nginx-1.25.5.tar.gz nginx-1.26.0.tar.gz rh
    进行初始化配置 
    1. [root@l2 opt]# systemctl disable --now firewalld.service
    2. Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
    3. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    4. [root@l2 opt]# setenforce 0
    5. [root@l2 opt]# vim /etc/selinux/config
    安装软件包 
    1. [root@l2 opt]# df
    2. 文件系统 1K-块 已用 可用 已用% 挂载点
    3. devtmpfs 1913548 0 1913548 0% /dev
    4. tmpfs 1930628 0 1930628 0% /dev/shm
    5. tmpfs 1930628 12528 1918100 1% /run
    6. tmpfs 1930628 0 1930628 0% /sys/fs/cgroup
    7. /dev/mapper/centos-root 38770180 5714188 33055992 15% /
    8. /dev/sda1 1038336 191100 847236 19% /boot
    9. tmpfs 386128 12 386116 1% /run/user/42
    10. tmpfs 386128 0 386128 0% /run/user/0
    11. [root@l2 opt]# mount /dev/sr0 /mnt
    12. mount: /dev/sr0 写保护,将以只读方式挂载
    13. [root@l2 opt]# yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make
    14. //安装软件包 
    创建用户  
    [root@l2 opt]# useradd -M -s /sbin/nolongin nginx
     编译安装Nginx
    1. [root@l2 opt]# cd /opt/
    2. [root@l2 opt]# ls
    3. nginx-1.25.5.tar.gz nginx-1.26.0.tar.gz rh
    4. [root@l2 opt]# tar xf nginx-1.25.5.tar.gz //解压
    5. [root@l2 opt]# cd nginx-1.25.5/
    6. [root@l2 nginx-1.25.5]#
    1. ./configure \
    2. --prefix=/usr/local/nginx \
    3. --user=nginx \
    4. --group=nginx \
    5. --with-http_stub_status_module

     

    1. [root@l2 nginx-1.25.5]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
    2. //指定安装路径,指定运行用户,运行组 ,开启模块,htps协议
    [root@l2 nginx-1.25.5]# make && make install
    
     设置软链接,可以直接调用nginx命令来进行管理
    1. [root@l2 nginx-1.25.5]# cd /usr/local/nginx/
    2. [root@l2 nginx]# ls sbin/
    3. nginx
    4. [root@l2 nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
    5. [root@l2 nginx]#
    6. [root@l2 nginx]# /usr/local/nginx/sbin/nginx //运行
    7. [root@l2 nginx]#
    8. [root@l2 nginx]# cd /usr/lib/systemd/system
    9. [root@l2 system]# vim nginx.service
    10. [root@l2 system]#
    11. [Unit]
    12. Description=nginx
    13. After=network.target
    14. [Service]
    15. Type=forking
    16. PIDFile=/usr/local/nginx/logs/nginx.pid
    17. ExecStart=/usr/local/nginx/sbin/nginx
    18. ExecReload=/bin/kill -s HUP $MAINPID
    19. ExecStop=/bin/kill -s QUIT $MAINPID
    20. PrivateTmp=true
    21. [Install]
    22. WantedBy=multi-user.target
    23. [root@l2 system]# chmod 754 /lib/systemd/system/nginx.service
    24. [root@l2 system]#

    启动nginx服务 ​​​​​​​

    1. /usr/local/nginx/sbin/nginx
    2. netstat -lntp | grep 80
     查看pid进程号
    1. [root@l2 ~]# cat /usr/local/nginx/logs/nginx.pid

    2. 14039

    3. [root@l2 ~]#

    查看版本 
    1. [root@l2 ~]# nginx -v
    2. nginx version: nginx/1.25.5
    1. [root@l2 ~]# netstat -lntp | grep 80
    2. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14039/nginx: master
    3. //已在运行

    升级

    新版本升级:
    tar -zxvf nginx-1.xx.xx.tar.gz 
    cd nginx-1.xx.xx
    ./configure \
    --prefix=/usr/local/nginx \
    --user=nginx \
    --group=nginx \
    --with-http_stub_status_module
    --with-http_ssl_module 

    1. [root@l2 ~]# cd /opt/
    2. [root@l2 opt]# ls
    3. nginx-1.25.5 nginx-1.25.5.tar.gz nginx-1.26.0.tar.gz rh
    4. [root@l2 opt]# tar xf nginx-1.26.0.tar.gz
    5. [root@l2 opt]#
    6. [root@l2 opt]# ls
    7. nginx-1.25.5 nginx-1.26.0 rh
    8. nginx-1.25.5.tar.gz nginx-1.26.0.tar.gz
    9. [root@l2 opt]# cd nginx-1.26.0/
    10. [root@l2 nginx-1.26.0]#
    1. [root@l2 nginx-1.26.0]# ls
    2. auto CHANGES.ru configure html man src
    3. CHANGES conf contrib LICENSE README
    4. [root@l2 nginx-1.26.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
    5. //做配置
    1. [root@l2 nginx-1.26.0]# make -j 2
    2. //进行编译

    ​​​​​​​

    nginx文件做个替换
    1. [root@l2 objs]# cd /usr/local/nginx/sbin/
    2. [root@l2 sbin]# ls
    3. nginx
    4. [root@l2 sbin]# mv nginx nginx_old //做个备份
    5. [root@l2 sbin]#
    6. [root@l2 sbin]# cp /opt/nginx-1.26.0/objs/nginx ./
    7. [root@l2 sbin]# ls
    8. nginx nginx_old
    9. [root@l2 sbin]#
    10. [root@l2 sbin]# cd /opt/nginx-1.26.0/
    11. [root@l2 nginx-1.26.0]# ls
    12. auto CHANGES.ru configure html Makefile objs src
    13. CHANGES conf contrib LICENSE man README
    14. [root@l2 nginx-1.26.0]#
     升级
    1. [root@l2 sbin]# cd /opt/nginx-1.26.0/
    2. [root@l2 nginx-1.26.0]# ls
    3. auto CHANGES.ru configure html Makefile objs src
    4. CHANGES conf contrib LICENSE man README
    5. [root@l2 nginx-1.26.0]# make upgrade //升级
    6. /usr/local/nginx/sbin/nginx -t
    7. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    8. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    9. kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
    10. sleep 1
    11. test -f /usr/local/nginx/logs/nginx.pid.oldbin
    12. kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
    13. [root@l2 nginx-1.26.0]#

    查看版本
    1. [root@l2 nginx-1.26.0]# nginx -v
    2. nginx version: nginx/1.26.0
    3. [root@l2 nginx-1.26.0]#
    4. [root@l2 nginx-1.26.0]# nginx -V
    5. nginx version: nginx/1.26.0
    6. built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
    7. built with OpenSSL 1.0.2k-fips 26 Jan 2017
    8. TLS SNI support enabled
    9. configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
    10. [root@l2 nginx-1.26.0]#

    •  注:
    • mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old
    •  cp objs/nginx /usr/local/nginx/sbin/nginx
    • make upgrade  #要保证当前 nginx 进程是通过 /usr/local/nginx/sbin/nginx 启动的,而不是通过查找环境变量中那个 nginx 命令启动的
    • #或者先 killall nginx ,再/usr/local/nginx/sbin/nginx
  • 相关阅读:
    代码随想录笔记_动态规划_494目标和
    Go 学习笔记(88) — 字符串拼接方法和性能、字符串组成、UTF-8 编码方案、字符串之间转换
    第八章 Linux实际操作——定时任务调度
    Python数据和Json数据的相互转换
    Socket 编程
    MySQL-性能优化
    HPA (Horizontal Pod Autoscaler) In K8s
    Netty入门指南之NIO Selector监管
    2024年腾讯云部署幻兽帕鲁服务器,如何选择合适的服务器配置套餐畅玩游戏?
    湖北大学2024年成人高考函授报名高起专大数据与会计专业介绍
  • 原文地址:https://blog.csdn.net/2401_83331026/article/details/139435192