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) 编 ...
随机推荐
- 2017-12-14python全栈9期第一天第五节之变量、常量、注释
6,变量. 变量:就是将一些运算的中间结果暂存到内存中,以便后续代码调用. 1,必须由数字,字母,下划线任意组合,且不能数字开头. 2,不能是python中的关键字. ['and', 'as', 'a ...
- saltstack SLS
SLS文件定义 SLS(代表SaLt State文件)是Salt State系统的核心.SLS描述了系统的目标状态,由格式简单的数据构成.这经常被称作配置管理 top.sls 是配置管理的入口文件,一 ...
- WebStorm记录(3)
连通接口 接口 我自己理解前后端传输数据都是通过ajax方式 一般使用get和post两种方式传输数据 GET 接口 接口描述 获取登录验证码图片及密钥 HTTP方法 POST URL /captch ...
- VMware Workstation Pro 14 虚拟机安装教程
准备学习一下linxus,可不想双系统,那么只有虚拟机这条路了.故在此记录一下安装VMware的过程. 一.下载VMware 我用的是VMware Workstation Pro 14(其他版本也可以 ...
- HDU 1039(字符串判断 **)
题意是检查一个字符串是否满足三个条件: 一.至少有一个元音字母.二.不能出现三个连续的元音或三个连续的辅音.三.除了 ee 和 oo 外不能出现两个连续相同字母. 若三个条件都能满足,该字符串满足条件 ...
- HDU 1020(连续同字符统计 **)
题意是要统计在一段字符串中连续相同的字符,不用再排序,相等但不连续的字符要分开输出,不用合在一起,之前用了桶排序的方法一直 wa,想复杂了. 代码如下: #include <bits/stdc+ ...
- 错误 1 “Entities.PlanPrjEntity.PlanPrjs”不可访问,因为它受保护级别限制
本人第一次是用List做父类,写了一个类PlanPrjs,如下: class PlanPrj { public int ID { get; set; } public string Name { ge ...
- impala系列: 字符串函数
--=======================常用字符串函数--=======================base64decode(string str) : base64 解码.base64 ...
- Linux 用top命令查看CPU和内存使用情况
直接 top 回车 PID:进程的ID USER:进程所有者 PR:进程的优先级别,越小越优先被执行 NInice:值 VIRT:进程占用的虚拟内存 RES:进程占用的物理内存 SHR:进程使用的共享 ...
- Android允许在UI线程中使用网络访问
StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode ...