企业实战_20_MyCat使用HAPpoxy对Mycat负载均衡

上一篇:企业实战_19_MyCat初始化ZK并配置Mycat支持ZK
https://gblfy.blog.csdn.net/article/details/100087824

解决了引入多个mycat节点之间配置文件信息同步问题
如何在多个mycat之间进行负载均衡的问题?
在某一个mycat节点出现宕机之后,我们还可以在集群中,将这个宕机的节点提出到负载之外,需要引入HAPpoxy和keepalived

文章目录

          • 一、mycat01节点安装和配置haproxy
            • 1. 安装haproxy
            • 2. 编辑/etc/haproxy/haproxy.cfg
            • 3. 使用48700端口来对mycat监控
            • 4. 新建mycatchk文件
            • 5. 新建mycat_status脚本
            • 6. 赋予可执行权限
            • 7. 脚本验证
            • 8. 添加端口
            • 9. 重新xinetd服务时生效
            • 10. 查看48700是否启动正常
            • 11. 启动haproxy
            • 12. 查看服务是否启动
          • 二、mycat02节点安装和配置haproxy
            • 2.1. 安装haproxy
            • 2.2. 编辑/etc/haproxy/haproxy.cfg
            • 2.3. 使用48700端口来对mycat监控
            • 2.4. 新建mycatchk文件
            • 2.5. 新建mycat_status脚本
            • 2.6. 赋予可执行权限
            • 2.7. 脚本验证
            • 2.8. 添加端口
            • 2.9. 重新xinetd服务时生效
            • 2.10. 查看48700是否启动正常
            • 2.11. 启动haproxy
            • 2.12. 查看服务是否启动
          • 三、验证
            • 3.1. 连接mycat
            • 3.2. haproxy管理页面

HAPpoxy是什么?
7层的代理服务,本身是没有状态的,因此,我们可以通过部署多台HAPpoxy服务的方式,来实现HAPpoxy的高可用,不过具体要使用哪一个HAPpoxy来提供服务呢?
这时候,我们需要使用另外一个组件keepalived,来进行判断了,这里使用keepalived呢,主要是对HAPpoxy来进行监控,并且对外提供一个虚拟ip,来访问HAPpoxy服务,以达到HAPpoxy的高可用,接下来需要对HAPpoxy进行相应的配置,把访问mycat的请求,均匀的将球分配到后面mycat节点上,把直接访问mycat的方式,修改为访问HAPpoxy提供的虚拟ip的方式,来访问mycat

在这里插入图片描述

主机名IP地址角色
mycat01192.168.92.101MYCAT/MYSQL/ZK/HAProxy/keepalied
node1192.168.92.102ZK/MYSQL
node2192.168.92.103ZK/MYSQL
mycat02192.168.92.104MYCAT/MYSQL/HAProxy/keepalied

温馨提醒:建议把HAProxy和keepalied部署到和mycat同一节点上,MYSQL数据建议部署在不同服务器上

在mycat01节点和mycat02节点,安装haproxy

一、mycat01节点安装和配置haproxy
1. 安装haproxy
yum install haproxy -y
2. 编辑/etc/haproxy/haproxy.cfg
vim /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global# to have these messages end up in /var/log/haproxy.log you will# need to:## 1) configure syslog to accept network log events.  This is done#    by adding the '-r' option to the SYSLOGD_OPTIONS in#    /etc/sysconfig/syslog## 2) configure local2 events to go to the /var/log/haproxy.log#   file. A line like the following can be added to#   /etc/sysconfig/syslog##    local2.*                       /var/log/haproxy.log#log         127.0.0.1 local2chroot      /var/lib/haproxypidfile     /var/run/haproxy.pidmaxconn     4000user        haproxygroup       haproxydaemon# turn on stats unix socketstats socket /var/lib/haproxy/stats#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaultsmode                    httplog                     globaloption                  httplogoption                  dontlognulloption http-server-closeoption forwardfor       except 127.0.0.0/8option                  redispatchretries                 3timeout http-request    10stimeout queue           1mtimeout connect         10stimeout client          1mtimeout server          1mtimeout http-keep-alive 10stimeout check           10smaxconn                 3000# 在这里开始添加配置
# 添加haproxy管理端口 用来监控hapeoxy的运行状态
listen admin_statusbind 0.0.0.0:48800stats uri /admin-statusstats auth admin:admin# 对后端mycat的监听服务
listen allmycat_service# 对外提供的服务端口,mycat启动之后,使用8096访问mycat服务# 后期我们的程序也是通过8096访问数据库bind 0.0.0.0:8096# 访问的模式tcpmode tcp# 日志格式采用tcplog格式option tcplogoption httpchk OPTIONS * HTTP/1.1\r\nHost:\ www# 负载均衡算法 轮询算法balance roundrobin# 对后端mycat服务配置# 通过48700端口来进行监控# 每隔5s监控一次,失败后重试3次server mycat_01 192.168.92.101:8066 check port 48700 inter 5s rise 2 fall 3server mycat_04 192.168.92.104:8066 check port 48700 inter 5s rise 2 fall 3# 对mycat的管理端口来进行监控
listen allmycat_adminbind 0.0.0.0:8097mode tcpoption tcplogoption httpchk OPTIONS * HTTP/1.1\r\nHost:\ wwwbalance roundrobin# mycat的管理端口server mycat_01 192.168.92.101:9066 check port 48700 inter 5s rise 2 fall 3server mycat_04 192.168.92.104:9066 check port 48700 inter 5s rise 2 fall 3

