Nginx在线服务状态下平滑升级及ab压力测试【转】
今天,产品那边发来需求,说有个 APP 的 IOS 版本下载包需要新增 https 协议,在景安购买了免费的 SSL 证书。当我往 nginx 上新增 ssl 时,发现服务器上的 nginx 居然没编译 SSL 模块!
看了下旧版本 nginx 的 configure 选项:
linux-gz215:# /usr/local/sbin/nginx -V
nginx version: nginx/1.0.
built by gcc 4.1. (prerelease) (SUSE Linux)
configure arguments: --prefix=/usr/local/nginx
可能是出于最小化安装的考虑,就只有一个 prefix 参数,而版本也挺低的,干脆就升级一下好了!由于服务器处于在线服务状态,为了避免升级带来的不良影响,我决定给 nginx 来个平滑升级,结果发现还真是如丝般顺滑。。。
下面记录一下平滑升级和新增模块的过程。
一、半自动平滑升级
所谓半自动,其实就是在最后迁移的时候使用源码自带的升级命令:make upgrade 来自动完成。
①、按需编译新版本的 nginx
根据需求,常规编译新版本 nginx,不过只要执行到 make 就打住,不要 make install!
#下载1..7版本,并解压
cd /usr/local/src
wget http://nginx.org/download/nginx-1.6.0.tar.gz
tar zxvf nginx-1.6..tar.gz
cd nginx-1.6.
#根据实际需要新增的模块,先准备所需文件(其实只需要解压即可,全部安装,后面编译就可以不指定路径了):
#. 安装pcre:
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
tar -zxvf pcre-8.34.tar.gz
cd pcre-8.34
./configure && make && make install
#. 安装zlib:
cd /usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2..tar.gz
cd zlib-1.2.
./configure && make && make install
#. 安装openssl:
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
cd openssl-1.0.1c
./configure && make && make install
#加上所需参数开始编译:
./configure --user=www --group=www
--prefix=/usr/local/nginx
--with-http_ssl_module
--with-openssl=/usr/local/src/openssl-1.0.1c #对应openssl源码解压后的路径,下同(pcre,zlib)
--with-http_stub_status_module
--with-pcre
--with-pcre=/usr/local/src/pcre-8.21
--with-zlib=/usr/local/src/zlib-1.2.
#执行make编译,但是不要执行make install
make
②、重命名 nginx 旧版本二进制文件,即 sbin 目录下的 nginx(期间 nginx 并不会停止服务!):
linux-gz215:/usr/local/src/nginx-1.6. # mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
③、然后拷贝一份新编译的二进制文件:
linux-gz215:/usr/local/src/nginx-1.6. # cp objs/nginx /usr/local/nginx/sbin/
④、在源码目录执行 make upgrade 开始升级:
linux-gz215:/usr/local/src/nginx-1.6. # make upgrade
#下面是make upgrade命令的打印信息:
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin` #最后确认一下nginx进程,可以发现有2个主进程,并且有正在关闭的进程(shutting down):
linux-gz215:/usr/local/src/nginx-1.6. # ps aux | grep nginx
root 0.0 0.3 Ss Dec09 : nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www 0.1 2.5 S : : nginx: worker process is shutting down
www 0.1 2.5 S : : nginx: worker process is shutting down
www 0.1 2.5 S : : nginx: worker process is shutting down
root 0.0 0.3 S : : nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #过一段时间后,再次确认nginx进程,可以发现老进程已自动退出了(存在一段时间是因为旧进程还有未结束的服务)
root 0.0 0.3 Ss Dec09 : nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www 0.1 2.4 S : : nginx: worker process
完成后,最后确认一下 nginx -V :
linux-gz215:~ # /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.6.
built by gcc 4.1. (prerelease) (SUSE Linux)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/src/openssl-1.0.1c --with-http_stub_status_module --with-pcre --with-pcre=/usr/local/src/pcre-8.21 --with-zlib=/usr/local/src/zlib-1.2.
正常了,平滑升级成功!
二、纯手动平滑升级
纯手动模式,指的是在最后做迁移的时候,全部使用手动命令来搞定,避免编译可能存在不一致的参数啥的。
实际上,在 make 之后,我们可以查看 nginx 源码目录下的 Makefile 内容如下:
default: build
clean:
rm -rf Makefile objs
build:
$(MAKE) -f objs/Makefile
$(MAKE) -f objs/Makefile manpage
install:
$(MAKE) -f objs/Makefile install
upgrade:
/usr/local/nginx/sbin/nginx -t
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
所以,说白了纯手动就是执行 upgrade 标签下的命令行而已,实际上只要确认 Makefile 下的命令路径都是正确的,用命令自动迁移是没有任何问题的。
总是有人会不放心的,喜欢手动一步一步的搞定,我也来整理下纯手动步骤:
①~③和半自动一样,按常规步骤先编译 nginx,不过只执行到 make 就打住,然后将旧的 sbin 下的 nginx 文件移走,再将编译得到的 objs 目录下的 nginx 文件放到原来的 sbin 目录。
④、测试新版本的 nginx 是否正常:
[root@Mars_Server nginx-1.6.0]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok #OK,没有问题!
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
⑤、给旧 nginx 发送平滑迁移信号(若不清楚 pid 路径就用可用命令(2)):
#可用命令():
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
#可用命令():
kill -USR2 `ps aux | grep "nginx: master process" | grep -v grep | awk '{print $2}'`
Ps:后面其实就是旧 nginx 的 pid,所以先用 ps aux 找到正在运行的 nginx 主进程 pid,再执行 kill -USR2 PID 值亦可。
⑥、等待旧版本 Nginx 的 pid 变为 oldbin(执行如下命令查看是否生成)
test -f /usr/local/nginx/logs/nginx.pid.oldbin && echo OK!
⑦、 从容关闭旧版本的 Nginx 进程
kill –WINCH `cat /usr/local/nginx/log/nginx.oldbin`
此时,旧的工作进程就都会慢慢随着任务执行完毕而退出,新版的 Nginx 的工作进程会逐渐取代旧版工作进程。
⑧、此时,不重载配置启动旧工作进程(个人感觉是为了将任务完全切换到新的 nginx 上)
kill –HUP `cat /url/local/nginx/log/nginx.oldbin`
⑨、结束工作进程,完成此次升级操作:
kill –QUIT `cat /usr/local/nginx/log/nginx.oldbin`
⑩、最后,验证 nginx 是否升级成功:
linux-gz215:~ # /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.6. #没问题
built by gcc 4.1. (prerelease) (SUSE Linux)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/src/openssl-1.0.1c --with-http_stub_status_module --with-pcre --with-pcre=/usr/local/src/pcre-8.21 --with-zlib=/usr/local/src/zlib-1.2.
特意测试了下纯手动的做法,下面是我的操作记录,仅供参考:
linux-gz215:/usr/local/nginx # cd sbin/
linux-gz215:/usr/local/nginx/sbin # ll
总计
-rwxr-xr-x root root -- : nginx
linux-gz215:/usr/local/nginx/sbin # mv nginx nginx.old
linux-gz215:/usr/local/nginx/sbin #
linux-gz215:/usr/local/nginx/sbin # cp /usr/local/src/nginx-1.5./objs/
autoconf.err nginx ngx_auto_config.h ngx_modules.c src/
Makefile nginx. ngx_auto_headers.h ngx_modules.o
linux-gz215:/usr/local/nginx/sbin # cp /usr/local/src/nginx-1.5./objs/nginx .
linux-gz215:/usr/local/nginx/sbin # ll
总计
-rwxr-xr-x root root -- : nginx
-rwxr-xr-x root root -- : nginx.old
linux-gz215:/usr/local/nginx/sbin # /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
linux-gz215:/usr/local/nginx/sbin # ps aux | grep nginx
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 1.0 0.0 S : : nginx: worker process
nobody 1.2 0.0 S : : nginx: worker process
nobody 0.6 0.0 S : : nginx: worker process
nobody 0.8 0.0 S : : nginx: worker process
nobody 0.4 0.0 S : : nginx: worker process
nobody 0.1 0.0 S : : nginx: worker process
nobody 0.3 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
root 0.0 0.0 pts/ S+ : : grep nginx
linux-gz215:/usr/local/nginx/sbin # kill -USR2
linux-gz215:/usr/local/nginx/sbin # ps aux | grep nginx
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 0.9 0.0 S : : nginx: worker process
nobody 1.2 0.0 S : : nginx: worker process
nobody 0.5 0.0 S : : nginx: worker process
nobody 0.8 0.0 S : : nginx: worker process
nobody 0.4 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
nobody 0.5 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 5.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
root 0.0 0.0 pts/ S+ : : grep nginx
linux-gz215:/usr/local/nginx/sbin # kill -WINCH
linux-gz215:/usr/local/nginx/sbin # ps aux | grep nginx
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 0.7 0.0 S : : nginx: worker process is shutting down
nobody 0.5 0.0 S : : nginx: worker process is shutting down
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 2.3 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
root 0.0 0.0 pts/ S+ : : grep nginx
linux-gz215:/usr/local/nginx/sbin # ps aux | grep nginx
root 0.0 0.0 S : : nginx: master process ./nginx
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 2.8 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
root 0.0 0.0 pts/ S+ : : grep nginx
linux-gz215:/usr/local/nginx/sbin # kill -HUP
linux-gz215:/usr/local/nginx/sbin # ps aux | grep nginx
root 0.0 0.0 S : : nginx: master process ./nginx
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 3.1 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.8 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.3 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 2.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
root 0.0 0.0 pts/ S+ : : grep nginx
linux-gz215:/usr/local/nginx/sbin # kill -QUIT
linux-gz215:/usr/local/nginx/sbin # ps aux | grep nginx
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 2.2 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 1.5 0.0 S : : nginx: worker process
nobody 0.1 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 3.2 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.6 0.0 S : : nginx: worker process
root 0.0 0.0 pts/ R+ : : grep nginx
linux-gz215:/usr/local/nginx/sbin # ps aux | grep nginx
root 0.0 0.0 S : : nginx: master process ./nginx
nobody 2.2 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
nobody 1.5 0.0 S : : nginx: worker process
nobody 0.1 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.2 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 3.2 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.0 0.0 S : : nginx: worker process
nobody 0.5 0.0 S : : nginx: worker process
root 0.0 0.0 pts/ S+ : : grep nginx
linux-gz215:/usr/local/nginx/sbin #
为了验证平滑升级确实不影响在线业务,我特意在升级的时候,利用 ab 命令一直在发送请求:
ab -n1000000 -c10 http://domain.com/
直到升级完成,使用 ctrl +C 终止并查看 ab 结果,可以发现几十万次的请求全部成功,没有失败!证明平滑升级的可行性!
Nginx在线服务状态下平滑升级及ab压力测试【转】的更多相关文章
- Nginx在线服务状态下平滑升级或新增模块的详细操作
今天应开发的需求,需要在Nginx增加一个模块,并不能影响现有的业务,所以就必须要平滑升级Nginx,好了,不多说了 1:查看现有的nginx编译参数 /usr/local/nginx/sbin/ng ...
- Nginx在线服务状态下平滑升级或新增模块
nginx在使用过程中,有时需要在不影响当前业务的情况下,进行升级或新增模块.nginx的升级有两种方法:1.半自动化升级:2.手动升级 不过都需要先查看安装的nginx版本和配置信息,然后前往官网下 ...
- Nginx网络架构实战学习笔记(五):大访问量优化整体思路、ab压力测试及nginx性能统计模块、nginx单机1w并发优化
文章目录 大访问量优化整体思路 ab压力测试及nginx性能统计模块 ab压力测试及nginx性能统计模块 ab压力测试 nginx性能统计模块 nginx单机1w并发优化 整装待发: socket ...
- Linux下四款Web服务器压力测试工具(http_load、webbench、ab、siege)介绍
一.http_load程序非常小,解压后也不到100Khttp_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载.但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不会把 ...
- Mac下使用Web服务器性能/压力测试工具webbench、ab、siege
Web开发,少不了的就是压力测试,它是评估一个产品是否合格上线的基本标准,下面我们来一一剖析他们的使用方式. 测试前,前面先把系统的端口限制数改大,看看Mac下面的默认限制 ulimit -a ope ...
- ab压力测试nginx
centos7系统: yum install httpd-tools -y #安装ab压力测试工具
- apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))
apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104)) 今天用apache 自带的ab工具测试,当并发量达到1000多的时 ...
- 简单模拟一下ab压力测试
简单了解下ab ab全程是apache benchmark,是apache官方推出的一个工具,创建多个并发访问线程,模拟多个访问者同时对一个URL地址进行访问.它的测试目标是基于URL的,因此它既可以 ...
- ab压力测试工具的使用
一.下载稳定版2.2.31 http://httpd.apache.org/ 二.2.2.*和2.4.*区别? httpd-2.2.x(prefork) httpd-2.4.x(event) 编 ...
随机推荐
- ansible playbook 变量
变量优先级 在命令中定义的变量(-e参数指定的) 在inventory中定义的变量(ansible_ssh_user等) 其他变量(role中.play中) 系统通过father_facts定义的变量 ...
- Hbase运维手册(1)
1. region情况 需要检查 1. region的数量(总数和每台regionserver上的region数) 2. region的大小 如果发现异常可以通过手动merge region和手动分配 ...
- MyBatis-Plugins 的创建流程与执行顺序
一.插件的解析,所有插件都会被添加到 InterceptorChain 类中,用于后续处理 org.apache.ibatis.builder.xml.XMLConfigBuilder private ...
- python第二次周末大作业
题目 ''' HR人力资源管理. 1. 菜单: ("查看员⼯信息","添加员⼯信息", "修改员⼯信息", "删除员⼯信息&quo ...
- 异常来自 HRESULT:0x80070057 (E_INVALIDARG)(转)
莫名其妙的编译总会报错 异常来自 HRESULT:0x80070057 (E_INVALIDARG) 未能加载程序集....... 几次删除引用然后重新引用程序集还是报错 奔溃中.... 网上搜索还真 ...
- ORM常用字段和参数
目录: ORM常用字段和参数
- python 可视化库
在做titanic分析的过程中,看了一些大神的想法,发现在分析数据的过程中,许多大神会使用到seaborn,plotly这些库,而我等小白仅仅知道matplotlib这个唯一的数据可视化库而已.上网查 ...
- 一次针对多台服务器交互式主机命令采集Python脚本编写
[环境介绍] 系统环境:Linux + Python 2.7.10(监控主机) [背景描述] 需求:每次节假日或者重要时间时,需要对数据库主机信息进行检查,比如主机空间使用率之类.有时候需要执 ...
- 什么是CMD
cmd是command的缩写.命令提示符是在操作系统中,提示进行命令输入的一种工作提示符.在不同的操作系统环境下,命令提示符各不相同. 在windows环境下,命令行程序为cmd.exe,是一个32位 ...
- linux下有名管道进程通信
一.任务 1.学习mkfifo等函数: 2.了解有名管道的特点.阻塞打开与非阻塞打开等: 3.编写一个关于有名管道进程通信的程序,并运行. 二.相关概念 1.相关函数 创建有名管道的函数是mkfifo ...