From f8aa35f9e1f5de09c5e8b266691a8212dfe06e47 Mon Sep 17 00:00:00 2001 From: RealStickman Date: Fri, 20 May 2022 21:24:09 +0200 Subject: [PATCH] (Grav GitSync) Automatic Commit from RealStickman --- .../20.mariadb-replication/default.en.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 pages/02.linux/20.mariadb-replication/default.en.md diff --git a/pages/02.linux/20.mariadb-replication/default.en.md b/pages/02.linux/20.mariadb-replication/default.en.md new file mode 100644 index 0000000..51ffb07 --- /dev/null +++ b/pages/02.linux/20.mariadb-replication/default.en.md @@ -0,0 +1,68 @@ +--- +title: 'MariaDB Replication' +--- + +## Master Slave Setup +### Master Configuration +The MariaDB Server has to be accessible from outside. For Debian, one has to comment `bind-address=127.0.0.1` in the file `/etc/mysql/mariadb.conf.d/50-server.cnf`. +If you have any firewall enabled, make sure to allow port 3306/TCP. + +Add this segment at the end of `/etc/mysql/my.cnf` +``` +[mariadb] +log-bin +server_id=1 +log-basename=master +binlog-format=mixed +``` +**Restart mariadb** now + +Create a replication user +``` +CREATE USER 'replication'@'%' IDENTIFIED BY ''; +GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%'; +``` + +Next we have to get the data necessary so the slave knows where to start replicating. +`FLUSH TABLES WITH READ LOCK;` +`SHOW MASTER STATUS;` +**Do not close this session, keep it running until you have made the backup from the next step** +`# mysqldump -u root -p (db name) > db_name.sql` + +You can unlock the database again. +`UNLOCK TABLES;` + +### Slave Configuration +Edit your `/etc/mysql/my.cnf` file +Make sure to choose different IDs for every host +``` +[mysqld] +server-id = 2 +``` + +Create the database and restore the sql dumps made earlier. +`# mysql -u root -p (db name) < db_name.sql` + +Set the database master now +``` +CHANGE MASTER TO + MASTER_HOST='', + MASTER_USER='replication', + MASTER_PASSWORD='', + MASTER_PORT=3306, + MASTER_LOG_FILE='', + MASTER_LOG_POS=, + MASTER_CONNECT_RETRY=10, + MASTER_USE_GTID = slave_pos; +``` + +Start slave now +`START SLAVE;` +And check the status +`SHOW SLAVE STATUS \G` + +If both of the following options say yes, everything is working as intended +``` +Slave_IO_Running: Yes +Slave_SQL_Running: Yes +``` \ No newline at end of file