在这里插入图片描述
在这里插入图片描述

3. 使用48700端口来对mycat监控
  • 启动48700端口,需要安装xinetd
yum install xinetd
4. 新建mycatchk文件

在/etc/xinetd.d/目录下面,新建mycatchk文件

#新建mycatchk脚本
vim /etc/xinetd.d/mycatchk
#添加内容如下:
# default: on 
# description: monitor for mycat
service mycatchk
{
flags = REUSE
socket_type = stream
port = 48700
wait = no
user = root
server =/app/mycat/bin/mycat_status
log_on_failure += USERID
disable = no
per_source      = UNLIMITED 
}

在这里插入图片描述
注释:这个地方脚本的路径在mycat的安装目录,我的安装目录为/app/mycat

5. 新建mycat_status脚本

#在/usr/local/bin目录下面,新建mycat_status脚本

#新建mycat_status脚本
vim /app/mycat/bin/mycat_status
#脚本内容如下
#!/bin/bash
#/usr/local/bin/mycat_status.sh
# This script checks if a mycat server is healthy running on localhost. It will
# return:
#
# "HTTP/1.x 200 OK\r" (if mycat is running smoothly)
#
# "HTTP/1.x 503 Internal Server Error\r" (else)
mycat=`/app/mycat/bin/mycat status |grep 'not running'| wc -l`
if [ "$mycat" = "0" ];
then/bin/echo -en "HTTP/1.1 200 OK\r\n" /bin/echo -en "Content-Type: text/plain\r\n" /bin/echo -en "Connection: close\r\n" /bin/echo -en "Content-Length: 40\r\n" /bin/echo -en "\r\n" /bin/echo -en "MyCAT  Cluster Node is synced.\r\n" exit 0
else/bin/echo -en "HTTP/1.1 503 Service Unavailable\r\n" /bin/echo -en "Content-Type: text/plain\r\n" /bin/echo -en "Connection: close\r\n" /bin/echo -en "Content-Length: 44\r\n" /bin/echo -en "\r\n" /bin/echo -en "MyCAT Cluster Node is not synced.\r\n" exit 1
fi

在这里插入图片描述
注意:脚本中的mycat安装目录,一定要写对了,根据自己安装的实际目录为准

6. 赋予可执行权限

#给这个脚本赋予可执行权限

chmod a+x /app/mycat/bin/mycat_status
7. 脚本验证

#执行这个脚本,返货http200说明成功,对mycat检测的

[root@node1 conf]# /app/mycat/bin/mycat_statusHTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 40MyCAT  Cluster Node is synced.

在这里插入图片描述

8. 添加端口
# 编辑services这个文件
vim /etc/services# 在最后一行添加内容:
mycatchk        48700/tcp               #mycatchk

在这里插入图片描述

9. 重新xinetd服务时生效
# centos6.xservice xinetd restart# centos7.x
systemctl restart xinetd.service

在这里插入图片描述

10. 查看48700是否启动正常
[root@node1 conf]#  netstat -nltp |grep 48700
tcp6       0      0 :::48700                :::*                    LISTEN      22330/xinetd   

在这里插入图片描述

11. 启动haproxy
 haproxy -f /etc/haproxy/haproxy.cfg

在这里插入图片描述

12. 查看服务是否启动
netstat -nltp

在这里插入图片描述

