我正在尝试设置MySQL复制。问题是必须在2个集群服务器之间进行复制,并且必须通过服务器的虚拟IP连接所使用的用户。
配置:
在/etc/hosts
- 两台服务器
# 10.0.1.34 - is the Virtual IP of the slave cluster
# 10.0.1.45 - is the virtual IP of the master cluster
10.0.1.34 mysqlslave
10.0.1.45 mysqlmaster
创建MySQL repl
用户并在两台服务器上授予访问权限
在主服务器上:
mysql -u root -pmy-password
mysql> CREATE USER 'repl'@'mysqlslave' IDENTIFIED BY 'my-password';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'mysqlslave';
mysql> GRANT ALL ON *.* TO 'repl'@'mysqlslave' IDENTIFIED BY 'my-password';
mysql> exit;
在Slave Server上:
mysql -u root -pmy-password
mysql> CREATE USER 'repl'@'mysqlmaster' IDENTIFIED BY 'my-password';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'mysqlmaster';
mysql> GRANT ALL ON *.* TO 'repl'@'mysqlmaster' IDENTIFIED BY 'my-password';
mysql> exit;
现在,当我尝试通过运行命令(在主服务器上)检查是否成功授予访问权限时:
mysql -u repl -pmy-password -h mysqlslave
我收到错误:
ERROR 1045 (28000): Access denied for user 'repl'@'10.0.1.46' (using password: YES)
其中10.0.1.46
是主群集主节点的IP。
为什么尝试连接时没有使用虚拟IP?
注意:如果我运行以下命令:
mysql -u repl -pmy-password -h mysqlslave --bind_address='10.0.1.45'
建立连接,但我想将此绑定用作默认值。我已经尝试更改bind-address
中的my.cnf
参数,但没有成功。
有什么想法吗?感谢。
答案 0 :(得分:0)
目前,解决方案是将所有群集IP添加到/etc/hosts
文件中:
10.0.1.34 mysqlslave
10.0.1.35 mysqlslave
10.0.1.36 mysqlslave
10.0.1.45 mysqlmaster
10.0.1.46 mysqlmaster
10.0.1.47 mysqlmaster
如果除了我发现的解决方案之外还有其他解决方案,请对其进行评论。