使用虚拟IP在群集服务器上进行MySQL复制

时间:2014-07-15 09:02:44

标签: mysql database-replication

我正在尝试设置MySQL复制。问题是必须在2个集群服务器之间进行复制,并且必须通过服务器的虚拟IP连接所使用的用户。

配置:

  1. /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
    
  2. 创建MySQL repl用户并在两台服务器上授予访问权限

    1. 在主服务器上:

       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;
      
    2. 在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;
      
  3. 现在,当我尝试通过运行命令(在主服务器上)检查是否成功授予访问权限时:

    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参数,但没有成功。

    有什么想法吗?感谢。

1 个答案:

答案 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

如果除了我发现的解决方案之外还有其他解决方案,请对其进行评论。