Migrating Zabbix Postgres Database Between Zabbix Servers
I’ve been tossing up moving my Zabbix server from a VMWare host to a ProxMox host, and decided that it was time. I’m hoping that by moving the server from VMWare to ProxMox, the disk latency will go down a bit since I’m using a RAID1 array for Zabbix on the ProxMox host rather than emulated disks on VMWare as well as moving to some cheap SSDs.
To do this, I’ve decided to start with a clean CentOS 7 server rather than migrating my CentOS 6 server from VMWare to ProxMox.
While I’m doing the migration, I’ll also upgrade to the latest version of Zabbix.
This means that I’ll need to set up a new Zabbix install, and then migrate the database over.
Starting with a clean CentOS 7 server, I’ve setup Postgresql, installed Zabbix with its dependencies –
# yum install postgresql postgresql-libs postgresql-server
# postgresql-setup initdb
# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
# yum install zabbix zabbix-web-pgsql zabbix-server-pgsql zabbix-agent
and also started the Zabbix agent, the http server, and disabled the firewall. I’ve also enabled the Zabbix and postgresql servers but I haven’t started it yet
# systemctl stop firewalld.service
# systemctl disable firewalld.service
# systemctl enable httpd.service
# systemctl start httpd.service
# systemctl enable postgresql.service
# systemctl enable zabbix-agent.service
# systemctl enable zabbix-server.service
# systemctl start zabbix-agent.service
After this, you should be able to access the Zabbix setup interface on
Next step is to replicate the Zabbix, and database configuration on the new server. Don’t just copy the Zabbix configuration file over as the configuration file has changed and there are new options to explore!
/etc/zabbix/zabbix_server.conf with the Database username and password, and also updated Postgresql’s
pg_hba.conf file to use the same authentication scheme as the old server.
This is a good time to go over your Zabbix server configuration to ensure it’s configured optimally.
After updating the files, make sure you start the postgres server.
Next is to do the actual migration of the database data. It’s a good idea to stop the source Zabbix server while the dump is taking place to ensure the data is consistent.
Depending on your database set up, you may need to create the users that Zabbix use to access the database before proceeding.
To do the dump, I’ve used
pg_dump to connect to the old server from the new server, however this requires the old server being configured to allow connections over the network. Depending on the size of your database, this could take quite a long time.
# pg_dump -h [ZABBIX SERVER] -U [ZABBIX DB USER] > /tmp/zabbix_dump.sql
After the dump completes, I’ll use
psql to reload the data into a new database. This database will need to be created first via
psql or other postgresql administration means. I’m also creating the zabbix role when I create the database – update the password as necessary in the create role command.
I’m using psql in this example –
# sudo -u postgres psql
postgres=# create database zabbix;
postgres=# \c zabbix
postgres=# create role zabbix with password 'zabbix';
I’ve called the database zabbix in this example, so I’m loading the data from the
zabbix_dump.sql file into the
# sudo -u postgres psql -dzabbix -f /tmp/zabbix_dump.sql
You should get a whole lot of
ALTER TABLE and
CREATE TABLE lines appear on the screen while the data is loaded in.
After the data is loaded in, you will need to start Zabbix so that it recognises the data has been loaded in.
# systemctl start zabbix-server.service
Check the zabbix log file to ensure that Zabbix has started and has converted the DB
[TIMESTAMP] current database version (mandatory/optional): 02020000/02020001
[TIMESTAMP] required mandatory version: 03000000
[TIMESTAMP] starting automatic database upgrade
Once that has finished, we can move onto setting up the front end for the Zabbix server.
First thing we need to setup is the timezone for PHP. This is located in
/etc/php.ini. After modifying it, we need to restart Apache.
# sed -i 's/;date.timezone =/date.timezone = Australia\/Perth/' /etc/php.ini
# systemctl restart httpd.service
After that, we can set up the frontend via the web based wizard by navigating to the Zabbix Server in your browser.
Check through the pre-requisites to ensure that your Apache and PHP configuration settings is ok, then step through the rest of the configuration wizard.
After the configuration wizard is completed, you should be able to login to your new Zabbix 3 server with any logins that were present on the old instance!
The last thing to do is to copy any custom scripts, crontabs, etc, over from the old server. Make sure they’re copied to the same location on the new server and watch the magic happen.