为 IBM® Db2 Warehouse 设置 HAProxy 负载均衡器
可以使用单独服务器上的 HAProxy 负载均衡器连接到 Db2® Warehouse MPP 集群的导引节点,代替直接连接到该节点。使用 HAProxy 负载均衡器是可选操作,但建议您这样做。
在故障转移(例如,因为导引节点崩溃)期间,MPP 导引节点角色会转移给 某个数据节点,以便继续执行处理。如果使用 HAProxy 来连接到导引节点,那么 HAProxy 将自动连接到新的导引节点,以便您可以继续使用原始 IP 地址。您不必确定新的导引节点并使用其 IP 地址进行连接。
开始之前
过程
- 以 root 用户身份,登录将为 MPP 集群托管 HAProxy 负载均衡器的 VM。
-
安装 HAProxy:
- 通过发出以下命令,为 HAProxy 服务器安装必需的实用程序:
yum install -y make gcc perl pcre-devel zlib-devel yum install -y openssl.x86_64 openssl-devel.x86_64 openssl-static.x86_64 httpd - 下载最新版本的 HAProxy 程序包。样本命令如下所示。要确定最新版本,请访问
HAProxy 下载页面。
wget -O /tmp/haproxy.tgz http://www.haproxy.org/download/1.6/src/haproxy-1.6.6.tar.gz - 通过发出以下命令,将下载的程序包解压缩:
tar -zxvf /tmp/haproxy.tgz -C /tmp - 切换目录,如下所示:
cd /tmp/haproxy-* - 通过发出以下命令,安装 HAProxy:
make TARGET=linux2628 USE_LINUX_TPROXY=1 USE_ZLIB=1 USE_REGPARM=1 USE_PCRE=1 USE_PCRE_JIT=1 USE_OPENSSL=1 SSL_INC=/usr/include SSL_LIB=/usr/lib ADDLIB=-ldl CFLAGS="-O2 -g -fno-strict-aliasing -DTCP_USER_TIMEOUT=18" make install - 将必需的 HAProxy 文件复制到相应的目录,如下所示:
cp /usr/local/sbin/haproxy /usr/sbin/ cp /tmp/haproxy-1.6.6/examples/haproxy.init /etc/init.d/haproxy - 创建必需的目录,如下所示:
chmod 755 /etc/init.d/haproxy mkdir -p /etc/haproxy mkdir -p /run/haproxy mkdir -p /var/lib/haproxy touch /var/lib/haproxy/stats - 通过发出以下命令,为 HAProxy 添加用户:
useradd -r haproxy
- 通过发出以下命令,为 HAProxy 服务器安装必需的实用程序:
-
通过发出以下命令,确认已正确安装 HAProxy:
haproxy -vv -
通过取消注释 /etc/rsyslog.conf 文件中的
$ModLoad和$UDPServerRun行,配置 rsyslog 实用程序,如下所示:#================================== # Provides UDP syslog reception $ModLoad imudp $UDPServerRun 514 #================================== -
通过发出以下命令,重新启动 rsyslog 实用程序:
HAProxy 将使用 /var/log/haproxy.log 文件。service rsyslog restart -
创建 /etc/haproxy/haproxy.cfg
配置文件,并使其包含以下示例中的信息,但下列内容例外:
- 将服务器名称和 IP 地址替换为您自己的服务器名称和 IP 地址。
- 在
stats auth haproxy:temp4now行,将temp4now替换为您自己的密码。
#============================================================= # Beginning of /etc/haproxy/haproxy.cfg #============================================================= global log 127.0.0.1 local2 #Log configuration chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin stats timeout 30s user haproxy group haproxy daemon defaults log global mode http option httplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000 listen http_web bind *:80 mode http stats enable stats hide-version stats realm Haproxy\ Statistics stats uri /stats stats auth haproxy:temp4now # [HTTPS Site Configuration] listen https_web bind *:8443 mode tcp balance source# Load Balancing algorithm reqadd X-Forwarded-Proto:\ http server bluhelix50 169.53.136.142:8443 check server bluhelix51 169.53.136.143:8443 check server bluhelix52 169.53.136.145:8443 check server bluhelix57 169.53.136.132:8443 check server bluhelix58 198.11.214.169:8443 check server bluhelix59 169.53.136.156:8443 check # port 50000 access listen bluhelix_port_50000 bind *:50000 mode tcp balance source reqadd X-Forwarded-Proto:\ http server bluhelix50 169.53.136.142:50000 check server bluhelix51 169.53.136.143:50000 check server bluhelix52 169.53.136.145:50000 check server bluhelix57 169.53.136.132:50000 check server bluhelix58 198.11.214.169:50000 check server bluhelix59 169.53.136.156:50000 check # SSL port 50001 access listen bluhelix_port_50001 bind *:50001 mode tcp balance source reqadd X-Forwarded-Proto:\ http server bluhelix50 10.122.59.160:50001 check server bluhelix51 10.122.59.131:50001 check server bluhelix52 10.122.59.136:50001 check server bluhelix57 10.122.59.139:50001 check server bluhelix58 10.90.61.59:50001 check server bluhelix59 10.122.59.152:50001 check #============================================================= # End of /etc/haproxy/haproxy.cfg #============================================================= -
通过发出以下命令,启动 HAProxy 服务:
service haproxy start -
通过发出以下命令,检查 HAProxy 服务的状态:
service haproxy status输出应该显示状态为 Active: active (running),如以下示例所示:
haproxy.service - SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments. Loaded: loaded (/etc/rc.d/init.d/haproxy) Active: active (running) since Wed 2016-07-13 19:21:12 CDT; 12min ago -
使 /etc/haproxy/haproxy.cfg file 中的更改生效:
- 发出以下命令:
service haproxy restart - 如果显示 Starting frontend GLOBAL: cannot bind UNIX socket
[/run/haproxy/admin.sock] 消息,请发出以下命令:
mkdir -p /run/haproxy/ service haproxy restart
- 发出以下命令:
-
尝试通过负载均衡器 VM IP 地址访问 Web 控制台,以测试 HAProxy 设置,如下所示:
https://IP_address_of_load_balancer_VM:8443
下一步做什么
https://IP_address_of_load_balancer_VM/stats