Upgrade OpenResty Edge Offline

1. Get offline package

If you don’t have the offline package named Edge-Offline-VERSION.tar.gz, please login and download it at OpenResty Download Center using your email address.

tar xf Edge-Offline-VERSION.tar.gz

# Example: tar xf Edge-Offline-20210721.tar.gz

Usually the offline package will contain the following files:

  • openresty-postgresql.tar.gz, or openresty-postgresql12.tar.gz either
  • openresty-postgresql12.tar.gz, or openresty-postgresql.tar.gz either
  • openresty-edge-admin.tar.gz
  • openresty-edge-node.tar.gz
  • openresty-edge-log-server.tar.gz
  • update-admin-db-VERSION.sh, use only when upgrading
  • update-log-server-db-VERSION.sh, use only when upgrading
  • init_admin_db_VERSION.sh, use only during installation
  • init_log_server_db_VERSION.sh, use only during installation

2. Upgrade Log Server Database

  • Upgrade database program

    If openresty-PostgreSQL is already installed on your system use openresty-postgresql.tar.gz. If openresty-postgresql12 is already installed on your system use openresty-postgresql12.tar.gz.

    # Transfer openresty-postgresql[12].tar.gz to the machine where the Log Server database is located
    tar xf openresty-postgresql[12].tar.gz
    cd openresty-postgresql[12]
    sudo bash upgrade.sh
    
  • Upgrade database schema

    # Transfer update-log-server-db-VERSION.sh to the machine where the Log Server database is located
    bash update-log-server-db-VERSION.sh
    
    # Example: bash update-log-server-db-40.sh
    

3. Upgrade Log Server

  • Check and record the software version before the upgrade:

    # centos/redhat/fedora
    rpm -q openresty-edge-log-server
    # or
    rpm -q openresty-edge-log-server-prod
    
    # debian/ubuntu
    dpkg -l | grep openresty-edge-log-server
    # or
    dpkg -l | grep openresty-edge-log-server-prod
    
  • Upgrade:

    # Transfer openresty-edge-log-server.tar.gz to the machine where the Log Server is located
    
    tar xf openresty-edge-log-server.tar.gz
    cd openresty-edge-log-server
    sudo bash upgrade.sh
    sudo rpm -qa | grep edge
    

4. Upgrade Node

Upgrade 1~2 Nodes first, and then upgrade all Node after there are no problems, please pay attention to the error log during the upgrade.

  • Check and record the software version before the upgrade:

    # centos/redhat/fedora
    rpm -q openresty-edge-node
    # or
    rpm -q openresty-edge-node-prod
    
    # debian/ubuntu
    dpkg -l | grep openresty-edge-node
    # or
    dpkg -l | grep openresty-edge-node-prod
    
  • Cut away traffic. If you are using Edge’s DNS, follow these steps; otherwise, proceed as you see fit.

    • Take the Node you want to upgrade offline.

      • Enter the [Gateway Clusters].
      • [Edit] The cluster where the node is located.
      • Modify the node’s [status] to [Disable DNS, disable caching cluster].
      • [Save]
    • Wait for the node to no longer have traffic. You could confirm by checking the access log:

      tail -f /usr/local/oredge-node/logs/access.log
      

      This process requires waiting for DNS to expire, which can be time-consuming.

  • Upgrade:

    # Transfer openresty-edge-node.tar.gz to the machine where the Node is located
    tar xf openresty-edge-node.tar.gz
    cd openresty-edge-node
    sudo bash upgrade.sh
    sudo rpm -qa | grep edge
    

5. Upgrade Admin database

  • Backup database

    Before executing the backup command, please check if there is enough disk space.

    # Please replace 127.0.0.1 with the actual IP and 5432 with the actual port.
    /usr/local/openresty-postgresql12/bin/pg_dump or_edge_admin                       \
    -h 127.0.0.1 -p 5432 -U postgres                                              \
    | gzip > db_edge_admin_$(date '+%Y-%m-%d').sql.gz
    

    or

    /usr/local/openresty/postgresql/bin/pg_dump or_edge_admin                         \
    -h 127.0.0.1 -p 5432 -U postgres                                              \
    | gzip > db_edge_admin_$(date '+%Y-%m-%d').sql.gz
    
  • Upgrade database program

    If openresty-PostgreSQL is already installed on your system use openresty-postgresql.tar.gz. If openresty-postgresql12 is already installed on your system use openresty-postgresql12.tar.gz.

    # Transfer openresty-postgresql[12].tar.gz to the machine where the Admin database is located
    tar xf openresty-postgresql[12].tar.gz
    cd openresty-postgresql[12]
    sudo bash upgrade.sh
    
  • Upgrade database schema

    # Transfer openresty-postgresql.tar.gz to the machine where the Admin database is located
    bash update-admin-db-VERSION.sh
    # 如:bash update-admin-db-179.sh
    

6. Upgrade Admin

  • Check and record the software version before the upgrade:

    # centos/redhat/fedora
    rpm -q openresty-edge-admin
    # or
    rpm -q openresty-edge-admin-prod
    
    # debian/ubuntu
    dpkg -l | grep openresty-edge-admin
    # or
    dpkg -l | grep openresty-edge-admin-prod
    
  • Upgrade:

    # Transfer openresty-edge-admin.tar.gz to the machine where the Admin is located
    tar xf openresty-edge-admin.tar.gz
    cd openresty-edge-admin
    sudo bash upgrade.sh
    sudo rpm -qa | grep edge
    

7. Recompile

Please recompile the application in the following order:

  1. Recompile a few applications that do not contain wildcard domains with less traffic first
  2. Recompile several high-traffic applications that do not contain wildcard domains
  3. Recompile all wildcard applications
  4. Recompile all applications
  5. Recompile global rules
cd /usr/local/oredge-admin/
# recompile upgrade compatible configurations
sudo /bin/bash utils/recompile-apps.sh upgrade-config
# recompile the specified application (replace APP-ID with application ID)
sudo bash utils/recompile-apps.sh http APP-ID
# recompile all applications
sudo bash utils/recompile-apps.sh wildcard-http
sudo bash utils/recompile-apps.sh http
sudo bash utils/recompile-apps.sh http_proxy
sudo bash utils/recompile-apps.sh socks5_proxy
# recompile global rules
sudo bash utils/recompile-apps.sh global
# recompile waf rules
sudo bash utils/recompile-apps.sh waf
# recompile DNS applications
sudo bash utils/recompile-apps.sh dns
# recompile global actions
sudo bash utils/recompile-apps.sh global-action
# recompile gateway (may trigger OpenResty Edge Node reload)
sudo bash utils/recompile-apps.sh gateway

If the whole system behave normally, the upgrade is complete!

this step may take longer to compile when there are many HTTP/HTTPS applications.

sudo /bin/bash utils/recompile-apps.sh http

We recommend using another tool for concurrent compilation then. The following command will start 4 processes to compile.

sudo /bin/bash utils/parallel-recompile.sh

If it is not fast enough, you can also specify a larger concurrency, but not larger than 8, e.g.

sudo /bin/bash utils/parallel-recompile.sh 8

8. After Upgrade

After the previous steps have been performed and validated. This step can be performed to clean up database fields that are no longer needed or to add constraints to database fields.

  • Admin DB
bash after-upgrade-admin-db-VERSION.sh
# Example: bash after-upgrade-admin-db-202.sh

If you have any questions, please contact us.