admin管理员组

文章数量:1532333

背景

之前安装了HMS(Hive metastore service),独立于hive运行,安装部署过程见我下面列出的另一篇文章,需要为它建立HA高可用功能。防止在访问时出现单点故障问题。

【大数据】Docker部署HMS(Hive Metastore Service)并使用Trino访问Minio-CSDN博客

本来想到的是Nginx,但是在进一步分析,HMS发布的是thrift协议,一种tcp协议,而nginx支持的是http和https协议,所以无法匹配。另外找解决方案,在chatgpt的帮助下,发现可以使用HAProxy来做thrift协议的HA,所以选择了HAProxy。

一:环境介绍

之前发布了HMS服务,现在需要支持HA,那么需要启动两个HMS(使用docker启动的),并且两个HMS指向同一个mysql数据库,这样在两个HMS之间可以实现HA,所以重新做了一个HMS的服务,在两台虚机上

虚机一:wuxdihadl03b,IP 10.40.8.44,部署了HMS和mysql服务

虚机二:wuxdihadl04b,IP 10.40.8.45,部署了HMS服务

使用trino访问了两个HMS实例,均能访问HMS及后端的minio数据

trino的catalog配置

trino访问数据

二:实现目标

环境已经准备好了,现在就是要使用HAProxy来代理到后端的两个HMS服务,并且在一台HMS下线后,仍然能使用另一台HMS对外服务。

三:安装HAProxy

yum install haproxy -y

四:配置HAProxy

找到配置文件/etc/haproxy/haproxy.cfg,修改frontend,backend,listen语段,frontend代表前端服务,客户端访问入口,backend代理后端服务,listen配置监控界面。因为HMS使用的是thrift协议,因此在设置时,需要设置mode为tcp,否则默认为http

frontend设置

frontend main
    bind *:5000    #对外暴露的访问地址及端口
    mode tcp       #设置协议为tcp,thrift归属于tcp协议
    acl url_static       path_beg       -i /static /images /javascript /stylesheets
    acl url_static       path_end       -i .jpg .gif .png .css .js

    use_backend static          if url_static
    default_backend             hms    #后端服务的名称

backend设置

backend hms
    balance     roundrobin    #负载均衡策略
    mode tcp                  #协议模式,thrift归属tcp
    server  app1 10.40.8.44:9083 check    #HMS服务1
    server  app2 10.40.8.45:9083 check    #HMS服务2

listen设置

listen stats
    bind :9000    # 页面访问端口
    stats enable    # 启用统计报告
    stats uri /haproxy_stats    # 设置统计页面的 URL 路径
    stats realm Haproxy\ Statistics    # 设置认证窗口标题
    stats auth admin:haproxy    # 设置访问统计页面的用户名和密码
    stats admin if TRUE    # 开启管理模式,允许通过界面进行某些操作

以上配置完成,下面贴出我这个文件haproxy.cfg的完整配置

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   https://www.haproxy/download/1.8/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 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

    # utilize system-wide crypto-policies
    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

listen stats
    bind :9000
    stats enable
    stats uri /haproxy_stats
    stats realm Haproxy\ Statistics
    stats auth admin:haproxy
    stats admin if TRUE

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
    bind *:5000
    mode tcp
    acl url_static       path_beg       -i /static /images /javascript /stylesheets
    acl url_static       path_end       -i .jpg .gif .png .css .js

    use_backend static          if url_static
    default_backend             hms

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
    balance     roundrobin
    server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend hms
    balance     roundrobin
    mode tcp
    server  app1 10.40.8.44:9083 check
    server  app2 10.40.8.45:9083 check

重启HAProxy服务

systemctl reload haproxy

五:测试HAProxy功能


首先修改trino的metastore地址为thrift://10.40.8.44:5000

docker停止两个HMS服务

查看HAProxy页面服务http://10.40.8.44:9000/haproxy_stats,两个服务是下线的

trino访问,metastore地址10.40.8.44:5000,无法访问


启动一个服务

查看页面,一个HMS已经启动

trino访问


再启动另一个HMS,仍然能访问


反复多情况测试均成功,本次测试结束!

六:附注:列一下chatgpt给与的帮助截图

只能说chatgpt提升工作效率100%以上,某度,某元还是扎根好好做吧。注:我用的是chatgpt4

问:HMS的HA怎么做

问:Nginx可以做HMS服务的HA吗

我指出了问题点,gpt马上就纠正了错误,肯定了我的观点

问:目前有哪些支持Thrift 协议的负载均衡器

问:使用HAProxy如何支持thrift协议的服务的HA

问:Haproxy配置监控界面

本文标签: 截图协议数据HAthrift