mysql+AA主主
mysql主主(AA)
实验环境
master-1 192.168.3.1
master-2 192.168.3.10
关闭防火墙(两台)
[root@master-1 ~]# service iptables stop
[root@master-1 ~]# setenforce 0
设置密码
[root@master-1 ~]# mysqladmin -u root password 123456
一、master-1操作
(1)安装ntp时间服务器
[root@master-1 ~]# yum -y install ntp
[root@master-1 ~]# vim /etc/ntp.conf
server 127.127.1.0
fudge 127.127.1.0 stratum 8
[root@master-1 ~]# service ntp restart
(2)修改配置文件
[root@master-1 ~]# vim /etc/my.cnf
[mysqld]
server-id=1
log-bin=mysql-binlog
[root@master-1 ~]# service mysqld restart
(3)授权用户
[root@master-1 ~]# mysql -u root -p123456
mysql>
mysql> grant replication slave on *.* to ‘slave‘@‘192.168.3.10‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
(4)导出数据
[root@master-1 ~]# mysqldump -u root -p123456 --all-databases > /root/alldb.sql
[root@master-1 ~]# scp /root/alldb.sql [email protected]:/root
二、master-2操作
(1)时间同步
[root@master-2 ~]# yum -y install ntpdate
[root@master-2 ~]# usr/sbin/ntpdate 192.168.3.10
[root@master-2 ~]# service ntpd restart
(2)修改配置文件
[root@master-2 ~]# vim /etc/my.cnf
[mysqld]
server-id=2
log-bin=mysql-binlog
[root@master-2 ~]# service mysqld restart
(3)授权用户
[root@master-1 ~]# mysql -u root -p123456
mysql>
mysql> grant replication slave on *.* to ‘master‘@‘192.168.3.1‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
(4)导出数据
[root@master-1 ~]# mysqldump -u root -p123456 --all-databases > /root/alldba.sql
[root@master-1 ~]# scp /root/alldba.sql [email protected]:/root
三、master-1操作
[root@master-1 ~]# mysql -u root -p123456
mysql> show master status;
+---------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-binlog.000001 | 337 | | |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
四、master-2操作
[root@master-2 ~]# mysql -u root -p123456
mysql> change master to
-> master_host=‘192.168.3.1‘,
-> master_user=‘slave‘,
-> master_password=‘123456‘,
-> master_log_file=‘mysql-binlog.000001‘,
-> master_log_pos=337;
Query OK, 0 rows affected (0.06 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+---------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+--------------+------------------+
| mysql-binlog.000001 | 336 | | |
+---------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
五、master-1操作
[root@master-1 ~]# mysql -u root -p123456
mysql> change master to
-> master_host=‘192.168.3.10‘,
-> master_user=‘master‘,
-> master_password=‘123456‘,
-> master_log_file=‘mysql-binlog.000001‘,
-> master_log_pos=336;
Query OK, 0 rows affected (0.06 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
六、分别master-1 和 master-2上面查看sql/io线程是否开启
(1)master-1查看
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.10
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-binlog.000001
Read_Master_Log_Pos: 417
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 335
Relay_Master_Log_File: mysql-binlog.000001
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: 417
Relay_Log_Space: 491
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:
1 row in set (0.00 sec)
(2)master-2查看
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.3.1
Master_User: myslave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-binlog.000001
Read_Master_Log_Pos: 785
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 702
Relay_Master_Log_File: mysql-binlog.000001
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: 785
Relay_Log_Space: 858
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:
1 row in set (0.00 sec)
注:两端都为Yes 则成功
七、测试
1、在master-1查看库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.07 sec)
2.在master-2上面查看库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
注:两台数据一模一样,我们现在在master-1上面创建一个库,看能否同步
3、在master-1创建库
mysql> create database fuzhenyang;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| fuzhenyang |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql>
4、我们在master-2上面查看是否同步过来了
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| fuzhenyang |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql>
此时我们已经看到fuzhenyang库已经同步过来了
同样操作在master-2上面创建库看是否在master-1上面同步 如果能,mysql主从(AA)实验完毕
本文出自 “空怀感” 博客,转载请与作者联系!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。