网站首页 > 技术教程 正文
温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。
Fayson的github:
https://github.com/fayson/cdhproject
提示:代码块部分可以左右滑动查看噢
1.文档编写目的
在使用Hive JDBC连接HiveServer2服务时,默认是不带负载均衡的,但一个HiveServer2很可能会产生单点的问题,这里我们就需要考虑HiveServer2的负载均衡。
但我们常常会碰到企业已经在用Nginx,Nginx毕竟在http和反向代理这块是最优秀的,这个时候我们就需要考虑复用Nginx,在前面的文章Fayson也介绍了《
如何使用Nginx实现Impala负载均衡
》。所以Fayson在这篇文章就介绍一下如何使用Nginx实现HiveServer2服务的负载均衡。
- 内容概述
1.Nginx安装及启停
2.配置HiveServer2负载均衡策略
3.JDBC测试及配置HiveServer2 Balancer
4.常见问题
- 测试环境
1.CM和CDH版本为5.15.0
2.采用root用户操作
3.Nginx1.12.2
4.集群未启用Kerberos
2.Nginx服务安装及启停
1.下载Nginx安装包,下载地址如下
选择集群中任意一台服务器用来安装Nginx服务或者选用一台独立的服务器用来部署Nginx,需要确保Nginx所在的服务器与集群中所有的HiveServer2节点网络是通的(包括端口号10000)
http://nginx.org/download/nginx-1.12.2.tar.gz
(可左右滑动)
2.解压nginx-1.21.2.tar.gz压缩包,并进行编译安装
[root@cdh05 ~]# tar -zxf nginx-1.12.2.tar.gz [root@cdh05 ~]# cd nginx-1.12.2 [root@cdh05 nginx-1.12.2]# ./configure --with-stream [root@cdh05 nginx-1.12.2]# make && make install
(可左右滑动)
注意:必须编译stream模块
默认Nginx的安装目录为/usr/local/nginx
3.将nginx服务加如系统自启动服务,在/etc/init.d目录下创建nginx脚本,内容如下
#!/bin/sh #chkconfig: - 85 15 #description: Http server daemon DESC="nginx daemon" NAME=nginx DAEMON=/usr/local/nginx/sbin/nginx set -e [ -x "$DAEMON" ] || exit 0 do_start() { $DAEMON || echo -n "nginx is already running"; } do_stop() { $DAEMON -s stop || echo -n "nginx stop failed" } do_reload() { $DAEMON -s reload || echo -n "nginx reload failed" } case "$1" in start) do_start ;; stop) do_stop ;; reload|graceful) do_reload ;; restart) do_stop sleep 2 do_start ;; *) echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2 exit 3 ;; esac exit 0
(可左右滑动)
注意:上图标注部分为Nginx的home目录,根据自己安装的目录进行调整。
4.设置自启动脚本执行权限
[root@cdh05 ~]# chmod +x /etc/init.d/nginx [root@cdh05 ~]# ll /etc/init.d/nginx
(可左右滑动)
5.将nginx服务加入系统自启动并设置开机启动
[root@cdh05 ~]# chkconfig --add nginx [root@cdh05 ~]# chkconfig nginx on
(可左右滑动)
6.启动与停止Nginx,这里Fayson将Nginx的端口修改为8089
[root@cdh05 conf]# service nginx start [root@cdh05 conf]# netstat -an |grep 80
(可左右滑动)
[root@cdh05 conf]# service nginx stop
(可左右滑动)
7.测试Nginx是否正常访问,在浏览器输入http://hostname
如上图显示则表示Nginx已成功安装并启动。
3.配置HiveServer2负载均衡策略
1.修改/usr/local/nginx/conf/nginx.conf文件,在文件末尾增加如下配置
stream{ log_format basic '$remote_addr [$time_local] ' '$protocol $status $bytes_sent $bytes_received' '$session_time'; upstream hiveserver2 { least_conn; #路由策略:least_conn:最少连接 server cdh01.fayson.com:10000; server cdh01.fayson.com:10000; } server{ #hiveserver2 jdbc 负载均衡 listen 10010; proxy_pass hiveserver2; } }
(可左右滑动)
2.重启Nginx服务
[root@cdh05 ~]# service nginx restart
(可左右滑动)
4.测试HiveServer2负载均衡
1.使用beeline通过JDBC访问负载均衡地址cdh05.fayson.com:10010
[root@cdh05 conf]# beeline beeline> !connect jdbc:hive2://cdh05.fayson.com:10010 hive hive 0: jdbc:hive2://cdh05.fayson.com:10010> select count(*) from hosts;
(可左右滑动)
执行成功
5.配置HiveServer2 Load Balancer
1.登录CM进入hive服务界面,搜索“load balancer”,配置为HiveServer2服务负载均衡地址
保存配置后,回到CM主页根据提示重启相应服务。
6.常见问题
1.Nginx编译时报错./configure: error: C compiler cc is not found
[root@ip-172-31-6-148 nginx-1.12.2]# ./configure checking for OS + Linux 2.6.32-431.el6.x86_64 x86_64 checking for C compiler ... not found ./configure: error: C compiler cc is not found [root@ip-172-31-6-148 nginx-1.12.2]#
(可左右滑动)
解决方法:
yum -y install gcc gcc-c++
(可左右滑动)
2.Nginx编译报错./configure: error: the HTTP rewritemodule requires the PCRE library
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option.
(可左右滑动)
解决方法:
yum -y install pcre-devel
(可左右滑动)
提示:代码块部分可以左右滑动查看噢
为天地立心,为生民立命,为往圣继绝学,为万世开太平。
温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。
推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。
原创文章,欢迎转载,转载请注明:转载自微信公众号Hadoop实操
猜你喜欢
- 2024-10-12 高端Linux 脚本很有用,赶紧学起来!
- 2024-10-12 linux日常脚本(linux有意思的脚本)
- 2024-10-12 彻底搞懂nginx基本使用配置(nginx常用配置参数)
- 2024-10-12 nginx的脚本特性-nginScript笔记(nginx执行lua脚本)
- 2024-10-12 详解shell脚本case条件语句,开发各种服务启动脚本跳板机
- 2024-09-25 详解利用系统函数模拟实现nginx 系统脚本启动的特殊颜色专业效果
- 2024-09-25 centos 7.9 shell脚本安装nginx-1.20.2
- 2024-09-25 CentOS 开机启动脚本(centos开机启动脚本)
- 2024-09-25 Nginx日志安全分析脚本(nginx日志大量502)
- 2024-09-25 redis&nginx运行参数采集脚本
你 发表评论:
欢迎- 最近发表
-
- Win10 TH2正式版官方ESD映像转换ISO镜像方法详解
- 使用iso镜像升级到Windows 10的步骤
- macOS Ventura 13.2 (22D49) Boot ISO 原版可引导镜像
- 安利一个用ISO镜像文件制作引导U盘的的小工具RUFUS
- CentOS 7使用ISO镜像配置本地yum源
- 用于x86平台的安卓9.0 ISO镜像发布下载:通吃I/A/N、完全免费
- AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术
- Rufus写入工具简洁介绍与教程(写入模式)
- 新硬件也能安装使用了,Edge版Linux Mint 21.3镜像发布
- 开源工程师:Ubuntu应该抛弃32位ISO镜像
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)