Skip to content

Instantly share code, notes, and snippets.

@gordyt
Created July 11, 2017 14:11
Show Gist options
  • Save gordyt/3848814b2ead70b02109290af7dcf592 to your computer and use it in GitHub Desktop.
Save gordyt/3848814b2ead70b02109290af7dcf592 to your computer and use it in GitHub Desktop.
Configure ZCS to run with external MariaDB

Configure ZCS to run with external MariaDB

Introduction

For this test I decided to start with a clean MariaDB install and initialize it with a backup from a current ZCS server. In the steps that follow:

  • ubuntu-test-1 will be the service that has a full ZCS install.
  • ubuntu-test-2 will be the database server.

ubuntu-test-1

Do a basic single-node install. Follow the instructions in MySQL Backup and Restore to enable binary logging and running a backup. They are summarized below.

ubuntu-test-2

Install and initialize MariaDB. Make note of the root password that you assign; however, it will change once we import the data from the ZCS backup.

sudo apt install mariadb-server
sudo /usr/bin/mysql_secure_installation

Update the following in /etc/mysql/mariadb.conf.d/50-server.cnf

  • Change port to 7306
  • Comment out bind-address

A note regarding starting and stopping MariaDB with a standard Ubuntu install. By default it will start MariaDB via the mysqld_safe command. This will require the use of the mysqladmin shutdown command to stop it, which the mysql script in /etc/init.d does do. However, the mysqladmin script requires the (MariaDB) root password to work. If you want this to work properly, update /etc/mysql/debian.cnf and add the root password, remembering that it will change once we restore from the backup of the ZCS database.

Restart the database.

ubuntu-test-1

Stop ZCS and copy the log-bin directory (/opt/zimbra/backup in our example) to the database server. I unpacked it to the same location on ubuntu-test-2.

Update localconfig to point to the new database server.

zmlocalconfig -e mysql_bind_address=ubuntu-test-2.local

Edit /opt/zimbra/bin/zmstorectl and remove mysql.server from START_ORDER and STOP_ORDER.

ubuntu-test-2

Restore the backup from the ZCS server:

sudo chmod -R a+r /opt/zimbra/backup
sudo mysql --user=root --password=ROOT-PW < /opt/zimbra/backup/full-backup.sql

Restart MariaDb. Remember that the root password is now the same as it was on the ZCS server.

ubuntu-test-1

Start ZCS.

MySQL Backup and Restore

Add the following config to /opt/zimbra/conf/my.conf. You can choose a different log-bin path if you like.

log-bin = /opt/zimbra/backup/mariadb
binlog-format = MIXED

Restart the store (zmstorectrl restart) and verify that binary logs are being created by listing the contents of the log-bin directory:

ls -l /opt/zimbra/backup
-rw-rw---- 1 zimbra zimbra 311 Jul 10 13:34 mariadb.000001
-rw-rw---- 1 zimbra zimbra  34 Jul 10 13:34 mariadb.index

Now run a full backup of the database:

source /opt/zimbra/bin/zmshutil
zmsetvars
/opt/zimbra/common/bin/mysqldump --user=root \
  --password=$mysql_root_password \
  --socket=$mysql_socket --all-databases \
  --single-transaction --master-data \
  --flush-logs > /opt/zimbra/backup/full-backup.sql
@gordyt
Copy link
Author

gordyt commented Jul 11, 2017

The above is just for a test. There are several additional items to consider, including (but not limited to):

  • Security audit. For example, update settings so that the zimbra account may only connect from approved servers.
  • Performance audit. Settings should be tweaked based on capabilities of the database server and the expected load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment