iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >Consul, ProxySQL and MySQL MHA架构高可用方案分享
  • 799
分享到

Consul, ProxySQL and MySQL MHA架构高可用方案分享

2024-04-02 19:04:59 799人浏览 八月长安
摘要

下文给大家带来关于Consul, Proxysql and Mysql MHA架构高可用方案,感兴趣的话就一起来看看这篇文章吧,相信看完Consul, ProxySQL and mysql MHA架构高可用

下文给大家带来关于Consul, Proxysql and Mysql MHA架构高可用方案,感兴趣的话就一起来看看这篇文章吧,相信看完Consul, ProxySQL and mysql MHA架构高可用方案对大家多少有点帮助吧。

架构特性:
1,高可用
2,读写分离,查询路由
3,sql过滤等功能

Consul, ProxySQL and MySQL MHA架构高可用方案分享

Installation of Consul:
Firstly, we’ll need to install the required packages, download the Consul arcHive and perfORM the initial configuration. We’ll need to perform the same installation on each of the nodes (i.e., appserver, mysql1 and mysql2).
Install pre-requisite packages:
sudo yum -y install wget unzip bind-utils dnsmasq
Install Consul:
sudo useradd consul
sudo mkdir -p /opt/consul /etc/consul.d
sudo touch /var/log/consul.log /etc/consul.d/proxysql.JSON
cd /opt/consul
sudo wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
sudo unzip consul_0.6.4_linux_amd64.zip
sudo ln -s /opt/consul/consul /usr/bin/consul
sudo chown consul:consul -R /etc/consul /opt/consul /var/log/consul.log

Configuration of Consul on Application Server (used as ‘bootstrap’ node):
Now, that we’re done with the installation on each of the hosts, let’s continue with the configuration. In this example we’ll bootstrap the Consul cluster using “appserver”:

Edit configuration files
$ sudo vi /etc/consul.conf
{
"datacenter": "dc1",
"data_dir": "/opt/consul/",
"log_level": "INFO",
"node_name": "agent1",
"server": true,
"ui": true,
"bootstrap": true,
"client_addr": "0.0.0.0",
"advertise_addr": "192.168.1.119"  ## Add server IP here
}
######
$ sudo vi /etc/consul.d/proxysql.json
{"services": [
{
"id": "proxy1",
"name": "proxysql",
"address": "192.168.1.120",
"tags": ["mysql"],
"port": 6033,
"check": {
"script": "mysqladmin ping --host=192.168.1.120 --port=6033 --user=root --passWord=123",
"interval": "3s"}
},
{
"id": "proxy2",
"name": "proxysql",
"address": "192.168.1.121",
"tags": ["mysql"],
"port": 6033,
"check": {
"script": "mysqladmin ping --host=192.168.1.121 --port=6033 --user=root --password=123",
"interval": "3s"}
}
]
}

Start Consul agent
$ sudo su - consul -c 'consul agent -config-file=/etc/consul.conf -config-dir=/etc/consul.d > /var/log/consul.log &'

Setup DNSMASQ (as root)
vim /etc/dnsmasq.conf
resolv-file=/etc/resolv.conf
server=/consul/127.0.0.1#8600
service dnsmasq restart

