impala keepalived haproxy

NO IMAGE

對impala jdbc訪問提供代理,採用 keepalived haproxy實現
一、haproxy安裝:
1、下載haproxy
下載軟體地址:http://www.haproxy.org/#down
2、安裝haproxy
tar -zxxf haproxy-.tar.gz
cd haproxy-
uname -r 2.6.32-431.29.2.el6.x86_64
註釋:TARGET指定核心版本,而uname -r是檢視核心版本;ARCH指定CPU架構
make TARGET = linux26 PREFIX=/usr/local/haproxy
make install PREFIX =/usr/local/haproxy
3、為Haproxy提供主配置檔案與服務指令碼,並將其新增到系統服務
mkdir /etc/haproxy
cp examples/haproxy.cfg /etc/haproxy
cp examples/haproxy.init /etc/init.d/haproxy
ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
chmod x /etc/init.d/haproxy
chkconfig –add haproxy
4、配置haproxy.cfg,簡單配置如下
主從節點配置(相同):
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
chroot /usr/local/haproxy
uid 99
gid 99
daemon
#debug
#quiet
pidfile /usr/local/haproxy/logs/haproxy.pid

defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000
listen stats
mode http
bind 192.168.194.101:8090 #指定IP地址與Port
stats enable #開啟Haproxy統計狀態
stats refresh 3s #統計頁面自動重新整理時間間隔
stats hide-version #狀態頁面不顯示版本號
stats uri /allen #統計頁面的uri為”/allen”
stats realm Haproxy\ allen #統計頁面認證時提示內容資訊
stats auth admin:admin #統計頁面的使用者名稱與密碼
stats admin if TRUE #啟用或禁用狀態頁面

listen impala 192.168.194.101:25003
mode tcp
option tcplog
balance leastconn
timeout connect 5000
timeout client 50000
timeout server 50000
server hadoop2 192.168.194.12:21050
server hadoop3 192.168.194.13:21050
server hadoop4 192.168.194.14:21050
server hadoop5 192.168.194.15:21050
5、配置haprox日誌輸出(可不配置,提高效能)
編輯/etc/rsyslog.conf檔案,新增如下內容:local3.* (依據haproxy.cfg中的配置而定) /var/log/haproxy.log
重啟rsyslog:service rsyslog restart

二、安裝Keepalived
1、軟連線系統核心目錄
ln -s /usr/src/kernels/2.6.18-194.11.3.el5-i686/ /usr/src/linux
有時你找不到這個核心的路徑,系統安裝後並沒有kernerls的目錄
解決方法:yum install kernel-devel
2、使用最新的ipvs
tar zxvf ipvsadm-1.26.tar.gz
cd ipvsadm-1.26
make
make install
http://www.linuxvirtualserver.org/software/ipvs.html
3、安裝keepalived
編譯安裝:進入keepalive解壓縮目錄。
./configure make && make install
注:configure過程中出現!!! OpenSSL is not properly installed on your system. !!!
解決:yum install -y openssl openssl-devel
註冊服務及配置
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
ln -s /usr/local/sbin/keepalived /usr/sbin/
service keepalived start
配置keepalived.conf:
global_defs {
router_id LVS_DEVEe
}
vrrp_script chk_http_port {
script “/etc/keepalived/check_haproxy.sh”

script “killall -0 haproxy”

interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER(從節點為BACKUP)
interface eth0
virtual_router_id 51
priority 150(優先順序降低為120)
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}

track_script {
chk_http_port
}

virtual_ipaddress {
192.168.194.101
}
}
check_haproxy.sh指令碼配置:
主節點:

!/bin/bash

A=ps -C haproxy --no-header | wc -l
if [ $A -eq 0 ];then
/etc/init.d/haproxy start
echo “haproxy start”
sleep 3
if [ ps -C haproxy --no-header | wc -l -eq 0 ];then
/etc/init.d/keepalived stop
echo “keepalived stop”
fi
Fi
從節點:

!/bin/bash

A=ip a | grep 192.168.194.101 | wc -l
B=ps -ef | grep haproxy | grep -v grep | awk '{print $2}'
if [ A−gt0];then/etc/init.d/haproxystartelsekill−9A -gt 0 ];then
/etc/init.d/haproxy start
else
kill -9 B
fi