<*_USERNAME>
and
<*_PASSWORD>
, enter your actual username and
password.Run the following commands on both the master and backup nodes to install and start the MariaDB service.
dnf install -y mariadb-server
mkdir -p /var/lib/mysql/
chown -R mysql:mysql /var/lib/mysql/
systemctl start mysql
mkdir -p /var/lib/mysql/binlogs
mkdir -p /var/lib/mysql/relaylogs
chown -R mysql:mysql /var/lib/mysql/binlogs /var/lib/mysql/relaylogs
/etc/my.cnf
file on the master node[mysqld]
datadir = /var/lib/mysql/
log-bin = /var/lib/mysql/binlogs/master-bin
relay-log = /var/lib/mysql/relaylogs/relay-bin
auto_increment_increment = 2
auto_increment_offset = 1
server-id = 131
log-error = /var/lib/mysql/mariadb.err
log-slave-updates = on
expire-logs-days = 14
sync-binlog = 1
binlog_do_db=slurm_acct_db
binlog_do_db=slurm_jobcomp_db
binlog_do_db=lico
/etc/my.cnf
file on the backup node[mysqld]
datadir = /var/lib/mysql/
log-bin = /var/lib/mysql/binlogs/backup-bin
relay-log = /var/lib/mysql/relaylogs/relay-bin
auto_increment_increment = 2
auto_increment_offset = 2
server-id = 132
log-error = /var/lib/mysql/mariadb.err
log-slave-updates = on
expire-logs-days = 14
sync-binlog = 1
binlog_do_db=slurm_acct_db
binlog_do_db=slurm_jobcomp_db
binlog_do_db=lico
systemctl restart mariadb
on master node
mysql
CREATE USER 'rep_master'@'%' IDENTIFIED BY '<PASSWORD>';
grant all privileges on *.* to 'rep_master'@'%' identified by '<PASSWORD>';
flush privileges;
exit
on backup node
mysql
CREATE USER 'rep_backup'@'%' IDENTIFIED BY '<PASSWORD>';
grant all privileges on *.* to 'rep_backup'@'%' identified by '<PASSWORD>';
flush privileges;
exit
mysql
show master status;
exit;
Note: Change the <DB_NAME>
to the name of
the databases you need to synchronize, each database name needs to be
executed once.
mkdir -p /var/lib/mysql/backup
mysqldump -u<USERNAME> -p<PASSWORD> --databases <DB_NAME> > /var/lib/mysql/backup/<DB_NAME>.sql
Note: Change the <DB_NAME>
to the name of
the databases you need to synchronize, each database name needs to be
executed once.
scp -r root@<MASTER_IP>:/var/lib/mysql/backup /var/lib/mysql/
mysql
source /var/lib/mysql/backup/<DB_NAME>.sql;
exit;
on master node
mysql
grant replication slave on *.* to 'rep_backup'@'<BACKUP_IP>' identified by '<PASSWORD>';
flush privileges;
exit;
systemctl restart mariadb
on backup node
mysql
grant replication slave on *.* to 'rep_master'@'<MASTER_IP>' identified by '<PASSWORD>';
flush privileges;
exit;
systemctl restart mariadb
on master node
mysql
stop slave;
change master to
master_host='<BACKUP_IP>',
master_port=3306,
master_user='rep_backup',
master_password='<PASSWORD>',
master_log_file='<BACKUP_BINLOG_FILENAME>',
master_log_pos=<BACKUP_BINLOG_POSITION>;
start slave;
show slave status\G
exit;
on backup node
mysql
stop slave;
change master to
master_host='<MASTER_IP>',
master_port=3306,
master_user='rep_master',
master_password='<PASSWORD>',
master_log_file='<MASTER_BINLOG_FILENAME>',
master_log_pos=<MASTER_BINLOG_POSITION>;
start slave;
show slave status\G
exit;
Slave_IO_Running
and Slave_SQL_Running
fields are YES or notdnf install -y keepalived
/etc/keepalived/keepalived.conf
file on the master
node add the following contentvrrp_script check_mariadb {
script "</dev/tcp/127.0.0.1/3306"
interval 5
weight -2
}
vrrp_instance VI_MARIADB {
state MASTER
interface <INTERFACE_NAME>
virtual_router_id 61
priority 100
advert_int 1
virtual_ipaddress {
<VIRTUAL_IP>
}
track_script {
check_mariadb
}
}
/etc/keepalived/keepalived.conf
file on the backup
node add the following contentvrrp_script check_mariadb {
script "</dev/tcp/127.0.0.1/3306"
interval 5
weight -2
}
vrrp_instance VI_MARIADB {
state BACKUP
interface <INTERFACE_NAME>
virtual_router_id 61
priority 99
advert_int 1
virtual_ipaddress {
<VIRTUAL_IP>
}
track_script {
check_mariadb
}
}
systemctl enable keepalived
systemctl start keepalived
systemctl status keepalived