前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何使用HAProxy实现HiveServer2服务的LDAP和Kerberos认证负载均衡

如何使用HAProxy实现HiveServer2服务的LDAP和Kerberos认证负载均衡

作者头像
Fayson
发布2018-04-24 15:00:49
1.9K0
发布2018-04-24 15:00:49
举报
文章被收录于专栏:Hadoop实操Hadoop实操

温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。

Fayson的github:https://github.com/fayson/cdhproject

提示:代码块部分可以左右滑动查看噢

1.文档编写目的


在CDH集群中启用了Kerberos并集成了OPenLDAP,在前面的文章中Fayson也介绍了在CDH集群中启用Kerberos与集成OPenLDAP,集群中HiveServer2服务需要同时支持Kerberos和OPenLDAP认证的负载均衡,本篇文章主要介绍如何使用HAProxy实现HiveServer2服务的两种认证方式的负载均衡。

  • 内容概述

1.测试环境描述

2.HAproxy配置

3.HiveServer2集成OPenLDAP

4.验证HiveServer2负载均衡

5.Hue配置HAProxy及验证

6.总结

  • 测试环境

1.RedHat7.3

2.OpenLDAP版本2.4.44

  • 前置条件

1.OpenLDAP已安装且正常使用

2.测试环境描述


在Fayson的测试环境安装3个HiveServer2的服务:

IP地址

HOSTNAME

描述

172.31.30.69

ip-172-31-30-69.ap-southeast-1.compute.internal

OPenLDAP认证

172.31.16.68

ip-172-31-16-68.ap-southeast-1.compute.internal

OPenLDAP认证

172.31.21.83

ip-172-31-21-83.ap-southeast-1.compute.internal

OPenLDAP认证

  • OpenLDAP服务信息

IP地址

HOSTNAME

描述

172.31.24.169

ip-172-31-24-169.ap-southeast-1.compute.internal

OpenLDAP已安装

172.31.16.68

ip-172-31-16-68.ap-southeast-1.compute.internal

OpenLDAP已安装

这里我们将172.31.24.169做为OpenLDAP的主节点,172.31.16.68做为OpenLDAP的备节点,具体RedHat7下OpenLDAP的HA实现可以参考《3.如何RedHat7上实现OpenLDAP的主主同步

3.HAProxy配置


1.修改/etc/haproxy/haproxy.cfg文件,内容如下:

代码语言:javascript
复制
[root@ip-172-31-24-169 ~]# more /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 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
#---------------------------------------------------------------------
# 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 0.0.0.0:1080
    mode http
    option httplog
    maxconn 5000
    stats refresh 30s
    stats  uri /stats 
listen hivejdbc-ldap
    bind 0.0.0.0:10099
    mode tcp
    option tcplog
    balance source
    server ip-172-31-21-83.ap-southeast-1.compute.internal ip-172-31-21-83.ap-southeast-1.compute.internal:10000 check
    server ip-172-31-16-68.ap-southeast-1.compute.internal ip-172-31-16-68.ap-southeast-1.compute.internal:10000 check
    server ip-172-31-30-69.ap-southeast-1.compute.internal ip-172-31-30-69.ap-southeast-1.compute.internal:10000 check

(可左右滑动)

2.保存配置文件并重启haproxy服务

代码语言:javascript
复制
[root@ip-172-31-24-169 ~]# systemctl restart haproxy
[root@ip-172-31-24-169 ~]# systemctl status haproxy 

(可左右滑动)

3.在浏览器访问如下地址查看是否配置成功

代码语言:javascript
复制
http://ip-172-31-24-169.ap-southeast-1.compute.internal:1080/stats

(可左右滑动)

到此完成了HiveServer2服务的负载均衡。

4.配置HiveServer2集成OpenLDAP及Load Balancer


1.使用管理员账号登录CM配置HiveServer2集成OPenLDAP

从CDH5.8.3开始,HS2就又可以使用Kerberos又可以使用LDAP登录了,所以这里只需要配置全局的OpenLDAP配置即可

2.在第三步已经配置了HiveServer2的HAProxy,这里需要配置HiveServer2的Load Balancer

配置HiveServer2的Load Balancer地址为HAProxy的地址及端口。

配置完成LDAP及Load Balancer信息后,保存配置回到CM主页根据提示重启相应服务。

5.使用两种认证方式验证HiveServer2负载均衡


1.通过Beeline使用LDAP认证方式连接HiveServer2

代码语言:javascript
复制
[root@ip-172-31-16-68 ~]# beeline 
beeline> !connect jdbc:hive2://ip-172-31-24-169.ap-southeast-1.compute.internal:10099
Enter username for jdbc:hive2://ip-172-31-24-169.ap-southeast-1.compute.internal:10099: testsentry
Enter password for jdbc:hive2://ip-172-31-24-169.ap-southeast-1.compute.internal:10099: ******
0: jdbc:hive2://ip-172-31-24-169.ap-southeast> select count(*) from tpcds_text_2.customer;

(可左右滑动)

SQL执行成功

HAproxy负载显示,可以看到连接到的是ip-172-31-30-69.ap-southeast-1.compute.internal节点

2.通过beeline使用Kerberos方式登录HiveServer2负载均衡

代码语言:javascript
复制
[root@ip-172-31-24-169 ~]# kinit testsentry
Password for testsentry@FAYSON.COM: 
[root@ip-172-31-24-169 ~]# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: testsentry@FAYSON.COM
Valid starting       Expires              Service principal
04/13/2018 02:55:56  04/14/2018 02:55:56  krbtgt/FAYSON.COM@FAYSON.COM
        renew until 04/20/2018 02:55:56
[root@ip-172-31-24-169 ~]# 

(可左右滑动)

代码语言:javascript
复制
[root@ip-172-31-16-68 ~]# beeline 
beeline> !connect jdbc:hive2://ip-172-31-24-169.ap-southeast-1.compute.internal:10099/;principal=hive/ip-172-31-24-169.ap-southeast-1.compute.internal@FAYSON.COM
0: jdbc:hive2://ip-172-31-24-169.ap-southeast> select count(*) from tpcds_text_2.customer;

(可左右滑动)

SQL执行成功

HAproxy负载显示,可以看到Kerberos认证方式连接的HiveServer2服务为ip-172-31-21-83.ap-southeast-1.compute.internal

6.配置Hue使用HAProxy配置及测试


1.登录CM服务,进入Hue服务搜索“hue_safety_valve.ini”

代码语言:javascript
复制
[beeswax]
hive_server_host=ip-172-31-24-169.ap-southeast-1.compute.internal
hive_server_port=10099

(可左右滑动)

保存配置,回到CM主页重启相应服务。

2.使用testsentry账号登录Hue

HAProxy负载显示

7.总结


  • 从CDH5.8.3开始,HIveServer2就又可以使用Kerberos又可以使用LDAP登录了,所以这里只需要配置全局的OPenLDAP配置即可。
  • 在配置HiveServer2服务的负载均衡时相对简单些,不需要像CDH5.8之前版本需要单独的配置HiveServer2支持OPenLDAP。

原创文章,欢迎转载,转载请注明:转载自微信公众号Hadoop实操

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-04-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Hadoop实操 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 4.配置HiveServer2集成OpenLDAP及Load Balancer
相关产品与服务
负载均衡
负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档