1.1.3.1 mariadbreplication Debian 11 - sivasmartins/Documentos GitHub Wiki

MASTER/SLAVE

Install

aptitude install mariadb-server -y

Services

systemctl enable mariadb
systemctl status mariadb

Security

mysql_secure_installation

MASTER

Configuration

vim /etc/mysql/mariadb.conf.d/50-server.cnf

bind-address = 192.168.10.1    #192.168.10.1: local IP (Master)
server-id 	 = 1
log_bin	 = mysql-bin

Restart service

systemctl restart mariadb

Create replication

mysql -u root -p
mysql> CREATE USER 'replica'@'192.168.10.2' IDENTIFIED BY '123456'; #192.168.10.2: remote site - replication
mysql> GRANT REPLICATION SLAVE ON *.*TO 'replica'@'192.168.10.2';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;

Verification

mysql -u root -p
mysql> SHOW MASTER STATUS

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      795 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.000 sec)

SLAVE

Configuration

vim /etc/mysql/mariadb.conf.d/50-server.cnf

bind-address = 192.168.10.2  #192.168.10.2: Local IP (Slave)
server-id    = 2
log_bin      = mysql-bin

Restart service

systemctl restart mariadb

Configure slave

mysql -u root -p
mysql> STOP SLAVE;

mysql> CHANGE MASTER TO
     MASTER_HOST='192.168.10.1' ,  #192.168.10.1: Master IP
     MASTER_USER='replica' ,
     MASTER_PASSWORD='123456' ,
     MASTER_LOG_FILE='mysql-bin.000001' , #Information from: show master status
     MASTER_LOG_POS=795;

Start slave

mysql> START SLAVE;

TESTS

MASTER

mysql -u root -p
mysql> CREATE DATABASE replication_db;
mysql> show databases;

SLAVE

mysql -u root -p
mysql> show databases;