在Amazon Linux 2018.3中将NginX更新至最新版本(1.17.1)

我们需要在/etc/yum.repos.d/目录下创建一个nginx.repo文件,并在每个项目中添加priority=1。

      [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 –showduplicates 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

由于 yum 将原本应为旧版本的 Nginx 软件包错误地识别为最新版本,导致显示 “包 XXX 已被已安装的 YYY 替代,无法更新”。因此,无法安装被视为旧版本的软件包。

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

你可以通过这个来进行安装(更新)。

额外赠品

这是针对ElasticBeanstalk(和CloudFormation)的配置文件。

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
广告
将在 10 秒后关闭
bannerAds