Mysql一主多从复制数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql一主多从复制数据相关的知识,希望对你有一定的参考价值。
应用场景:外部仅仅访问主数据库(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一主多从复制数据的主要内容,如果未能解决你的问题,请参考以下文章