impala的負載均衡,使用haproxy來作,主要是比較簡單。安裝後作一個小配置就行。redis
主要用的就是haproxy四層交換機的特性,講全部指向haproxy主機和端口的請求,轉發到相應的主機:端口上。sql
cdh官網裏面的信息已經比較久了,有些配置須要改,所以作一個筆記。shell
yum install haproxy
vim /etc/haproxy/haproxy.cfg
下面是一個實際的配置文件,主機信息已經隱藏。vim
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 local0 log 127.0.0.1 local1 notice 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 # # You might need to adjust timing values to prevent timeouts. #--------------------------------------------------------------------- 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 maxconn 3000 #鏈接時間須要修改,由於若是時間較短的話會出現,任務在執行,可是鏈接已經斷開因此獲取不到結果的狀況。 timeout connect 3600000ms timeout client 3600000ms timeout server 3600000ms # # This sets up the admin page for HA Proxy at port 25002. # listen stats :25002 balance mode http stats enable stats auth admin:admin # This is the setup for Impala. Impala client connect to load_balancer_host:25003. # HAProxy will balance connections among the list of servers listed below. # The list of Impalad is listening at port 21000 for beeswax (impala-shell) or original ODBC driver. # For JDBC or ODBC version 2.x driver, use port 21050 instead of 21000. # 注意:haproxy-host-ip是haproxy的ip地址,主機名也能夠 listen impala haproxy-host-ip:25003 # impala負載均衡須要第四層的,因此填tcp mode tcp option tcplog balance leastconn #主機列表 #impala-host-1是impala的主機列表 #因爲是要對jdbc的請求進行轉發,因此端口設置的是21050 server impala-1 impala-host-1:21050 server impala-2 impala-host-2:21050 server impala-3 impala-host-3:21050 server impala-4 impala-host-4:21050
/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg
使用起來十分方便,區別僅僅至關因而修改了一個ip地址和端口而已,其他不變。bash
jdbc:hive2://haproxy-host-ip:25003/;auth=noSasl
網絡知識基本上是廢的差很少了,以前四層交換機都想不起來是什麼東東。從新稍微溫習一下基礎,在腦子裏面就會對這些負載均衡仍是什麼幾層交換機理解了,再來作工程,至少是從原理上能有所把握,不至因而爲了作東西而作東西,一堆堆的組件拼接。markdown
來源:
http://blog.csdn.net/zhaodedong
http://zhaodedong.leanote.com
http://zhaodedong.com網絡
2016-04-05 15:17:00 hzct負載均衡