LoginSignup
2
4

More than 3 years have passed since last update.

Amazon Linux 2018.3で最新バージョン(1.17.1)のNginXにアップデートする

Last updated at Posted at 2019-07-01

nginx.repo/etc/yum.repos.d/以下に作成します。このとき各項目にpriority=1を追加しましょう。

/etc/yum.repos.d/nginx.repo
      [nginx-stable]
      name=nginx stable repo
      baseurl=http://nginx.org/packages/centos/6/$basearch/
      priority=1
      gpgcheck=1
      enabled=0
      gpgkey=https://nginx.org/keys/nginx_signing.key

      [nginx-mainline]
      name=nginx mainline repo
      baseurl=http://nginx.org/packages/mainline/centos/6/$basearch/
      priority=1
      gpgcheck=1
      enabled=0
      gpgkey=https://nginx.org/keys/nginx_signing.key

そしてyum --showduplicate list nginx

$ yum --enablerepo=nginx-mainline --showduplicate list nginx
Installed Packages
nginx.x86_64                                   1.17.1-1.el6.ngx                                     @nginx-mainline
Available Packages
nginx.x86_64                                   1.9.0-1.el6.ngx                                      nginx-mainline
nginx.x86_64                                   1.9.1-1.el6.ngx                                      nginx-mainline
(中略)
nginx.x86_64                                   1.15.12-1.el6.ngx                                    nginx-mainline
nginx.x86_64                                   1.17.0-1.el6.ngx                                     nginx-mainline
nginx.x86_64                                   1.17.0-1.el6.ngx                                     nginx-mainline

利用可能なパッケージのバージョンの一覧が表示されるのですが、この中のパッケージを指定して新しいバージョンにアップデートしようとしても

$ sudo yum --disablerepo=amzn-updates install nginx-1.17.1-1.el6.ngx.x86_64
Loaded plugins: priorities, update-motd, upgrade-helper
1 packages excluded due to repository priority protections
Package nginx-1.17.1-1.el6.ngx.x86_64 is obsoleted by 1:nginx-all-modules-1.12.1-1.33.amzn1.x86_64 which is already installed

と表示されてしまい、アップデートできません。
Package XXX is obsoleted by YYY which is already installedと表示されてしまう原因としてyumが本来古いはずのNginxのパッケージを最新版と認識するために古いバージョン扱いとなるパッケージがインストールできないようです。ということで

$ yum --disablerepo=amzn-updates --enablerepo=nginx-mainline downgrade nginx-1.17.1 -y

これでインストール(アップデート)できます。

おまけ

ElasticBeanstalk(およびCloudFormation)用の設定ファイルです。

ebextensions/upgrade_nginx.config
commands:
  update_nginx:
    command: |
      NGINX_VER=$(yum list nginx | grep nginx | awk '{print $2}')
      if ! [ NGINX_VER = "1.17.1-1.el6.ngx" ] ; then
        yum --disablerepo=amzn-updates downgrade nginx-1.17.1 -y
      fi
      nginx -V

files:
  /etc/yum.repo.d/nginx.repo:
    mode: "000644"
    owner: root
    group: root
    content: |
      [nginx-stable]
      name=nginx stable repo
      baseurl=http://nginx.org/packages/centos/6/$basearch/
      priority=1
      gpgcheck=1
      enabled=1
      gpgkey=https://nginx.org/keys/nginx_signing.key

      [nginx-mainline]
      name=nginx mainline repo
      baseurl=http://nginx.org/packages/mainline/centos/6/$basearch/
      priority=1
      gpgcheck=1
      enabled=1
      gpgkey=https://nginx.org/keys/nginx_signing.key
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4