公司需求:
有个项目需要升级NGIXN
1、首先查看ngxin版本
[root@appcube-0008 nginx-1.21.0]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (EulerOS 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sb
in/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/lo
g/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/ru
n/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx
--with-compat --with-file-aio --with-threads --with-http_addition_module --wit
h-http_auth_request_module --with-http_dav_module --with-http_flv_module --wit
h-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --w
ith-http_random_index_module --with-http_realip_module --with-http_secure_link
_module --with-http_slice_module --with-http_ssl_module --with-http_stub_statu
s_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_
ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module
--with-stream_ssl_preread_module --with-zlib=/root/setup/zlib-1.2.11 --add-mod
ule=/root/setup/headers-more
这里要注意的问题:
后续用到的这两个要注意,可能因为环境的部署不一样,所以路径不一样(有的人喜欢放在opt目录下)
?
?2、下载解压
wget http://nginx.org/download/nginx-1.21.1.tar.gz
tar -zxvf nginx-1.21.1.tar.gz
cd nginx-1.21.1
3、编译(这里就用到nginx -V看到的从?--prefix开始往后的参数)
[root@appcube-0008 nginx-1.21.1]# ls
auto bash.sh CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@appcube-0008 nginx-1.21.1]# cat bash.sh #我这里嫌麻烦改成了shell
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/ng
inx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/n
ginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-compat --with-file-aio --with-th
reads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --
with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --wi
th-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_s
tub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --
with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-zlib=/root/setup/zlib-1
.2.11 --add-module=/root/setup/headers-more
4、make
千万不要执行make install,make install 直接重装了,环境就没了
[root@localhost nginx-1.21.1]# make
make -f objs/Makefile
make[1]: Entering directory `/setup/nginx-1.21.0'
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
。。。。
objs/src/http/modules/ngx_http_upstream_keepalive_module.o \
objs/src/http/modules/ngx_http_upstream_zone_module.o \
objs/src/http/modules/ngx_http_stub_status_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/opt/nginx|" \
-e "s|%%PID_PATH%%|/var/nginx/logs/nginx.pid|" \
-e "s|%%CONF_PATH%%|/var/nginx/conf/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/var/nginx/logs/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/root/setup/nginx-1.21.0'
5、替换
[root@appcube-0008 nginx-1.21.1]# ls
auto bash.sh CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
[root@appcube-0008 nginx-1.21.1]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx-1.18.0
[root@appcube-0008 nginx-1.21.1]# cp objs/nginx /usr/local/nginx/sbin/
6、依次启动新的主进程和新的工作进程.
通过ps -ef | grep ngxin 查看
kill -USR2 `cat /var/run/nginx/nginx.pid` #杀死主进程
kill -WINCH `cat /var/run/nginx/nginx.pid.oldbin`
主进程长期不死的情况下直接kill -9 主进程
7、最后结果
?8、升级完成
|