consul1.6实现Mysql-Gtid主从读写分离-03

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了consul1.6实现Mysql-Gtid主从读写分离-03相关的知识,希望对你有一定的参考价值。

规划

技术图片

mysql Gtid主从配置

 https://blog.51cto.com/9025736/2500516

consul集群搭建

 https://blog.51cto.com/9025736/2500976

创建mysql用户并授权(mysql服务器需要授权)

 MySQL [(none)]> grant all on *.* to ‘han‘@‘%‘ identified by ‘hanye131‘;
 MySQL [(none)]> flush privileges;

配置consul (consul client端 server3 和server4)

   [root@server4 consul.d]# cd /etc/consul.d
   [root@server4 consul.d]# cat mysql-write.json 
         {
      "services": [
        {
          "name": "mysql-master",
          "tags": [
             "mysql-179"
          ],
          "address": "192.168.31.179",
          "port": 3306,
          "checks": [
            {
              "args": ["/usr/bin/bash","/data/mysql_master.sh"],
              "interval": "10s",
              "timeout": "1s"
            }
          ]
        }
      ]
    }

 [root@server4 consul.d]# cat mysql-readonly.json 
    {
      "services": [
        {
          "name": "mysql-slave",
          "tags": [
             "mysql-180"
          ],
          "address": "192.168.31.180",
          "port": 3306,
          "checks": [
            {
              "args": ["/usr/bin/bash","/data/mysql_slave.sh"],
              "interval": "10s",
              "timeout": "1s"
            }
          ]
        }
      ]
    }
  [root@server4 consul.d]# cat /data/mysql_master.sh 
      #!/bin/bash
      mysql -uhan -phanye131 -h 192.168.31.179 -e "select 1;"
      if [ $? -eq 0 ]; then
        exit 0
      else
        exit 2
      fi
  [root@server4 consul.d]# cat  /data/mysql_slave.sh 
      #!/bin/bash
      mysql -uhan -phanye131 -h 192.168.31.180 -e "select 1;"
      if [ $? -eq 0 ]; then
        exit 0
      else
        exit 2
      fi
   [root@server4 consul.d]# scp /data/mysql_*.sh server3:/data/
     [root@server4 consul.d]# scp /etc/consul.d/mysql-* server3:/etc/consul.d/

重载consul(server3和server4)

 consul reload

测试检测

技术图片
技术图片
技术图片
技术图片

停止server3 consul

技术图片
[root@server2 consul.d]# dig mysql-master.service.consul
[root@server2 consul.d]# dig mysql-slave.service.consul

正常登录访问

技术图片

以上是关于consul1.6实现Mysql-Gtid主从读写分离-03的主要内容,如果未能解决你的问题,请参考以下文章

Linux——MySQL主从复制与读写分离实现高可用性,负载均衡的功能

mysql数据库读写分离,主从同步实现方法

数据库读写分离,主从同步实现方法

mysql-proxy代理加mysql主从实现读写分离

Mycat 实现 MySQL 主从架构的读写分离

利用Amoeba实现MySQL主从复制和读写分离