1. 程式人生 > >Mysql一主多從復制數據

Mysql一主多從復制數據

sock 是否 art str cor term 數據庫 啟動 ado

應用場景:外部僅僅訪問主數據庫(Mysql_Master),多個從數據庫(Mysql_Slave)做數據庫熱備份。一旦主數據庫宕機,從服務器負責處理數據


實驗拓補圖:

技術分享圖片

實驗環境:

操作系統版本:CentOS7

Mysql_Master:192.168.199.17

Mysql_Slave01:192.168.199.18

Mysql_Slave02:192.168.199.19


實驗步驟:

01.依據以上環境,分別登錄到Mysql_Master、Mysql_Slave01、Mysql_Slave02三臺服務器,關閉firewalld和selinux防火墻,並配置IP、DNS、hostname等

Mysql_Master:

技術分享圖片

Mysql_Slave01:

技術分享圖片

Mysql_Slave02:

技術分享圖片

02.分別登錄到Mysql_Master、Mysql_Slave01、Mysql_Slave02三臺服務器,執行以下操作。

#安裝Mariadb

yum install mariadb-server mariadb -y

#設置Mariadb開機自動啟動服務


systemctl enable mariadb

#啟動Mariadb服務

systemctl start mariadb

#查看Mariadb服務是否正常運行

systemctl status mariadb


03.分別配置Mysql_Master、Mysql_Slave01、Mysql_Slave02三臺服務器的/etc/my.cnf文件

Mysql_Master:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
server-id=3
log-bin=mysql-bin
relay-log=mysql-relay-bin
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

Mysql_Slave01:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
server-id=2
log-bin=mysql-bin
relay-log=mysql-relay-bin
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

Mysql_Slave02:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

server-id=3
log-bin=mysql-bin
relay-log=mysql-relay-bin
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%


[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d





Mysql一主多從復制數據