二、mycat02节点安装和配置haproxy
2.1. 安装haproxy
yum install haproxy -y
2.2. 编辑/etc/haproxy/haproxy.cfg
vim /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global# to have these messages end up in /var/log/haproxy.log you will# need to:## 1) configure syslog to accept network log events.  This is done#    by adding the '-r' option to the SYSLOGD_OPTIONS in#    /etc/sysconfig/syslog## 2) configure local2 events to go to the /var/log/haproxy.log#   file. A line like the following can be added to#   /etc/sysconfig/syslog##    local2.*                       /var/log/haproxy.log#log         127.0.0.1 local2chroot      /var/lib/haproxypidfile     /var/run/haproxy.pidmaxconn     4000user        haproxygroup       haproxydaemon# turn on stats unix socketstats socket /var/lib/haproxy/stats#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaultsmode                    httplog                     globaloption                  httplogoption                  dontlognulloption http-server-closeoption forwardfor       except 127.0.0.0/8option                  redispatchretries                 3timeout http-request    10stimeout queue           1mtimeout connect         10stimeout client          1mtimeout server          1mtimeout http-keep-alive 10stimeout check           10smaxconn                 3000# 在这里开始添加配置
# 添加haproxy管理端口 用来监控hapeoxy的运行状态
listen admin_statusbind 0.0.0.0:48800stats uri /admin-statusstats auth admin:admin# 对后端mycat的监听服务
listen allmycat_service# 对外提供的服务端口,mycat启动之后,使用8096访问mycat服务# 后期我们的程序也是通过8096访问数据库bind 0.0.0.0:8096# 访问的模式tcpmode tcp# 日志格式采用tcplog格式option tcplogoption httpchk OPTIONS * HTTP/1.1\r\nHost:\ www# 负载均衡算法 轮询算法balance roundrobin# 对后端mycat服务配置# 通过48700端口来进行监控# 每隔5s监控一次,失败后重试3次server mycat_01 192.168.92.101:8066 check port 48700 inter 5s rise 2 fall 3server mycat_04 192.168.92.104:8066 check port 48700 inter 5s rise 2 fall 3# 对mycat的管理端口来进行监控
listen allmycat_adminbind 0.0.0.0:8097mode tcpoption tcplogoption httpchk OPTIONS * HTTP/1.1\r\nHost:\ wwwbalance roundrobin# mycat的管理端口server mycat_01 192.168.92.101:9066 check port 48700 inter 5s rise 2 fall 3server mycat_04 192.168.92.104:9066 check port 48700 inter 5s rise 2 fall 3

在这里插入图片描述

在这里插入图片描述

2.3. 使用48700端口来对mycat监控
  • 启动48700端口,需要安装xinetd
yum install xinetd
2.4. 新建mycatchk文件

在/etc/xinetd.d/目录下面,新建mycatchk文件

#新建mycatchk脚本
vim /etc/xinetd.d/mycatchk
#添加内容如下:
# default: on 
# description: monitor for mycat
service mycatchk
{
flags = REUSE
socket_type = stream
port = 48700
wait = no
user = root
server =/app/mycat/bin/mycat_status
log_on_failure += USERID
disable = no
per_source      = UNLIMITED 
}

在这里插入图片描述

注释:这个地方脚本的路径在mycat的安装目录,我的安装目录为/app/mycat

2.5. 新建mycat_status脚本

#在/usr/local/bin目录下面,新建mycat_status脚本

#新建mycat_status脚本
vim /app/mycat/bin/mycat_status
#脚本内容如下
#!/bin/bash
#/usr/local/bin/mycat_status.sh
# This script checks if a mycat server is healthy running on localhost. It will
# return:
#
# "HTTP/1.x 200 OK\r" (if mycat is running smoothly)
#
# "HTTP/1.x 503 Internal Server Error\r" (else)
mycat=`/app/mycat/bin/mycat status |grep 'not running'| wc -l`
if [ "$mycat" = "0" ];
then/bin/echo -en "HTTP/1.1 200 OK\r\n" /bin/echo -en "Content-Type: text/plain\r\n" /bin/echo -en "Connection: close\r\n" /bin/echo -en "Content-Length: 40\r\n" /bin/echo -en "\r\n" /bin/echo -en "MyCAT  Cluster Node is synced.\r\n" exit 0
else/bin/echo -en "HTTP/1.1 503 Service Unavailable\r\n" /bin/echo -en "Content-Type: text/plain\r\n" /bin/echo -en "Connection: close\r\n" /bin/echo -en "Content-Length: 44\r\n" /bin/echo -en "\r\n" /bin/echo -en "MyCAT Cluster Node is not synced.\r\n" exit 1
fi

在这里插入图片描述

注意:脚本中的mycat安装目录,一定要写对了,根据自己安装的实际目录为准

2.6. 赋予可执行权限

