WIUNIX ACADEMY
Install MariaDB primary-replica replication with GTID and TLS
Build a fresh primary and read-only replica, seed a consistent InnoDB dataset, secure the channel with verified TLS and prove that new transactions arrive.
Make this guide yoursYOUR SYSTEM. YOUR STEPS.
Where are you working?
Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.
USE YOUR OWN VALUES
Configure this tutorial
Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.
Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.
Set values for my environment3 editable values
THE OUTCOME
What will you have at the end?
A dedicated fresh primary and read-only replica with a consistent seed, verified TLS and demonstrated post-seed transaction delivery.
Supported operating systems and versions
Thirteen environment paths reviewed against official documentation on 2026-11-05; no fresh full distro installation matrix. Historical evidence concerns two extracted MariaDB 10.11.14 instances in an isolated network namespace on Ubuntu 24.04.4 only. It does not test host installation, systemd, firewall, private DNS or organizational PKI. Use identical distro packages on both disposable VMs; Arch and Manjaro branches can differ. Illustrative teaching photographs.
Before you begin
- Two fresh systemd hosts on the same reviewed OS and MariaDB package version; sudo/SSH, private addresses, synchronized clocks, minimum 2GB RAM each and capacity for database/logs/backups.
- Existing default-deny private firewall/ACL, verified SSH host keys and internal DNS for db-primary.example.internal. No public3306 access.
- Existing trusted PKI: primary serverAuth certificate with matching DNS SAN/key and CA chain; public CA chain on replica. Secret manager and protected terminal. No application writer until verification.
One writer, one asynchronous copy
Build a dedicated two-node lab: primary 10.20.0.10 (server_id 101), replica 10.20.0.11 (102), domain 0 on both, TCP 3306 only on the private network. Only the primary accepts application writes. The replica receives binary logs over verified TLS and applies them independently. A commit can be acknowledged before it reaches the replica; this is neither synchronous HA nor a backup. Accidental deletes also replicate.
Agree the boundary before installation
Use two fresh disposable VMs on the SAME selected OS release and identical MariaDB package versions. No existing MySQL/MariaDB installation, user database, replication channel or application writer may be present. This guide seeds only academy_lab on dedicated instances; it does not migrate production data or copy users/system schemas. Stop on retained state; do not delete it to pass a guard.
LET’S BUILD
Inspect both fresh hosts
On both hosts, as your existing sudo administrator. The guard aborts on an installed server or retained data/configuration. Do not remove an existing directory to make it pass. Confirm OS, architecture, private addresses, time synchronization and free space; allow at least 2GB RAM and 10GB free for this small lab, plus room for logs, seed and backups.
Both fresh hosts; Bash as existing sudo administrator.
(
set -euo pipefail
. /etc/os-release
printf '%s %s\n' "$ID" "$VERSION_ID"
uname -m
ip -br address
timedatectl status
df -h / /var
installed=$(pacman -Qq)
if printf '%s\n' "$installed" | grep -Ei '^(mariadb|mysql|percona-server)(-.*)?$' >/dev/null; then
echo 'Existing database package: STOP' >&2; exit 1
fi
for path in /var/lib/mysql /var/lib/mariadb /etc/my.cnf /etc/my.cnf.d /etc/mysql /etc/mariadb /root/academy-seed /root/.my.cnf; do
if sudo test -e "$path" || sudo test -L "$path"; then echo "Existing state: $path; STOP" >&2; exit 1; fi
done
systemctl list-unit-files 'mariadb*' 'mysql*' --no-pager
sudo ss -lntp 'sport = :3306'
)
Both hosts are fresh, addresses are assigned, clocks synchronized and resources sufficient.
LET’S BUILD
Restrict the primary port before exposing it
Arch/Manjaro has no mandated firewall manager. This lab path uses an ALREADY active UFW with default-deny incoming, preserved SSH and an equivalent upstream private ACL. If the lab uses nftables/firewalld instead, have that existing policy owner apply the equivalent source/destination TCP3306 rule; do not install/switch a firewall to run this panel. Change ens18 to the actual private interface. Inspect existing broad allows: a narrow added rule does not undo them.
Primary
(
set -euo pipefail
state=$(sudo env LC_ALL=C ufw status verbose)
printf '%s\n' "$state"
printf '%s\n' "$state" | grep -E '^Status: active$' >/dev/null
printf '%s\n' "$state" | grep -F 'Default: deny (incoming)' >/dev/null
sudo ufw allow in on ens18 from 10.20.0.11 to 10.20.0.10 port 3306 proto tcp
sudo ufw status numbered
)
Active default-deny firewall; only the replica can reach the primary private3306 port.
LET’S BUILD
Install this release’s signed packages
On both disposable VMs, review the full pacman transaction, including whole-system updates. Reboot if required by a kernel or system-component update and then recheck addresses and time. Initialize only a datadir without any existing entries. First create z0-academy-loopback.cnf for a loopback-only listener; the later role file zz-academy-replication.cnf sorts after normal vendor files and this bootstrap include.
Manjaro rolling reviewed 2026-11-05; no fixed ISO version. Arch Extra lists MariaDB 13.0.2-2 at review; Manjaro branches can lag and must be checked locally. Run a full synchronized upgrade on these disposable VMs, never a partial upgrade. Packages mariadb/mariadb-clients; /usr/bin/mariadbd; mysql user/group; explicit mariadb-install-db before first service start; include /etc/my.cnf.d, datadir /var/lib/mysql. Both nodes must use the same branch and exact versions, not one Arch and one Manjaro node. Review current MariaDB maintenance before choosing a rolling deployment.
Both fresh hosts; Bash as existing sudo administrator.
(
set -euo pipefail
sudo pacman -Syu --needed mariadb mariadb-clients openssl ca-certificates nano
pacman -Q mariadb mariadb-clients
sudo bash -eu <<'LOOPBACK'
set -o noclobber
test -d /etc/my.cnf.d
test ! -L /etc/my.cnf.d
umask 022
cat > /etc/my.cnf.d/z0-academy-loopback.cnf <<'CONFIG'
[mariadb]
bind_address=127.0.0.1
CONFIG
chmod 0644 /etc/my.cnf.d/z0-academy-loopback.cnf
LOOPBACK
if sudo test -d /var/lib/mysql; then
test -z "$(sudo find /var/lib/mysql -mindepth 1 -maxdepth 1 -print -quit)"
fi
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo /usr/bin/mariadbd --verbose --help >/dev/null
sudo systemctl enable --now mariadb
sudo mariadb -NBe 'SELECT VERSION();'
sudo ss -lntp 'sport = :3306'
)
Same supported series and exact package version on both hosts; initial3306 is loopback only.
Provide an existing private-CA server certificate
Before the next commands, your PKI administrator must deliver ca.pem, primary-fullchain.pem and primary-key.pem into a root-only academy-pki directory on the primary. The leaf is for serverAuth, valid now, with SAN DNS:db-primary.example.internal and its matching unencrypted service key; the fullchain includes intermediates. Keep the CA signing key offline and out of BOTH database hosts. Deliver the SAME public CA chain as ca.pem on the replica. Certificate issuance/renewal is an existing PKI responsibility, not a self-signed certificate bypass. Verify fingerprints through a trusted channel. Do not proceed with missing, expired or mismatched files.