记录一次nginx升级过程

本文记录了一次Debain系统升级nginx的过程。所有命令以Debain为例进行阐述。

在LINUX系统中如果想升级一个软件最简单的方法应该是这样的:

apt-get upgrade nginx

不过LINUX系统中想使用这个命令升级,你需要先执行这个:

apt-get update

因为如果源不更新的话系统总会提示你当前的软件已经是最新的了。例如:

root@webhost:/usr/sbin# apt-get install nginx
Reading package lists… Done
Building dependency tree
Reading state information… Done
nginx is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.

LINUX更新源很慢,并且如果你想更新到最新,比如为了躲避一个0day,这种方法往往还是会让你失望的。并且如果这样能解决问题我也就i需要往下写了。

本次nginx升级过程如下:

首先在系统中执行nginx -V 这是一个小窍门,很多开源软件都可以用这个方法来获得原始编译参数,非常实用。

看看现在的nginx 的编译参数是什么,因为如果不使用相同的参数编译的话,你可能会面临一个问题:新编译的nginx因为某些配置与原版不同因此你的网站在新环境下跑不起来,然后你需要跟着错误提示一点点调整编译。

root@webhost:~# nginx -V
nginx version: nginx/1.2.1
TLS SNI support enabled
configure arguments: –prefix=/etc/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-client-body-temp-path=/var/lib/nginx/body –http-fastcgi-temp-path=/var/lib/nginx/fastcgi –http-log-path=/var/log/nginx/access.log –http-proxy-temp-path=/var/lib/nginx/proxy –http-scgi-temp-path=/var/lib/nginx/scgi –http-uwsgi-temp-path=/var/lib/nginx/uwsgi –lock-path=/var/lock/nginx.lock –pid-path=/var/run/nginx.pid –with-pcre-jit –with-debug –with-http_addition_module –with-http_dav_module –with-http_geoip_module –with-http_gzip_static_module –with-http_image_filter_module –with-http_realip_module –with-http_stub_status_module –with-http_ssl_module –with-http_sub_module –with-http_xslt_module –with-ipv6 –with-sha1=/usr/include/openssl –with-md5=/usr/include/openssl –with-mail –with-mail_ssl_module –add-module=/build/nginx-1.2.1/debian/modules/nginx-auth-pam –add-module=/build/nginx-1.2.1/debian/modules/nginx-echo –add-module=/build/nginx-1.2.1/debian/modules/nginx-upstream-fair –add-module=/build/nginx-1.2.1/debian/modules/nginx-dav-ext-module

从这里获得nginx的源码:http://nginx.org/en/download.html

git clone http://nginx.org/download/nginx-1.10.3.tar.gz

建一个目录把源码放进去。
解压源码,开始configure。

别忘了使用上面获得的参数。

configure 会检查系统依赖项,这个过程中会遇到一些缺库的提示,解决方法就是apt-get。

过首先要解决的是第三方模块的问题:配置项中使用了非官方的源码以扩展nginx功能。参数如下:
–add-module=/build/nginx-1.2.1/debian/modules/nginx-auth-pam –add-module=/build/nginx-1.2.1/debian/modules/nginx-echo –add-module=/build/nginx-1.2.1/debian/modules/nginx-upstream-fair –add-module=/build/nginx-1.2.1/debian/modules/nginx-dav-ext-module

这些模块我们可能不知道原编译者是从哪获得的了。一般来说github.com上通常会有我们想要的东西。
以nginx-auth-pam nginx-echo nginx-upstream-fair nginx-dav-ext-module 为关键字去github上找吧,如果没有相同的至少也可以找到等价的。

以下就是我找的了:
git clone https://github.com/openresty/echo-nginx-module.git
git clone https://github.com/arut/nginx-dav-ext-module.git

git clone https://github.com/gnosek/nginx-upstream-fair.git
git clone https://github.com/sto/ngx_http_auth_pam_module.git

编译中提示依赖pcre找了源码:
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
后来想想还是算了,因为依赖库的编译参数应没办法像程序那样可以用-V来确定编译参数了。
直接安装系统源自带的开发包吧:
apt-get install libpcre3 libpcre3-dev

依赖项找齐后因为后找的第三方库与原编译者不同所以要调整模块路径最终编译参数:

./configure –prefix=/etc/nginx –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-client-body-temp-path=/var/lib/nginx/body –http-fastcgi-temp-path=/var/lib/nginx/fastcgi –http-log-path=/var/log/nginx/access.log –http-proxy-temp-path=/var/lib/nginx/proxy –http-scgi-temp-path=/var/lib/nginx/scgi –http-uwsgi-temp-path=/var/lib/nginx/uwsgi –lock-path=/var/lock/nginx.lock –pid-path=/var/run/nginx.pid –with-pcre-jit –with-debug –with-http_addition_module –with-http_dav_module –with-http_geoip_module –with-http_gzip_static_module –with-http_image_filter_module –with-http_realip_module –with-http_stub_status_module –with-http_ssl_module –with-http_sub_module –with-http_xslt_module –with-ipv6 –with-sha1=/usr/include/openssl –with-md5=/usr/include/openssl –with-mail –with-mail_ssl_module –add-module=/root/work/nginx-1.10.3/mod/nginx_http_authnz_pam_module –add-module=/root/work/nginx-1.10.3/mod/echo-nginx-module –add-module=/root/work/nginx-1.10.3//mod/nginx-upstream-fair –add-module=/root/work/nginx-1.10.3/mod/nginx-dav-ext-module