#给这个脚本赋予可执行权限

chmod a+x /app/mycat/bin/mycat_status
2.7. 脚本验证

#执行这个脚本,返货http200说明成功,对mycat检测的

[root@node4 ~]#  /app/mycat/bin/mycat_status
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 40MyCAT  Cluster Node is synced.

在这里插入图片描述

2.8. 添加端口
# 编辑services这个文件
vim /etc/services# 在最后一行添加内容:
mycatchk        48700/tcp               #mycatchk

在这里插入图片描述

2.9. 重新xinetd服务时生效
# centos6.xservice xinetd restart# centos7.x
systemctl restart xinetd.service

在这里插入图片描述

2.10. 查看48700是否启动正常
[root@node4 conf]#  netstat -nltp |grep 48700
tcp6       0      0 :::48700                :::*                    LISTEN      22330/xinetd   

在这里插入图片描述

2.11. 启动haproxy
 haproxy -f /etc/haproxy/haproxy.cfg
2.12. 查看服务是否启动
netstat -nltp

在这里插入图片描述

三、验证
3.1. 连接mycat

通过haproxy,使用mysql客户端连接mycat

# 这里虚拟地址待定
mysql -uapp_imooc -p -h192.168.92.101 -P8096
[root@node4 ~]# mysql -uapp_imooc -p -h192.168.92.101 -P8096
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6.5-release-20180122220033 MyCat Server (OpenCloundDB)Copyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> use imooc_db;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> select count(1) from order_master;
+--------+
| COUNT0 |
+--------+
|      1 |
+--------+
1 row in set (0.28 sec)mysql> 

正常返回数据
在这里插入图片描述

3.2. haproxy管理页面

http://192.168.92.101:48800/admin-status
在这里插入图片描述

http://192.168.92.104:48800/admin-status
在这里插入图片描述

下一篇:企业实战_21_MyCat_keepalived 安装配置验证
https://gblfy.blog.csdn.net/article/details/100103518

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/523395.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

安全,从写第一行代码开始!

戳蓝字“CSDN云计算”关注我们哦!作者 | 刘晶晶伴随5G时代的脚步渐进,物联网发展也将成井喷式增长,“网络安全”这个老生常谈的话题似乎进入了新阶段。数据是天使?还是魔鬼?归根结底,没有安全保障的物联网终…

python模块里的函数及说明,Python模块 time与datetime模块的函数说明及使用实例

time模块模块time包含用于获取当前时间,操作时间和日期.从字符串中读取日期,将日期格式化为字符串的函数.日期可表示为实数,也可表示为包含9个整数的元组例如tuple(2018,12,24,12,2,56,-1,-1,-1)------------------------------------------------------索引 字段 值0-----年--…

Linux zookeeper下载、单点部署

说明地址ziphttp://mirror.bit.edu.cn/apache/zookeeper/stable/apache-zookeeper-3.5.5-bin.tar.gz命令下载wget http://mirror.bit.edu.cn/apache/zookeeper/stable/apache-zookeeper-3.5.5-bin.tar.gz http://archive.apache.org/dist/zookeeper/zookeeper-3.5.7/apache-zoo…

聚科技精英,享开源之美- 2019 Open Source Summit 主题演讲+项目亮点

2019年6月24-26日,在上海世博中心,由Linux基金会主办的LinuxCon ContainerCon CloudOpen大会(简称LC3)将与CNCF主办的KubeCon CloudNativeCon大会合体,自此,大会正式更名为KubeCon CloudNativeCon Ope…

php写linux应用程序,Linux应用程序使用写文件调试程序的方法

Linux,一切皆文件,那么在Android系统本身,也是Linuxjava罢了,也是在Linux的运行环境下。通常,我们在调试程序的都会使用printf。在Android中,我们会去使用logcat,现在,给大家介绍一种…

_Mycat-Web之UI监控

接上一篇:企业实战_19_Mycatkeepalived 安装配置验证 https://blog.csdn.net/weixin_40816738/article/details/100103518 文章目录1、zip下载2、wget 下载方式3、解压4、在安装mycat-web之前首先要安装一下5、设置zookeeper服务路径6、启动mycat-web7、浏览器验证8…

企业实战_21_MyCat_keepalived 安装配置验证

接上一篇:企业实战_20_MyCat使用HAPpoxy对Mycat负载均衡 https://gblfy.blog.csdn.net/article/details/100087884 主机名IP地址角色mycat192.168.43.32MYCAT MYSQL,ZK,Haproxy,Keepalivednode1192.168.43.104MYSQL,ZKnode2192.168.43.217MYSQL,ZKnode3192.168.43.1…

