环境

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. typescript 关于class属性类型定义被属性默认值覆盖的问题及解决方式

    问题来源于 React.component的第二个参数的类型定义问题,我构建了以下简化demo,方便描述问题: class P<STATE> { public state: STATE; ...

  2. 【webpack学习笔记】a05-模块热替换

    什么是模块热替换? 这个功能会在程序运行过程中替换.添加或删除模块,而无需重新加载整个页面 有什么用呢? 保留在完全重新加载页面时丢失的应用程序状态. 只更新变更内容,以节省宝贵的开发时间. 调整样式 ...

  3. R语言预测实战(游浩麟)笔记1

    预测流程 确定主题.指标.主体.精度.周期.用户.成本和数据七要素. 收集数据.内容划分.收集原则. 选择方法.主要方法有自相关分析.偏相关分析.频谱分析.趋势分析.聚类分析.关联分析.相关分析.互相 ...

  4. 第四周博客之一---Linux的基本命令(前5个)

    一.Linux的系统结构 "/"根目录部分有以下子目录: 1./bin:系统启动时需要的执行文件(二进制),这些文件可以被普通用户使用. 2./boot:用于自举加载程序(LILO ...

  5. ECC算法软件保护中的应用

    椭圆曲线在软件注册保护的应用 我们知道将公开密钥算法作为软件注册算法的好处是Cracker很难通过跟踪验证算法得到注册机.下面,将简介一种利用Fp(a,b)椭圆曲线进行软件注册的方法. 软件作者按如下 ...

  6. Python基础-Python的三元运算符和lambda表达式

    1. Python的三元表达式: 现在大部分高级语言都支持 “?”这个三元运算符,它对应的表达式如下:condition ? value if true:value if else 但是 Python ...

  7. Spring源码学习(6)——容器的功能扩展

    之前的随笔中借BeanFactory介绍了bean的解析和加载的完整过程,实际上,除了BeanFactory,spring还提供了一种功能更加强大的容器:ApplicationContext Appl ...

  8. python之django基础

    看了不是同一期的视频,发现9期老师线性引入的方式,讲得django更加易于理解掌握. 抱歉的是,笔记没有整理就发上来了.希望看到的人不要被我带偏. 1. 新建Django项目 命令行创建: djang ...

  9. Ionic 2 + 手动搭建开发环境教程 【转】

    ionic简介 为什么选用ionic: 彻底开源且免费 性能优异 基于红的发紫的AngularJs 漂亮的UI 强大的命令行(基于更热门的nodejs) 开发团队非常活跃. ngCordova,将主流 ...

  10. json_encode 的局限 , 使用自定义的函数 .returnJson.

    $arr = array("liming", "tom", "green"); $arr2 = array( 1 => "l ...