将现有的Nginx迁移到主线版本

我将自己的服务器上的HTTP(S)终端由Debian软件包版迁移到了mainline版本的Nginx,并记录了该过程的备忘录。

环境

    • debian jessie

 

    • 既に入っているNginx (1.6.2-5)

 

    • これから入れるNginx (1.11.2)

 

    既にconfファイルは多く存在する
$ cat /etc/issue
Debian GNU/Linux 8 \n \l

在开始任务前

$ sudo dpkg -l nginx
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                          Version                     Architecture                Description
+++-=============================================-===========================-===========================-===============================================================================================
ii  nginx                                         1.6.2-5                     all                         small, powerful, scalable web/proxy server

完成任务后 (zuò yè

$ dpkg -l nginx
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                          Version                     Architecture                Description
+++-=============================================-===========================-===========================-===============================================================================================
ii  nginx                                         1.11.2-1~jessie             amd64                       high performance web server

任务内容

安装Nginx GPG。

$ wget "http://nginx.org/keys/nginx_signing.key"
--2016-07-07 13:48:43--  http://nginx.org/keys/nginx_signing.key
Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1561 (1.5K) [text/plain]
Saving to: ‘nginx_signing.key’

nginx_signing.key                                  100%[==================================================================================================================>]   1.52K  --.-KB/s   in 0s

2016-07-07 13:48:43 (440 MB/s) - ‘nginx_signing.key’ saved [1561/1561]

$ sudo apt-key  add nginx_signing.key
OK

在apt列表中添加Nginx mainline。

$ cat /etc/apt/sources.list.d/nginx.list
deb http://nginx.org/packages/mainline/debian/ jessie nginx
deb-src http://nginx.org/packages/mainline/debian/ jessie nginx
$ sudo apt-get update
[中略]

确认已追加的事项。 yǐ de .)

$ sudo apt-cache show nginx
Package: nginx
Version: 1.11.2-1~jessie
Architecture: amd64
Maintainer: Sergey Budnevitch <sb@nginx.com>
Installed-Size: 2483
Depends: libc6 (>= 2.14), libpcre3 (>= 1:8.35), libssl1.0.0 (>= 1.0.1), zlib1g (>= 1:1.1.4), lsb-base, adduser
Provides: httpd
Filename: pool/nginx/n/nginx/nginx_1.11.2-1~jessie_amd64.deb
Size: 720626
MD5sum: 71606b0d233c624e1ed0f2bb2cb1544a
SHA1: 85f61bad083fab55d1450a8594d28ed7bec6c701
SHA256: 3c984a186fbccf36f73a06683977a2416645e723045ad6eb61f0d584f26847bd
Section: httpd
Priority: optional
Homepage: http://nginx.org
Description: high performance web server
 nginx [engine x] is an HTTP and reverse proxy server, as well as
 a mail proxy server.
Description-md5: c3ecf9b168b3f5d1b11dda6baf5dd768

[以下略]

安装Nginx主线版本

由于存在现有的Nginx而无法运行,所以暂时删除。

$ sudo apt-get remove nginx-common
$ sudo apt-get install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  nginx
0 upgraded, 1 newly installed, 0 to remove and 177 not upgraded.
Need to get 0 B/721 kB of archives.
After this operation, 2,543 kB of additional disk space will be used.
Selecting previously unselected package nginx.
(Reading database ... 50261 files and directories currently installed.)
Preparing to unpack .../nginx_1.11.2-1~jessie_amd64.deb ...
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

----------------------------------------------------------------------
Unpacking nginx (1.11.2-1~jessie) ...
Processing triggers for systemd (215-17) ...
Setting up nginx (1.11.2-1~jessie) ...
Installing new version of config file /etc/default/nginx ...
Installing new version of config file /etc/init.d/nginx ...
Installing new version of config file /etc/logrotate.d/nginx ...
Installing new version of config file /etc/nginx/fastcgi_params ...

Configuration file '/etc/nginx/nginx.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** nginx.conf (Y/I/N/O/D/Z) [default=N] ?
Installing new version of config file /etc/nginx/scgi_params ...
Installing new version of config file /etc/nginx/uwsgi_params ...
Installing new version of config file /etc/nginx/win-utf ...
Processing triggers for systemd (215-17) ...

以这个方式,安装成功了。

$ sudo nginx -V
nginx version: nginx/1.11.2
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1k 8 Jan 2015 (running with OpenSSL 1.0.1t  3 May 2016)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/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-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=debian/extra/njs-ef2b708510b1/nginx --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed'

解决问题

无法通过systemd启动

由于apt-get remove命令的影响,被屏蔽了,因此我们来解除屏蔽。

$ sudo systemctl status nginx.service
● nginx.service
   Loaded: masked (/dev/null)
   Active: inactive (dead) since Thu 2016-07-07 13:56:32 JST; 1min 17s ago
 Main PID: 700 (code=exited, status=0/SUCCESS)

$ sudo systemctl unmask nginx.service
Removed symlink /etc/systemd/system/nginx.service.

总结

    • 一時的でもNginxの停止が発生するので、本番環境の場合はメンテナンス用サーバを用意して逃がしましょう

 

    • バージョンが変更された事によりconfに不整合が発生する場合があるので気を付けましょう

元々warningだったのがemergencyになって起動しない場合などがあります

快適Nginx生活は意外と簡単に出来るので、是非ご家庭にどうぞ

请参阅

    • 公式ドキュメント

 

    • どのバージョンのnginxを使うべきか? – 考える人、コードを書く人

 

    「Systemd」を理解する ーシステム管理編ー | ギークを目指して
广告
将在 10 秒后关闭
bannerAds