IT运维笔记


nginx平滑添加模块

1、先查看nginx版本和已支持的模块,发现未有--with-ipv6模块
./nginx -V
nginx version: nginx/1.11.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --error-log-path=/var/log/nginx-err --http-log-path=/usr/local/nginx/logs --user=nginx --group=nginx --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_gzip_static_module --with-http_perl_module --with-pcre --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-http_realip_module --with-http_v2_module --with-http_addition_module --with-http_image_filter_module --with-http_secure_link_module --add-module=/usr/local/ngx_devel_kit-0.3.0 --add-module=/usr/local/lua-nginx-module-0.10.6
2、官网下载相同版本nginx 3、添加模块 下载要添加的模块,如果是第三方则需要下载,然后指定添加路径(就是下载第三方的路径),以淘宝ngx_http_concat_module模块为列 --add-module=/home/xiexie/nginx-http-concat ,如果是自带的模块比如我们今天要添加的ipv6模块 --with-ipv6 编译前加上之前查看版本的模块信息
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs --user=nginx --group=nginx --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_gzip_static_module --with-http_perl_module --with-pcre --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-http_realip_module --with-http_v2_module --with-http_addition_module --with-ipv6 --with-http_image_filter_module --with-http_secure_link_module --add-module=/usr/local/ngx_devel_kit-0.3.0 --add-module=/usr/local/lua-nginx-module-0.10.6
编译成功后make,记住千万不要make install,这样会覆盖你以前的nginx 备份nginx mv /usr/local/nginx /usr/local/nginx.bak 复制编译目录下的nginx启动文件 cp ./objs/nginx /usr/local/nginx/sbin/ 4、启动测试
./nginx -V
nginx version: nginx/1.11.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --error-log-path=/var/log/nginx-err --http-log-path=/usr/local/nginx/logs --user=nginx --group=nginx --with-select_module --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_gzip_static_module --with-http_perl_module --with-pcre --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-stream --with-stream_ssl_module --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-http_realip_module --with-http_v2_module --with-http_addition_module --with-http_image_filter_module --with-http_secure_link_module --with-ipv6 --add-module=/usr/local/ngx_devel_kit-0.3.0 --add-module=/usr/local/lua-nginx-module-0.10.6
5、发送USR2信号给nginx master 进程(nginx服务接收到USR2信号后,首先会将旧的nginx.pid文件添加后缀.oldbin,变为nginx.pid.oldbin,然后执行新版本的二进制文件启动服务,如果新的服务启动成功,系统中将有新旧两个Nginx服务共同提供web服务)
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
ps -ef | grep nginx
root   22644   1 0 23:30 ?    00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www   22648 22644 0 23:30 ?    00:00:00 nginx: worker process  
root   25784 22644 0 23:47 ?    00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www   25789 25784 0 23:47 ?    00:00:00 nginx: worker process 
6、通过发送WINCH信号(平缓停止worker process)和QUIT信号(平缓停止Nginx服务)停止旧的Nginx服务进程
kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`