为什么说 5G 是物联网的时代?

受 5G 冲击最大的领域终将会是谁?作者 | 屠敏 整理出品 | CSDN(ID:CSDNnews)提及当前科技圈有哪些热点词,那 5G 必是其中之一。6 月 6 日,工业和信息化部正式向中国移动、中国联通、中国电信和中国广电发布…

命令行给php脚本传参,如何在CLI命令行下运行PHP脚本,同时向PHP脚本传递参数?...

标签:c t sp get int name php test print root enter//命令行输入输出流fwrite(STDOUT,"Enter your name:");$name trim(fgets(STDOUT));fwrite(STDOUT,"hello,$name");*/echo$argc;if ($argc > 1){print_r($argv);}?…

企业实战_24_MyCat实现读写分离

接上一篇:企业实战_23_MyCat SQL防火墙 https://gblfy.blog.csdn.net/article/details/100074335 文章目录一、MyCat读写分离操作流程二、环境部署安排:三、主机操作103(node3)3.1. 数据备份3.2. 将node3.sql复制到节点53.3. 导入数据3.4. 在查看是否创建…

c#中计算三角形面积公式,C#源代码—三角形面积、圆的面积

三角形面积、圆的面积using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _2{public abstract class shape{private string mc;public shape(string s){Mc s;}public string Mc{get{return mc;}set{mc value;}}public double Are…

Storm精华问答 | 为什么要用Storm?不用Spark?

戳蓝字“CSDN云计算”关注我们哦!Apache Storm是一个分布式实时大数据处理系统。Storm设计用于在容错和水平可扩展方法中处理大量数据。它是一个流数据框架,具有最高的摄取率。今天,我们就挑一些Storm的安装配置问题来看看吧。1Q:…

oracle读取表空间物理文件中数据,shell脚本读取oracle数据库数据写入到文件中

1、linux 需要用 sqlplus 客户端去连接oracle 数据库,首先需要确认有没有安装:which sqlplus2、如果没有安装就需要先安装一下(百度)3、配置环境变量:vim /etc/profile4、执行 source /etc/profile5、whereis oracle #查看oracle 客户端安装…

做“云”,京东云是认真的!

戳蓝字“CSDN云计算”关注我们哦!作者 | 刘晶晶在2018年,京东云的营收达到了三位数的增长,10倍于行业增速;18个月的时间,京东云推出了超过200项的PaaS/IaaS服务……京东云总裁申元庆在2019全球人工智能技术大会上接受采…

这位博士跑赢“地震波”:提前 10 秒预警宜宾地震!

戳蓝字“CSDN云计算”关注我们哦!整理 | 胡巍巍出品 | CSDN(ID:CSDNnews)天府之国四川,又遭地震!据中国地震台网测定:6月17日22时55分,四川省宜宾市长宁县发生6.0级地震,…

oracle10gasmcmd,ORACLE 10g中ASMCMD使用及ASM文件

ORACLE 10g中ASMCMD使用及ASM文件XML DB访问1.引言自动存储管理(ASM)是Oracle数据库10g的新功能,它为数据库管理员提供了一个简单的存储管理界面,并且该界面在所有服务器和存储平台上都是一致的。作为专门为Oracle数据库文件创建的整合的文件系统和卷管理…

企业实战_04_MyCat常用配置文件详解

Mycat 常用配置文件,配置灵活,能应用于场景很多,建议根据应用场景去记忆,要理解! 接上一篇:企业实战_03_MyCat下载、安装、启动 https://gblfy.blog.csdn.net/article/details/100049304 文章目录一、Mycat目录说明二、…

OpenStack精华问答 | OpenStack是云吗?

自诞生以来,OpenStack 似乎一直被质疑,其背后最重要的两大推手 NASA 和 Rackspace 都弃它而去,惠普、思科接连宣布关闭基于 OpenStack 的公有云服务,但是,OpenStack 依旧坚挺。1Q:openstack介绍A:openstack…

mclmcrrt77 matlab,mclmcrrt77.dll下载

mclmcrrt77.dll文件作为应用程序中非常重要的一个组件,如果弄丢或者报错后会出现很多麻烦的事情,这时候大家只需要到本站来下载该文件包,然后按照本站的安装方法进行安装就可以修复了!mclmcrrt77.dll介绍如果您的系统提示“找不到…

社会保障查询

公积金个人用户登录: http://www.zzz.gov.cn/wtgrgjj/index.html http://www.bjrbj.gov.cn/csibiz/home/index.html