再解决几个缺库问题

apt-get install libgd2-xpm
apt-get install libgd2-xpm-dev
apt-get install libgeoip-dev

配置成功输出结果如下:
creating objs/Makefile

Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library

nginx path prefix: “/etc/nginx”
nginx binary file: “/etc/nginx/sbin/nginx”
nginx modules path: “/etc/nginx/modules”
nginx configuration prefix: “/etc/nginx”
nginx configuration file: “/etc/nginx/nginx.conf”
nginx pid file: “/var/run/nginx.pid”
nginx error log file: “/var/log/nginx/error.log”
nginx http access log file: “/var/log/nginx/access.log”
nginx http client request body temporary files: “/var/lib/nginx/body”
nginx http proxy temporary files: “/var/lib/nginx/proxy”
nginx http fastcgi temporary files: “/var/lib/nginx/fastcgi”
nginx http uwsgi temporary files: “/var/lib/nginx/uwsgi”
nginx http scgi temporary files: “/var/lib/nginx/scgi”

开始编译:

make

在编译中还碰到了一个错误,说security/pam_appl.h找不到,有问题就找百度搜一下提示信息。结果还是缺库。

一开始怀疑是三方模块的问题,所以替换了一个模块:
git clone https://github.com/pkamenickova/nginx_http_authnz_pam_module.git
最后装上它编译成功。
apt-get install libpam-dev

make install

root@webhost:~/work/nginx-1.10.3# make install
make -f objs/Makefile install
make[1]: Entering directory `/root/work/nginx-1.10.3′
test -d ‘/etc/nginx’ || mkdir -p ‘/etc/nginx’
test -d ‘/etc/nginx/sbin’ \
|| mkdir -p ‘/etc/nginx/sbin’
test ! -f ‘/etc/nginx/sbin/nginx’ \
|| mv ‘/etc/nginx/sbin/nginx’ \
‘/etc/nginx/sbin/nginx.old’
cp objs/nginx ‘/etc/nginx/sbin/nginx’
test -d ‘/etc/nginx’ \
|| mkdir -p ‘/etc/nginx’
cp conf/koi-win ‘/etc/nginx’
cp conf/koi-utf ‘/etc/nginx’
cp conf/win-utf ‘/etc/nginx’
test -f ‘/etc/nginx/mime.types’ \
|| cp conf/mime.types ‘/etc/nginx’
cp conf/mime.types ‘/etc/nginx/mime.types.default’
test -f ‘/etc/nginx/fastcgi_params’ \
|| cp conf/fastcgi_params ‘/etc/nginx’
cp conf/fastcgi_params \
‘/etc/nginx/fastcgi_params.default’
test -f ‘/etc/nginx/fastcgi.conf’ \
|| cp conf/fastcgi.conf ‘/etc/nginx’
cp conf/fastcgi.conf ‘/etc/nginx/fastcgi.conf.default’
test -f ‘/etc/nginx/uwsgi_params’ \
|| cp conf/uwsgi_params ‘/etc/nginx’
cp conf/uwsgi_params \
‘/etc/nginx/uwsgi_params.default’
test -f ‘/etc/nginx/scgi_params’ \
|| cp conf/scgi_params ‘/etc/nginx’
cp conf/scgi_params \
‘/etc/nginx/scgi_params.default’
test -f ‘/etc/nginx/nginx.conf’ \
|| cp conf/nginx.conf ‘/etc/nginx/nginx.conf’
cp conf/nginx.conf ‘/etc/nginx/nginx.conf.default’
test -d ‘/var/run’ \
|| mkdir -p ‘/var/run’
test -d ‘/var/log/nginx’ \
|| mkdir -p ‘/var/log/nginx’
test -d ‘/etc/nginx/html’ \
|| cp -R html ‘/etc/nginx’
test -d ‘/var/log/nginx’ \
|| mkdir -p ‘/var/log/nginx’

检查nginx是否被新程序替换了:
nginx -v

nginx version: nginx/1.2.1

没有替换,那看一下老程序装在什么位置了,把新程序复制过去不就好了么?

root@webhost:~/work/nginx-1.10.3# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx /usr/share/man/man1/nginx.1.gz

那么我们的程序装哪儿了?

root@webhost:~/work/nginx-1.10.3# find / -name nginx
/usr/sbin/nginx
/usr/share/doc/nginx
/usr/share/nginx
/var/log/nginx
/var/lib/nginx
/etc/init.d/nginx
/etc/ufw/applications.d/nginx
/etc/logrotate.d/nginx
/etc/default/nginx
/etc/nginx
/etc/nginx/sbin/nginx
/root/work/nginx-1.10.3/objs/nginx

在这里:/etc/nginx/sbin/nginx

复制过去,然后再试试。

root@webhost:~/work/nginx-1.10.3# nginx -v
nginx version: nginx/1.10.3

OK,重启服务去看看效果:

service nginx restart

 

关于xmsg

技术面前人人平等.同时技术也不分高低贵贱.正所谓学无大小,达者为尊.
此条目发表在Linux, 功能配置分类目录,贴了, , , , 标签。将固定链接加入收藏夹。

发表评论