mysql ab复制 aa复制_MySQL 主主复制

环境

服务器

两台 centos6.5 (ip:192.168.1.121、192.168.1.212)

软件

mysql5.6

haproxy-1.5.14

keepalived-1.2.19

步骤

在两台服务器上分别安装mysql环境(完全相同的安装即可)

在线安装流程:参考 官方文档 中文文档

注:本文中的例子使用的mysql5.6,目前不确定该配置流程在mysql5.7上是不是好使的,貌似5.7对主从复制这块有优化,大家可以自行尝试一下。)

配置mysql主主复制(参考 http://www.cnblogs.com/phpstudy2015-6/p/6485819.html#_label7)

何为主主复制:就是两个mysql都能读能写,数据记录通过二进制传达给对方从而保持数据的一致性。

实现:

192.168.1.121(主)+192.168.1.212(从) 主从复制 +

192.168.1.212(主)+192.168.1.121(从) 主从复制 =

192.168.1.121+192.168.1.212 主主复制。

2.1. 修改mysql配置文件

shell> sudo vim /etc/my.cnf

192.168.1.121 mysql配置文件内容:

[mysqld]

server-id=1 #任意自然数n,只要保证两台MySQL主机不重复就可以了。

log-bin=mysql-bin #开启二进制日志

auto_increment_increment=2 #步进值auto_imcrement。一般有n台主MySQL就填n

auto_increment_offset=1 #起始值。一般填第n台主MySQL。此时为第一台主MySQL

binlog-ignore=mysql #忽略mysql库【我一般都不写】

binlog-ignore=information_schema #忽略information_schema库【我一般都不写】

#replicate-do-db=aa #要同步的数据库,默认所有库

192.168.1.212 mysql配置文件内容:

[mysqld]

#mysql负载均衡配置

server-id=2

log-bin=mysql-bin

auto_increment_increment=2 #步进值auto_imcrement。一般有n台主MySQL就填n

auto_increment_offset=2 #起始值。一般填第n台主MySQL。此时为第二台主MySQL

#replicate-do-db=aa #要同步的数据库,默认所有库

两台服务器的配置文件修改好后均重启mysql服务。

2.2. 配置192.168.1.121(主)+192.168.1.212(从) 主从复制

使用root用户登录192.168.1.121主机的mysql,创建一个可以从192.168.1.212登录的mysql用户并授权。

mysql> create user 'mysql212'@'192.168.1.212' identified by 'password';

mysql> GRANT REPLICATION SLAVE ON *.* TO ‘mysql212’@’192.168.1.121’ IDENTIFIED BY 'password';

mysql> FLUSH PRIVILEGES;

查看192.168.1.121 mysql服务器二进制日志

mysql> show master status\G

*************************** 1. row ***************************

File: mysql-bin.000076

Position: 1173222

Binlog_Do_DB:

Binlog_Ignore_DB:

Executed_Gtid_Set:

1 row in set (0.00 sec)

告知从服务器主服务器的二进制文件名和位置

使用root用户登录192.168.1.212主机的mysql,在192.168.1.121中执行:

mysql> change master to

-> master_host='192.168.1.121',

-> master_user='mysql212',

-> master_password='password',

-> master_log_file='mysql-bin.000076',

-> master_log_pos=1173222;

192.168.1.212服务器开启复制:

mysql> start slave;

查看主从复制是否配置成功

mysql> show slave status\G

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.1.121

Master_User: mysql212

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000076

Read_Master_Log_Pos: 1173222

Relay_Log_File: bogon-relay-bin.000006

Relay_Log_Pos: 1173385

Relay_Master_Log_File: mysql-bin.000076

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: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 1173222

Relay_Log_Space: 1173721

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

Last_IO_Errno: 0

Last_IO_Error:

Last_SQL_Errno: 0

Last_SQL_Error:

Replicate_Ignore_Server_Ids:

Master_Server_Id: 1

Master_UUID: e69cc9bd-109e-11e5-b9e7-00e066233823

Master_Info_File: /var/lib/mysql/master.info

SQL_Delay: 0

SQL_Remaining_Delay: NULL

Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

Master_Retry_Count: 86400

Master_Bind:

Last_IO_Error_Timestamp:

Last_SQL_Error_Timestamp:

Master_SSL_Crl:

Master_SSL_Crlpath:

Retrieved_Gtid_Set:

Executed_Gtid_Set:

Auto_Position: 0

1 row in set (0.00 sec)

当看到Slave_IO_Running: YES、Slave_SQL_Running: YES才表明状态正常。

2.3. 配置192.168.1.212(主)+192.168.1.121(从) 主从复制

步骤同2.2。

2.4. 测试主主复制配置是否成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值