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

原文地址:http://blog.51cto.com/hbgslz/2071431

时间: 2024-08-04 15:24:24

Mysql一主多从复制数据的相关文章

Mysql双主多从复制数据

应用场景:需要高并发且无间断访问数据库时,可使用双主多从数据库集群 实验架构: 实验环境: 关闭firewalld和selinux防火墙 操作系统版本:CentOS7 DB1:192.168.1.104 DB2:192.168.1.45 DB3:192.168.1.73 DB4:192.168.1.90 实验步骤: 注意:整个实验过程都是在重复配置Mysql主从配置,只是主从顺序不一样罢了 01.登录到DB1-DB4,安装mariadb.mariadb-server #安装Mariadb yum

Mysql之一主多从复制

MySQL主从复制 简介 将master数据库中的DDL和DML操作通过二进制日志(BINLOG)传输到slave数据库上,然后将这些日志重新执行(重做):从而使得slave数据库的数据与master数据库保持一致. MySQL数据库自身提供的主从复制功能可以方便的实现数据的多处自动备份,实现数据库的拓展.多个数据备份不仅可以加强数据的安全性,通过实现读写分离还能进一步提升数据库的负载性能. 目录 一.主从原理 1.1 主从复制基本原理 1.2 主从复制原理运行流程 二.主从用途 2.1 主从复

MySQL一主二从复制环境切换主从库

假设有一个一主二从的环境,当主库M出现故障时,需要将其中一个从库S1切换为主库,同时将S2指向新的主库S1,如果可能,需要将故障的主库M修复并重置为新的从库. 搭建一主二从复制环境可参考:mysql5.7主从复制配置——读写分离实现. 1.环境信息:Mater:130.168.0.25Slave1:130.168.0.13Slave2:130.168.0.27 2.配置MySQL一主二从2.1.查询master(主服务器)的状态show master status; 2.2.配置slave1(从

keepalived+mysql双主复制高可用方案

MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了双主对外的统一接口以及自动检查.失败切换机制.联合使用,可以实现MySQL数据库的高可用方案. 实验环境:OS:centos 6.x x86_64系统MySQL版本: :mysql 5.6.22   64 位A: master :192.168.79.3 3306B: slave :192.168.

怎么设置 mysql 多主复制

更新 其实本文主要来自www.digitalocean.com ,但是我没有买他们家的 VPS 用来 demo 了.只是用vagrant 来模拟了. 介绍 说说关于通过两台 vps 来扩展 mysql. 之前我们说到了在2台 vps 直接通过nginx 来设置负载均衡, 你可以读读它 所谓 Mysql 的复制就是实时的把单一的数据集复制到另外一台服务器上. 这个配置称之为主从复制. 这是一个典型的操作配置. 我们接下来会有一个更加好的方案来实现. 以为多主(主-主)复制能够允许数据拷贝到的其他的

MySQL中快速复制数据表方法汇总

本文将着重介绍两个MySQL命令的组合,它将以原有数据表为基础,创建相同结构和数据的新数据表. 这可以帮助你在开发过程中快速的复制表格作为测试数据,而不必冒险直接操作正在运行 的数据表. 示例如下: 将 production 数据库中的 mytbl 表快速复制为 mytbl_new,2个命令如下: CREATE TABLE mytbl_new LIKE production.mytbl; INSERT mytbl_new SELECT * FROM production.mytbl; 第一个命令

MariaDB、MySQL双主互备模型同步数据

MySQL双主互备即两台MySQL服务器同时是主服务器,而同时又是对方的从服务器,这样可以分担主服务器的一部分写请求,因为如果是单主模型的话数据写入只能写入在一台MySQL服务器,而双主模型则可同时写在两台服务器上,有效加快了写入的速度,而且还能提供数据的备份功能. 环境如下: server1:CentOS 6.5 x86_64 mariadb 10.0.10 IP:192.168.10.204 server2:CentOS 6.5 x86_64 mariadb 10.0.10  IP:192.

MySql --主从复制 主主复制

MySql 复制 系统的扩展方式有:scale up [向上扩展或是垂直扩展]  scale out:[向外扩展或是水平扩展] Mysql的复制就是为了实现mysql的水平扩展 为什么要实现水平扩展 当前端节点很少时可以用垂直扩展的方式进行换更好的硬件,但是这会有上限当达到一定的程度后就无法在继续扩展,同时这种扩展的方式成本会很高. 因此更好的办法还是进行水平扩展.来应对前方的压力.但是这对于mysql水平扩展有一个问题就是数据共享的问题. 共享存储的解决方案有NAS SAN 假设使用的是NAS

Mysql Group Replication 简介及单主模式组复制配置【转】

一 Mysql Group Replication简介 Mysql Group Replication(MGR)是一个全新的高可用和高扩张的MySQL集群服务. 高一致性,基于原生复制及paxos协议的组复制技术,以插件方式提供一致数据安全保证: 高容错性,大多数服务正常就可继续工作,自动不同节点检测资源征用冲突,按顺序优先处理,内置自动防脑裂机制: 高扩展性,自动添加移除节点,并更新组信息: 高灵活性,单主模式和多主模式.单主模式自动选主,所有更新操作在主进行:多主模式,所有server同时更