How to Upgrade to Ubuntu 20.04 without breaking Zabbix

Recently I ran into a raft of issues when I upgraded from Ubuntu 18.04 to 20.04 on my Zabbix server.
My reasons for doing this was because Apache had several CVE’s and wouldn’t upgrade to the latest version using the default Ubuntu repo’s, whereas upgrading to 20.04 got me on the latest Apache2 version.

Firstly before you start any of this I cannot stress enough the importance of taking a backup of your Zabbix server as well as your Zabbix database and testing the backups too before starting any of the upgrade. I usually just take a snapshot of the VM running my Zabbix server. If you get into hot water then you can simply roll back to the point that you took the snapshot. But in this instance I have a sandbox environment setup and I simply cloned my zabbix server and database server into my sandbox first and did a dry run in there of the upgrade and only once I had tested it fully did I then perform the upgrade on my production zabbix server. If people are interested in how to simply setup a sandbox environment, then let me know and i’ll post up a separate topic on how to do that too. It’s actually easier than you might think :slight_smile:

Step 1 - Install any outstanding Updates on your Ubuntu server
apt-get update && apt-get upgrade

Step 2 - Upgrade to the latest zabbix version
rm -Rf /etc/apt/sources.list.d/zabbix.list
dpkg -i zabbix-release_5.0-1+bionic_all.deb

Say Yes to overwriting your /etc/apt/sources.list file
apt-get update
apt-get install --only-upgrade zabbix-server-mysql zabbix-frontend-php zabbix-agent zabbix-apache-conf
service zabbix-server start
service zabbix-agent start

Next log in to your Zabbix UI using a web browser. If you are quick to do this you will get a notice saying your Zabbix database is not on the correct version. Do not panic. Zabbix will be doing a silent upgrade in the background. Be patient and the page will refresh and eventually give you the login screen.
Once logged in you might find the interface looks a little different since version 5 now has the menu on the left instead of the top. And no I also coulnd;t find an option to move it back either, but bare with it, you’ll get used to it :slight_smile:
Once logged in, just go through and make sure everything is still working as expected.

Step 3 - Do the release upgrade for Ubuntu
apt update && apt upgrade -y
sudo apt --purge autoremove
sudo apt install update-manager-core

This next bit is best done via the console or be sure to run “tmux” first so that if you get disconnected, then you can reconnect back to your session without loosing it.
sudo do-release-upgrade -d

  • Say Yes to begin the upgrade and work through all the prompts.
  • Say Y to removing any obsolete programs etc
  • Say Yes to restarting services automatically
  • If you get asked to replace any config files, choose the default option of “No”. aka just hit Enter.
  • Choose LXD 4.0 snap track, which is recommended
  • Say yes to removing obsoleted software
  • Then at the end simply say Yes to reboot your server.

Step 4 - Don’t Panic
At this stage your Zabbix will be broken. Don’t panic. This is why I’ve written this topic, because if anyone arrives here these are the steps I took to get it working again.
The reason why it’ll appear broken is that hte upgrade firstly uninstalls the MySQL libraries and if your like me and use MySQL as your database backend then you’ll need to do these steps to put it back. If you use Postgres then you may need to substitute my mysql commands for the equivelant postgres ones.

First we need to put hte correct repo in for Zabbix and Ubuntu 20.04
rm -Rf /etc/apt/sources.list.d/zabbix.list
dpkg -i zabbix-release_5.0-1+focal_all.deb

Now update
apt-get update

Lastly install the missing components needed to run Zabbix again
apt-get install --only-upgrade zabbix-server-mysql zabbix-frontend-php zabbix-agent zabbix-apache-conf
apt-get install zabbix-server-mysql
apt install php
apt install php-gd php-ldap openipmi fping php-mbstring php-bcmath

At this point it’s probably best to just reboot and then you should be back up and running again.