环境

Ubuntu 14.04.4 LTS *3 分别是master1(192.168.42.28), master2(192.168.42.29), slave1(192.168.42.33)测试下只有master1有从

配置

vim /etc/mysql/my.cnf
#必要的配置
[mysqld]
...
bind-address = 0.0.0.0
#3台主机的id分别是 ,,
server-id = binlog-do-db=test #需要记录二进制日志的数据库.如果有多个数据库可用逗号分隔,或者使用多个binlog-do-db选项
#需要同步的数据库
replicate-do-db=test #需要进行同步的数据库.如果有多个数据库可用逗号分隔,或者使用多个binlog-do-db选项 log_bin = /var/log/mysql/mysql-bin.log
#这很主要,不然没办法做主从
log-slave-updates
...

同步数据

我使用的是 innobackupex 同步,也可以mysqldump。 
master1 master2 slave1都需要同步

master1 配置

#给master2权限
grant replication slave,file on *.* to 'slave'@'192.168.42.29' identified by '';
#给slave1权限
grant replication slave,file on *.* to 'slave'@'192.168.42.33' identified by ''; stop slave;
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin. | | test | |
+------------------+----------+--------------+------------------+ change master to master_host='192.168.42.29',master_user='slave',master_password='',master_log_file='mysql-bin.000008', master_log_pos=,master_connect_retry=; #mysql-bin.000008和267是master2的状态
#参数
#master_connect_retry默认60秒,重连的时间,如果断开就60秒从试,直到链接上
#master_log_pos,master_log_file为复制主机的show master status的值 #启动复制
start slave;
#查看状态
show slave status\G; *************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.42.29
Master_User: slave
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysqld-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes #显示YES配置成功
Slave_SQL_Running: Yes
Replicate_Do_DB: test
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
row in set (0.00 sec)

master2 配置

#给master2权限
grant replication slave,file on *.* to 'slave'@'192.168.42.28' identified by ''; stop slave;
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin. | | test | |
+------------------+----------+--------------+------------------+ change master to master_host='192.168.42.28',master_user='slave',master_password='',master_log_file='mysql-bin.000007', master_log_pos=;
#启动复制
start slave;
#查看状态
show slave status\G; *************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.42.28
Master_User: slave
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysqld-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:

slave1 配置

stop slave; 

change master to master_host='192.168.42.28',master_user='slave',master_password='',master_log_file='mysql-bin.000007', master_log_pos=; 

show slave status\G  

*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.42.28
Master_User: slave
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysqld-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:

测试

分别在master1,master2 插入数据,在查看3个主机的数据

mysql 主主+主从笔记的更多相关文章

  1. MYSQL的主从和主主复制模式

    一.复制介绍 MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护文件的一个索引以跟踪日志循环.这些日志可以记录 ...

  2. mysql的主从配置以及主主配置

    基础环境 系统:linuxmysql版本:5.5主服务器IP:192.168.1.101从服务器IP:192.168.1.102 1.主服务器(master)要打开二进制日志2.从服务器(slave) ...

  3. MySQL 主主同步配置和主从配置步骤

    ★预备知识 : 1.双机热备 对于双机热备这一概念,我搜索了很多资料,最后,还是按照大多数资料所讲分成广义与狭义两种意义来说. 从广义上讲,就是对于重要的服务,使用两台服务器,互相备份,共同执行同一服 ...

  4. 学一点 mysql 双机异地热备份----快速理解mysql主从,主主备份原理及实践

    双机热备的概念简单说一下,就是要保持两个数据库的状态 自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致. 这样做的好处多. 1. 可以做灾备,其中一个坏了可以切换 ...

  5. Mysql主从备份、主主备份

    简单介绍mysql双机,多机异地热备简单原理实战. 双机热备的概念简单说一下,就是要保持两个数据库的状态自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致. 这样做 ...

  6. mysql主从配置主主配置

    一.     概述  MySQL从3.23.15版本以后提供数据库复制(replication)功能,利用该功能可以实现两个数据库同步.主从模式.互相备份模式的功能.本文档主要阐述了如何在linux系 ...

  7. MYSQL主从同步/主主同步

    一.MYSQL主从同步 注意:进行主从同步操作时需要确保DB无写操作 flush tables with read lock:   //全局读锁定,执行了命令之后所有库所有表都被锁定只读. 1.在主机 ...

  8. MySQL主从及主主环境部署

    主从同步 主机环境 mysql的安装可以参考:https://www.cnblogs.com/brianzhu/p/8575243.htmlCentos7版本master:192.168.192.12 ...

  9. Mysql主从同步(1) - 概念和原理介绍 以及 主从/主主模式 部署记录

    Mysql复制概念Mysql内建的复制功能是构建大型高性能应用程序的基础, 将Mysql数据分布到多个系统上,这种分布机制是通过将Mysql某一台主机数据复制到其它主机(slaves)上,并重新执行一 ...

  10. 学一点 MYSQL 双机异地热备份—-MYSQL主从,主主备份原理及实践

    简单介绍mysql双机,多机异地热备简单原理实战. 双机热备的概念简单说一下,就是要保持两个数据库的状态自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始终保持两个数据库数据一致. 这样做 ...

随机推荐

  1. SpringBoot Actuator

    SpringBoot Actuator 提供了检查项目内部信息的一整套API,通常在项目启动时可以看到. 1.引入依赖包 <dependency> <groupId>org.s ...

  2. Android : 高通平台Camera调试之SetpropKey/camxoverridesettings.txt

    高通相关网址:Createpoint: https://createpoint.qti.qualcomm.com(可下载文档,Release Note等)Chipcode: https://chipc ...

  3. 搭建SSH框架心得

    <Struts2+Spring4+hibernate3> 工程结构 导入相关jar包:自行网上百度即可,根据环境需要 写dao类 以及实现 package com.icommon.dao; ...

  4. windows环境搭建nginx

    1.下载安装nginx 2.启动nginx:点击nginx.exe文件,cmd,进入nginx根目录,执行start nginx 2.修改nginx配置文件nginx.conf 修改配置文件中serv ...

  5. springboot - websocket实现及原理

    本文章包括websocket面试相关问题以及spring boot如何整合webSocket. 参考文档 https://blog.csdn.net/prayallforyou/article/det ...

  6. Maven中添加镜像

    Maven库在天朝的下载速度实在是感人,所以添加镜像之后速度会提升很多. 在maven的settings.xml 文件里配置mirrors的子节点,添加如下mirror <mirror> ...

  7. css清除浮动方式总结

    1.通过父元素overflow:hidden,缺点:超出部分隐藏,不推荐使用 <!DOCTYPE html> <html lang="en"> <he ...

  8. linux启动流程的理解

    1.bios 2.grub 选择 3.内核自解压vmlinux 4.内核引导的模式与变量(引导期内存分页映射)设置 #汇编级 5.内核内存再分页(内存空间映射),宏定义与设置,初始化consol,启动 ...

  9. 使用VS调试DUMP文件

    使用前准备: 1.保存编译文件的PDB文件(要和生成exe文件的对应) 2.在开发机器上,使用vs直接双击打开dmp文件,注意 进程名称 ,这个是程序运行crash的时候所在的目录位置,这个很重要. ...

  10. 微信小程序调用快递物流查询API的实现方法

    一. 创建index.wxml.index.wxss.index.js 附上代码: <view class='container'> <input class='info' plac ...