运行环境
操作系统:CentOS Linux release 7.4.1708 (Core)
旧nginx版本:nginx version: nginx/1.14.0
升级目标版本:nginx-1.28.0
升级前准备
1、官网http://nginx.org/en/download.html下载最新稳定版nginx。
2、查看nginx安装路径
[root@201 ~]# which nginx
/usr/sbin/nginx
3、查看版本与编译参数
[root@201 sbin]# cd /usr/sbin/
[root@201 sbin]# ./nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --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 --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_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-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
4、备份旧版nginx
[root@201 ~]# cp /usr/sbin/nginx /data/nginx/bak/
[root@201 ~]# ls /data/nginx/bak/
nginx
5、上传最新安装包,如上传到/data/nginx路径下。
升级过程
1、解压安装包
[root@201 ~]# cd /data/nginx/
[root@201 nginx]# tar -zxvf nginx-1.28.0.tar.gz
2、配置新版nginx,根据上文nginx -V 输出的旧版configure arguments,保持旧版的安装模块。
[root@201 nginx]# cd nginx-1.28.0
[root@201 nginx-1.28.0]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --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 --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_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-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
3、编译新版nginx(注意不要install)
[root@201 nginx]# make
4、用编译好的新版nginx替换就得nginx
[root@201 nginx-1.28.0]# ls objs/
autoconf.err Makefile nginx nginx.8 ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_modules.o src
[root@201 nginx-1.28.0]# cp objs/nginx /usr/sbin/
cp: overwrite ‘/usr/sbin/nginx’? y
cp: cannot create regular file ‘/usr/sbin/nginx’: Text file busy
提示旧nginx在使用中,先执行/usr/sbin/nginx -s stop 停止旧的nginx再执行cp命令。
5、启动新的nginx并查看版本
[root@201 nginx-1.28.0]# /usr/sbin/nginx -c /etc/nginx/nginx.conf
[root@201 nginx-1.28.0]# /usr/sbin/nginx -V
nginx version: nginx/1.28.0
1888

被折叠的 条评论
为什么被折叠?



