• MySQLfailover错误一则


    由于公司现有主库要转移到新的主库上,所以,我打算利用MySQLfailover工具的故障转移。

    1、开发把程序账号转移到新主库上

    2、停止现有主库,使之进行故障转移,转移期间会自动锁表,保持数据一致性。

    3、查看转移状态,检查是否转移成功

    在启动MySQLfailover的时候,报错:

    The master and one of the candidates are the same host and port.

    大概意思是说主库和候选机使用了相同的端口和host。

    检查MySQLfailover源码:

    # Parse the master, slaves, and candidates connection parameters
    try:
      master_val, slaves_val, candidates_val = parse_topology_connections(
        opt)
      except UtilRplError:
        _, e, _ = sys.exc_info()
        print("ERROR: {0}".format(e.errmsg))
        sys.exit(1)

      # Check hostname alias
        for slave_val in slaves_val:
          if check_hostname_alias(master_val, slave_val):
          parser.error("The master and one of the slaves are the same "
            "host and port.")
        for cand_val in candidates_val:
          if check_hostname_alias(master_val, cand_val):
          parser.error("The master and one of the candidates are the same "
            "host and port.")

     这段是报错的代码,可以看到是一段异常捕获代码,这里调用了check_hostname_alias()这个函数。查找开头引用:

      from mysql.utilities.common.server import check_hostname_alias

    可以看到是引用了server文件里的check_hostname_alias方法。进入common目录下查看:

    /usr/lib/python2.6/site-packages/mysql/utilities/common

    查看server.py文件:

    def check_hostname_alias(server1_vals, server2_vals):

      server1_vals[in] connection dictionary for server1
      server2_vals[in] connection dictionary for server2

      Returns bool - true = server1 and server2 are the same host
        """
      server1 = Server({'conn_info': server1_vals})
      server2 = Server({'conn_info': server2_vals})
      server1_socket = server1_vals.get('unix_socket', None)
      server2_socket = server1_vals.get('unix_socket', None)
      if server1_socket:
        server1.connect()
        server1.disconnect()
      if server2_socket:
        server2.connect()
        server2.disconnect()

      return (server1.is_alias(server2.host) and
        int(server1.port) == int(server2.port))

    可以看出,这段代码主要是检查主库和候选机的端口和host,如果相同,则返回一个true。

    如果返回true,则会触发到异常捕获代码,从而报错。

    可以肯定是因为新主库没有设置Host名称所导致的错误。

    这里可以编辑一下check_hostname_alias这个方法,让他返回一个flase就可以了。改成这样:

      return (server1.is_alias(server2.host) and
        int(server1.port) == int(3333))

    然后启动MySQLfailover进程,发现不会报错,正常运行了。

  • 相关阅读:
    理解volatile与synchronized
    实现任意两个数的互换
    增删改查+部分前段内容
    Hibernate知识点小结汇总
    Spring知识点小结(一)
    JDBC相关
    Redis工具之Jedis
    Hibernate知识点小结(四)--JPA
    Hibernate知识点小结(三)-->一对多与多对多配置
    Hibernate知识点小结(二)
  • 原文地址:https://www.cnblogs.com/magmell/p/9754916.html
Copyright © 2020-2023  润新知