Remember to add the localhost as a DNS server (this step can vary
depending on how your DNS servers are managed... here I'm just
adding the following line to resolve.conf:
sudo vi /etc/resolve.conf
#... snippet ...#
nameserver 127.0.0.1
#... snippet ...#
Restart dnsmasq
sudo service dnsmasq restart

====================================================================

Configuration of Consul on Proxy Servers:
The next item is to configure each of the proxy Consul agents. Note that the “agent name” and the “IP address” need to be updated for each host (values for both must be unique):

Edit configuration files
$ sudo vi /etc/consul.conf
{
"datacenter": "dc1",
"data_dir": "/opt/consul/",
"log_level": "INFO",
"node_name": "agent2",  ### Agent node name must be unique
"server": true,
"ui": true,
"bootstrap": false,   ### Disable bootstrap on joiner nodes
"client_addr": "0.0.0.0",
"advertise_addr": "192.168.1.xxx",  ### Set to local instance IP
"dns_config": {
"only_passing": true
}
}
######
$ sudo vi /etc/consul.d/proxysql.json
{"services": [
{
"id": "proxy1",
"name": "proxysql",
"address": "192.168.1.120",
"tags": ["mysql"],
"port": 6033,
"check": {
"script": "sh /etc/consul.d/test.sh",
"interval": "3s"}
},
{
"id": "proxy2",
"name": "proxysql",
"address": "192.168.1.121",
"tags": ["mysql"],
"port": 6033,
"check": {
"script": "sh /etc/consul.d/test.sh",
"interval": "3s"}
}
]
}

=============================================================

[root@localhost consul.d]# more test.sh
mysql -u haproxy -h 127.0.0.1 -P 3306 -e "select 1" >/dev/null 2>&1

if [ "$?" -ne 0 ]
then echo "not available"
exit 8
fi

==============================================================

Start Consul agent:
$ sudo su - consul -c 'consul agent -config-file=/etc/consul.conf -config-dir=/etc/consul.d > /var/log/consul.log &'
Join Consul cluster specifying 1st node IP e.g.
$ consul join 192.168.1.119
Verify logs and look out for the following messages:
$ cat /var/log/consul.log
==> Starting Consul agent...
==> Starting Consul agent rpc...
==> Consul agent running!
Node name: 'agent2'
Datacenter: 'dc1'
Server: true (bootstrap: false)
Client Addr: 0.0.0.0 (Http: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
Cluster Addr: 192.168.1.120 (LAN: 8301, WAN: 8302)
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
Atlas:
==> Log data will now stream in as it occurs:
... snippet ...
2016/09/05 19:48:04 [INFO] agent: Synced service 'consul'
2016/09/05 19:48:04 [INFO] agent: Synced check 'service:proxysql1'
2016/09/05 19:48:04 [INFO] agent: Synced check 'service:proxysql2'
... snippet ...

=============================================================================

Install ProxySQL packages and initialise ProxySQL DB
sudo yum -y install https://GitHub.com/sysown/proxysql/releases/proxysql-1.4.3-1-Centos67.x86_64.rpm
sudo service proxysql initial
sudo service proxysql stop
Edit the ProxySQL configuration file to update username / password
vi /etc/proxysql.cnf

admin_variables=
{
admin_credentials="admin:admin"
mysql_ifaces="127.0.0.1:6032;/tmp/proxysql_admin.sock"
}

Start ProxySQL
sudo service proxysql start
Connect to ProxySQL and configure
mysql -P6032 -h227.0.0.1 -uadmin -padmin
First we create a replication hostgroup:
mysql> INSERT INTO mysql_replication_hostgroups VALUES (10,11,'Standard Replication Groups');
Add both nodes to the hostgroup 11 (ProxySQL will automatically put the writer node in hostgroup 10)
mysql> INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight) VALUES ('192.168.1.120',10,3306,1000);
mysql> INSERT INTO mysql_servers (hostname,hostgroup_id,port,weight) VALUES ('192.168.1.121',11,3306,1000);
Save server configuration
mysql> LOAD MYSQL ServerS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;
Add query rules for RW split
mysql> INSERT INTO mysql_query_rules (active, match_pattern, destination_hostgroup, cache_ttl, apply) VALUES (1, '^SELECT . FOR UPDATE', 10, NULL, 1);
mysql> INSERT INTO mysql_query_rules (active, match_pattern, destination_hostgroup, cache_ttl, apply) VALUES (1, '^SELECT .', 11, NULL, 1);
mysql> LOAD MYSQL QUERY RULES TO RUNTIME; SAVE MYSQL QUERY RULES TO DISK;
Finally configure ProxySQL user and save configuration
mysql> INSERT INTO mysql_users (username,password,active,default_hostgroup,default_schema) VALUES ('root','123',1,10,'test');
mysql> LOAD MYSQL USERS TO RUNTIME; SAVE MYSQL USERS TO DISK;
mysql> EXIT;

总结,坑点:
1,用户访问的数据库,主从,读写都是通过hostgroup 要定义和标识,所以这个参数一定对应

2,consul 健康检查
如果健康script 脚本返回error code 为1 ,code 1 只是warning ,还是会被解析,所以修改检查脚本内容,如果不匹配,手动返回error code 2或者其他值,之后这个异常服务才不解析。

看了以上关于Consul, ProxySQL and MySQL MHA架构高可用方案分享详细内容,是否有所收获。如果想要了解更多相关,可以继续关注我们的数据库板块。

您可能感兴趣的文档:

--结束END--

本文标题: Consul, ProxySQL and MySQL MHA架构高可用方案分享

本文链接: https://www.lsjlt.com/news/36056.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • mysql MHA 高可用架构部署
    MHA简介:即Master High Availability Manager and Tools for MySQL,是日本的一位MySQL专家采用Perl语言编写的一个脚本管理工具, 该工具仅...
    99+
    2024-04-02
  • MySQL高可用架构之MHA架构全解
    目录一、介绍二、组成三、工作过程四、架构五、实例展示MHA(Master HA)是一款开源的 MySQL 的高可用程序,它为 MySQL 主从复制架构提供了 automating m...
    99+
    2024-04-02
  • MySQL高可用架构之MHA的原理分析
    这篇文章主要介绍了MySQL高可用架构之MHA的原理分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。MHA角色部署MHA 服务有两种角色,...
    99+
    2024-04-02
  • MHA实现MySQL高可用集群架构
    转转连接 https://www.cnblogs.com/tanxiaojun/p/10424699.html MHA简介 MHA(Master HighAvailability)目前在MySQL高可...
    99+
    2024-04-02
  • MySQL高可用方案MHA怎么用
    这篇文章主要为大家展示了“MySQL高可用方案MHA怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“MySQL高可用方案MHA怎么用”这篇文章吧。 MyS...
    99+
    2024-04-02
  • 【MySQL】【高可用】基于MHA架构的MySQL高可用故障自动切换架构
    基于MHA架构的MySQL高可用切换架构 环境: ​ CentOS7+MySQL 5.7 + GTID 业务系统:mainBusiness ​ node1 : 192.16...
    99+
    2024-04-02
  • MySQL高可用之MHA架构企业实战
    📢📢📢📣📣📣 哈喽!大家好,我是【IT邦德】,江湖人称jeames007,10年DBA工作经验 一位上进心十足的【大数据领域博主】!😜😜😜 中国DBA联盟(ACDU)成员,目前从事DBA及程序编程 擅长主流数据Oracle、MySQL、...
    99+
    2023-08-17
    mysql 架构 数据库 MHA
  • MySQL高可用方案MHA如何部署
    这篇文章将为大家详细讲解有关MySQL高可用方案MHA如何部署,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。MHA(Master High Availability)是一...
    99+
    2024-04-02
  • MyCAT高可用方案和架构图
    MyCAT的优势 基于阿里开源的Cobar产品而研发,Cobar的稳定性、可靠性、优秀的架构和性能以及众多成熟的使用案例使得MYCAT一开始就拥有一个很好的起点,站在巨人的肩膀上,我们能看到更远。业界优...
    99+
    2024-04-02
  • MySQL数据库实现高可用架构之MHA的实战
    目录一、MySQLMHA介绍1.1什么是MHA1.2MHA的组成1.3MHA的特点二、MySQLMHA搭建1.MHA架构部分2.故障模拟部分3.实验环境三、实验步骤1、关闭防火墙和S...
    99+
    2024-04-02
  • MySQL MHA高可用架构部署配置实例是怎样的
    本篇文章给大家分享的是有关MySQL MHA高可用架构部署配置实例是怎样的,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。MHA高可用架构部署配...
    99+
    2024-04-02
  • MySQL高可用架构中MHA的本质以及如何部署
    这篇文章将为大家详细讲解有关MySQL高可用架构中MHA的本质以及如何部署,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。MySQL高可用架构之MHA1、关于...
    99+
    2024-04-02
  • MySQL高可用实现:主从结构下ProxySQL中的读写分离
    原文: http://www.enmotech.com/web/detail/1/714/1.html ( 复制链接,打开浏览器即可查看原文 )  墨墨导读:Pro...
    99+
    2024-04-02
  • 企业中MySQL主流高可用架构实战三部曲之MHA
    老张最近两天有些忙,一些老铁一直问,啥时更新博文,我可能做不到天天更新啊,但保证以后一有空就写一些干货知识分享给大家。我们如果想要做好技术这项工作,一定要做到理论与实践先结合。我一个曾经被数据库虐得体无完肤...
    99+
    2024-04-02
  • MySQL MGR+ Consul之数据库高可用方案最佳实践
    MySQL MGR+ Consul之数据库高可用方案最佳实践 背景说明:     基于目前存在很多MySQL数据库单点故障,传统的MHA,PXC等方案用VIP或者DNS切...
    99+
    2024-04-02
  • MySQL之高可用架构的示例分析
    小编给大家分享一下MySQL之高可用架构的示例分析,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!MySQL高可用MySQL的高可用也是同样的思路,首先要有多个MySQL实例提供服务,其次就是当某个实例挂掉时,可以自动切换流...
    99+
    2023-06-22
  • MySQL高可用方案MHA在线切换的步骤及原理
    在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小。 MHA...
    99+
    2024-04-02
  • 解析高可用Redis服务架构分析与搭建方案
    基于内存的Redis应该是目前各种web开发业务中最为常用的key-value数据库了,我们经常在业务中用其存储用户登陆态(Session存储),加速一些热数据的查询(相比较mysq...
    99+
    2024-04-02
  • MySQL 中常见的几种高可用架构部署方案解析
    目录MySQL 中的集群部署方案前言MySQL ReplicationMySQL Group ReplicationInnoDB ClusterInnoDB ClusterSetIn...
    99+
    2023-05-17
    mysql高可用 mysql高可用架构部署 MySQL常用部署
  • MySQL 中常见的几种高可用架构部署方案解析
    目录mysql 中的集群部署方案前言MySQL ReplicationMySQL Group ReplicationInnoDB ClusterInnoDB ClusterSetInnoDB ReplicaSetMMMM...
    99+
    2023-04-21
    mysql高可用 mysql高可用架构部署 MySQL常用部署
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作