nginx-平滑升级

》》
》》

在服务器运行时,如果我们要升级Nginx的版本,是不是要把Nginx 服务停掉呢,但是停掉服务,对生产环境老说损失挺大的,我们要学习一下平滑升级。

Nginx 平滑升级

可以在不间断服务器的前提表进行版本的升级,叫作平滑升级(热升级)

热数据: 经常描写缓存层的数据,一直在被改写的数据

热升级前提:

1)确保有更新版本的Nginx服务器

2)确保有nginx旧版本

3)确保Nginx在运行中

平滑升级

  • 解压更高版本包
[root@localhost ~]# tar -zxf nginx-1.11.1.tar.gz -C /usr/src/
  • 编译配置
[root@localhost ~]# cd /usr/src/nginx-1.11.1/

[root@localhost nginx-1.11.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module 
  • 直接make 不需要make install
[root@localhost nginx-1.11.1]# make 
  • 将原有的nginx启动脚本移动至其他位置
[root@localhost nginx-1.11.1]# mv /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx_old
  • NGinx源码目录中 objs/nginx启动脚本复制到指定位置(
[root@localhost nginx-1.11.1]# cp /usr/src/nginx-1.11.1/objs/nginx /usr/local/nginx/sbin/
  • 查看logs下nginx.pid 文件后 将原有的pid文件的进程干掉
[root@localhost nginx-1.11.1]# ls /usr/local/nginx/logs/

access.log  error.log  nginx.pid

[root@localhost nginx-1.11.1]# cat /usr/local/nginx/logs/nginx.pid 

5526
[root@localhost nginx-1.11.1]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`

[root@localhost nginx-1.11.1]# cat /usr/local/nginx/logs/nginx.pid
21411
  • 实现pid无缝升级
[root@localhost nginx-1.11.1]# nginx -v

nginx version: nginx/1.11.1

编写nginx启动脚本的目的

1)将nginx放入/etc/init.d/下,可以将nginx服务添加至服务项中,使用systemctl进行管理

2)方便nginx的使用,将nginx进行更直观的操作,start | stop | restart

# $0 表示为第一个参数

# $1 表示为第二个参数

[root@localhost ~]# vim /etc/init.d/nginx

#! /bin/bash

#welcome to user my nginx

#chkconfig: 2345 55 23

PROG="/usr/local/nginx/sbin/nginx"

PIDF="/usr/local/nginx/logs/nginx.pid"

case "$1" in

​        start)$PROGecho "nginx start>>>>>>"

;;

​        stop)kill -s QUIT $( cat $PIDF)echo " nginx closed>>>>>>>>"

;;

​        restart)$0 stop

​                $0 start

;;

​        reload)kill -s HUHP $( cat $PIDF)echo "nginx already reload"

;;

​        *)echo "please usage $0 { start  |  stop  |  restart  | reload }"exit 1

esac

exit 0
  • 添加至系统服务并赋予 脚本执行权限
[root@localhost ~]# chkconfig --add nginx

[root@localhost ~]# chmod 755 /etc/init.d/nginx	
  • 启动服务
[root@localhost ~]# /etc/init.d/nginx start

nginx start>>>>>>

[root@localhost ~]# netstat -anpt | grep 80

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      21747/nginx: master 
  • 关闭服务
[root@localhost ~]# /etc/init.d/nginx stop

 nginx closed>>>>>>>>

[root@localhost ~]# netstat -anpt | grep 80
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值