• Mycat故障转移之writetype与switchtype


    转载于:http://blog.itpub.net/29096438/viewspace-2137743/ 

    1.配置文件如下:

    1. <dataHost name="localhost1" maxCon="1000" minCon="10" balance="2"
    2.                           writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
    3.                 <heartbeat>select user()</heartbeat>
    4.                 <!-- can have multi write hosts -->
    5.                 <writeHost host="hostM1" url="192.168.6.121:3306" user="root"
    6.                                    password="ESBecs00">
    7.                         <!-- can have multi read hosts -->
    8.                 </writeHost>
    9.                 
    10.                 <writeHost host="hostS1" url="192.168.6.121:3307" user="root"
    11.                                    password="ESBecs00">
    12.                         <!-- can have multi read hosts -->
    13.                 </writeHost>
    14.         </dataHost>

    writeType属性
    负载均衡类型,目前的取值有3种:
    1. writeType="0", 所有写操作发送到配置的第一个writeHost,第一个挂了切到还生存的第二个writeHost,重新启动后已切换后的为准,切换记录在配置文件中:dnindex.properties .
    2. writeType="1",所有写操作都随机的发送到配置的writeHost。 
    3. writeType="2",没实现。

    switchtype属性如下(控制自动切换的 )


    2 模拟数据库down机

    1. 2.1 主库down机
    1. [root@localhost ~]# /etc/init.d/mysql stop
      Shutting down MySQL....                                    [确定]

    1. 2.2 mycat插入数据
    1. mysql> insert into zs values (2),(3);
      Query OK, 2 rows affected (0.00 sec)
      Records: 2  Duplicates: 0  Warnings: 0

    1. 2.3 查看备库
    1. mysql> select * from zs;
      +------+
      | id   |
      +------+
      |    1 |
      |    2 |
      |    3 |
      +------+
      3 rows in set (0.00 sec)
      数据发送至备库,可见已切换成功

    1. 2.4 主库恢复
    1. [root@localhost ~]# /etc/init.d/mysql start
      Starting MySQL.                                            [确定]

    1. 2.5 再次插入数据,并查看从和主
    1. mycat> insert into zs values (4),(5);
    2. 从上:mysql> select * from zs;
      +------+
      | id   |
      +------+
      |    1 |
      |    2 |
      |    3 |
      |    4 |
      |    5 |
      +------+
    3. 主上:mysql> select * from zs;
      +------+
      | id   |
      +------+
      |    1 |
      +------+
      1 row in set (0.00 sec)

    4. 通过上面的步骤可以发现,主库down掉后 就以从库为准了,就算主库恢复了,还是以从库为准,所以搭个双主是最好的解决办法
    5. 可以看下切换的记录文件
    6. [root@localhost conf]# more dnindex.properties 
      #update
      #Fri Apr 21 13:40:09 CST 2017
      localhost3=0
      localhost2=0
      localhost1=1  ###使用第二个writehost

    7. 将新的主库down机 再恢复,又切换回原主库了
    8. [root@localhost conf]# more dnindex.properties 
      #update
      #Fri Apr 21 13:56:09 CST 2017
      localhost3=0
      localhost2=0
      localhost1=0  ###使用第一个writehost
      #这0和1代表的就是写入时使用第几个writehost的意思了
     
  • 相关阅读:
    C++ 函数指针
    windows重建ESP分区修复引导
    [Python] typora文档复制到博客图片失效 SM.MS限制
    [Python] 破解一款软件验证
    requests.packages.urllib3.exceptions.ProxySchemeUnknown: Not supported proxy scheme
    nvalidSchema: Missing dependencies for SOCKS support
    html 未选择复选框不上传
    deepin linux 安装之后 引导错误 出现 grub>
    js/jquery加入的select value显示不正确问题
    请求响应状态status为canceled
  • 原文地址:https://www.cnblogs.com/kelelipeng/p/13638463.html
Copyright © 2020-2023  润新知