MYSQL搭建主从碰到的坑

刚来新公司不久,准备搭建个一主二从的mysql架构。

1,在虚拟机上新建三个虚拟机,分别是vm4  192.168.56.4(主), vm2  192.168.56.88(从),  vm3   192.168.56.100(从),系统都是redhat 6.5。数据库版本分别是 vm4: mysql  5.7.12, vm2 : mysql 5.7.12,  vm3:mysql5.6.23

2,从库也开binlog,不配置log_slave_updates参数(因为会变成主库)

3,按照常规步骤做完后,在从库上show slave status\G,看到Slave_IO_Running进程的状态是Connecting
错误是Last_IO_Error: error connecting to master 'root@192.168.56.4:3306' - retry-time: 30  retries: 1

从这里看不出来什么东西,所以查看错误日志。
错误日志如下
2017-06-22 10:50:27 2063 [ERROR] Slave I/O: error connecting to master 'root@192.168.56.4:3306' - retry-time: 30  retries: 1, Error_code: 2003
2017-06-22 10:50:27 2063 [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
2017-06-22 10:50:27 2063 [Note] Slave SQL thread initialized, starting replication in log 'binlog.000007' at position 450, relay log './vm3-relay-bin.000001' position: 4
发现是slave没有脸上master
在从库使用mysql -h 192.168.56.4 -P 3306 -uroot -p测试,发现确实是连不上master

4,百度错误号 Error_code: 2003,
网上说有以下几种可能
1),网络不通
2),密码不对
3),pos不对
4),防火墙没有关

我测试可以ping通,密码也对,pos也对。

5,我的问题是没有关闭防火墙,关闭防火墙后再次测试。
发现报错如下:
[root@vm4 ~]# mysql -h 192.168.56.100 -uroot -p
Enter password: 
ERROR 1130 (HY000): Host '192.168.56.4' is not allowed to connect to this MySQL server
原因是账号不允许从远程登录。

6,修改权限使账号可以从远程登录(每个节点都修改)
mysql> select host,user from mysql.user;
+----------------+-----------+
| host           | user      |
+----------------+-----------+
| 192.168.56.100 | repl      |
| 192.168.56.100 | root      |
| 192.168.56.88  | repl      |
| 192.168.56.88  | root      |
| localhost      | mysql.sys |
| localhost      | root      |
+----------------+-----------+
6 rows in set (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> select host,user from mysql.user;
+----------------+-----------+
| host           | user      |
+----------------+-----------+
| %              | root      |
| 192.168.56.100 | repl      |
| 192.168.56.100 | root      |
| 192.168.56.88  | repl      |
| 192.168.56.88  | root      |
| localhost      | mysql.sys |
| localhost      | root      |
+----------------+-----------+
7 rows in set (0.00 sec)

7,再次测试,slave_io和slave_sql都是yes状态,没有问题。搭建成功

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31447263/viewspace-2141123/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31447263/viewspace-2141123/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值