Saturday, July 31, 2021

Upgrade Nginx on CentOS/RHEL 7 from 1.16.1/1.15.2 to 1.20.1, install with Ansible

The upgrade of Nginx on CentOS/RHEL 7 from 1.16.1/1.15.2 to 1.20.1 involved a complete manual removal and ansible installation.  Complete removal and installation were used vs upgrading the version because upgrading requires Nginx modules to be upgraded separately, where an installation takes care of everything.

NOTES:

  • In my case, there were no breaking changes with the nginx.conf and cherryshoe.conf files used from the old to new versions.
  • I installed with yum several times, and on occasion the /etc/nginx/conf.d and /etc/nginx/default.d folders were not created.  You may have to add the ansible task to create these for you prior to copying over the configuration files.
Environment:
ansible 2.9.9
CentOS/RHEL 7
nginx 1.16.1/1.15.2 to 1.20.1

Uninstall existing Nginx

  1. change to the appropriate user that has access to sudo
  2. note the old version, should be 1.16.1/1.15.2
    • nginx -v
  3. stop nginx and verify it's down
    • sudo systemctl stop nginx
    • sudo systemctl status nginx
  4. remove nginx
    • sudo yum remove nginx
    • Confirm y
    • Should see something like the following:
      Loaded plugins: fastestmirror
      Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
      Resolving Dependencies
      --> Running transaction check
      ---> Package nginx.x86_64 1:1.16.1-1.el7 will be erased
      --> Processing Dependency: nginx for package: 1:nginx-mod-http-xslt-filter-1.16.1-1.el7.x86_64
      --> Processing Dependency: nginx for package: 1:nginx-mod-http-perl-1.16.1-1.el7.x86_64
      --> Processing Dependency: nginx for package: 1:nginx-mod-stream-1.16.1-1.el7.x86_64
      --> Processing Dependency: nginx for package: 1:nginx-mod-mail-1.16.1-1.el7.x86_64
      --> Processing Dependency: nginx for package: 1:nginx-mod-http-image-filter-1.16.1-1.el7.x86_64
      --> Running transaction check
      ---> Package nginx-mod-http-image-filter.x86_64 1:1.16.1-1.el7 will be erased
      --> Processing Dependency: nginx-mod-http-image-filter = 1:1.16.1-1.el7 for package: 1:nginx-all-modules-1.16.1-1.el7.noarch
      ---> Package nginx-mod-http-perl.x86_64 1:1.16.1-1.el7 will be erased
      ---> Package nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.el7 will be erased
      ---> Package nginx-mod-mail.x86_64 1:1.16.1-1.el7 will be erased
      ---> Package nginx-mod-stream.x86_64 1:1.16.1-1.el7 will be erased
      --> Running transaction check
      ---> Package nginx-all-modules.noarch 1:1.16.1-1.el7 will be erased
      --> Finished Dependency Resolution
      Dependencies Resolved
      ==========================================================================================
      Package                            Arch          Version               Repository    Size
      ===========================================================================================
      Removing:
       nginx                              x86_64        1:1.16.1-1.el7        @epel        1.6 M
      Removing for dependencies:
       nginx-all-modules                  noarch        1:1.16.1-1.el7        @epel        0.0
       nginx-mod-http-image-filter        x86_64        1:1.16.1-1.el7        @epel         24 k
       nginx-mod-http-perl                x86_64        1:1.16.1-1.el7        @epel         54 k
       nginx-mod-http-xslt-filter         x86_64        1:1.16.1-1.el7        @epel         24 k
       nginx-mod-mail                     x86_64        1:1.16.1-1.el7        @epel         99 k
       nginx-mod-stream                   x86_64        1:1.16.1-1.el7        @epel        171 k
      Transaction Summary
      ===========================================================================================
      Remove  1 Package (+6 Dependent packages)
       Installed size: 2.0 M
      Is this ok [y/N]:
      
  5. delete nginx configuration and log folders
    • sudo rm -R /etc/nginx
    • sudo rm -R /var/log/nginx

Install Nginx

The ansible deploy will install nginx-1.20.1, task looks like:

The upgrade of Nginx on CentOS/RHEL 7 from 1.16.1/1.15.2 to 1.20.1 involved a complete manual removal and ansible installation.  Complete removal and installation were used vs upgrading the version because upgrading requires Nginx modules to be upgraded separately, where an installation takes care of everything.

NOTES:

  • In my case, there were no breaking changes with the nginx.conf and cherryshoe.conf files used from the old to new versions.
  • I installed with yum several times, and on occasion the /etc/nginx/conf.d and /etc/nginx/default.d folders were not created.  You may have to add the ansible task to create these for you prior to copying over the configuration files.

Uninstall existing Nginx

  1. change to the appropriate user that has access to sudo
  2. note the old version, should be 1.16.1/1.15.2
    • nginx -v
  3. stop nginx and verify it's down
    • sudo systemctl stop nginx
    • sudo systemctl status nginx
  4. remove nginx
    • sudo yum remove nginx
    • Confirm y
    • Should see something like the following:
  5. delete nginx configuration and log folders
    • sudo rm -R /etc/nginx
    • sudo rm -R /var/log/nginx

Install Nginx

The ansible deploy will install nginx-1.20.1, task looks like:

- name: install system dependencies
  yum:
    name:
      - nginx-1.20.1
    state: present
    update_cache: yes

- block:
    - name: set up nginx site conf
      template:
        src: "{{ item.src }}"
        dest: "{{ item.dest }}"
      with_items:
        - { src: "cherryshoe.conf.j2", dest: "/etc/nginx/conf.d/cherryshoe.conf" }
        - { src: "nginx.conf.j2", dest: "/etc/nginx/nginx.conf" }
    - name: restart nginx
      systemd: enabled=yes state=reloaded name=nginx

Verification

  1. verify new version
    • nginx -v
  2. verify nginx configuration and log folders created
    • sudo ls -la /etc/nginx
    • sudo ls -la /var/log/nginx
  3. verify application works

No comments:

Post a Comment

I appreciate your time in leaving a comment!