安装配置Haproxy
1、安装haproxy
在全部控制节点安装haproxy,以master1节点为例;
如果需要安装最新版本,可参考:http://www.cnblogs.com/netonline/p/7593762.html
yum install haproxy -y
2、配置haproxy.cfg
在全部控制节点配置haproxy.cfg;
haproxy依靠rsyslog输出日志,是否输出日志根据实际情况设定;
备份原haproxy.cfg文件
cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.default
集群的haproxy文件,涉及服务较多,这里针对涉及到的openstack服务,一次性设置完成,如下:
grep -v ^# /etc/haproxy/haproxy.cfg
global
chroot /var/lib/haproxy
daemon
group haproxy
user haproxy
#maxconn 4000
pidfile /var/run/haproxy.pid
defaults
log global
maxconn 65535
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
#timeout client 1m
#timeout server 1m
timeout check 10s
# haproxy监控页
listen stats
bind 0.0.0.0:1080
mode http
stats enable
stats uri /
stats realm OpenStack\ Haproxy
stats auth admin:admin
stats refresh 30s
stats show-node
stats show-legends
stats hide-version
# horizon服务
listen dashboard_cluster
bind 192.168.0.10:80
balance source
option tcpka
option httpchk
option tcplog
server master1 192.168.0.11:80 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:80 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:80 check inter 2000 rise 2 fall 5
# mariadb服务;
# 设置master1节点为master,master2/03节点为backup,一主多备的架构可规避数据不一致性;
# 另外官方示例为检测9200(心跳)端口,测试在mariadb服务宕机的情况下,虽然”/usr/bin/clustercheck”脚本已探测不到服务,但受xinetd控制的9200端口依然正常,导致haproxy始终将请求转发到mariadb服务宕机的节点,暂时修改为监听3306端口
listen galera_cluster
bind 192.168.0.10:3306
balance source
mode tcp
server master1 192.168.0.11:3306 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:3306 backup check inter 2000 rise 2 fall 5
server master3 192.168.0.13:3306 backup check inter 2000 rise 2 fall 5
# 为rabbirmq提供ha集群访问端口,供openstack各服务访问;
# 如果openstack各服务直接连接rabbitmq集群,这里可不设置rabbitmq的负载均衡
listen rabbitmq_cluster
bind 192.168.0.10:5673
mode tcp
option tcpka
balance roundrobin
timeout client 3h
timeout server 3h
option clitcpka
server master1 192.168.0.11:5672 check inter 10s rise 2 fall 5
server master2 192.168.0.12:5672 check inter 10s rise 2 fall 5
server master3 192.168.0.13:5672 check inter 10s rise 2 fall 5
# glance_api服务
listen glance_api_cluster
bind 192.168.0.10:9292
balance source
option tcpka
option httpchk
option tcplog
server master1 192.168.0.11:9292 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:9292 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:9292 check inter 2000 rise 2 fall 5
# glance_registry服务
listen glance_registry_cluster
bind 192.168.0.10:9191
balance source
option tcpka
option tcplog
server master1 192.168.0.11:9191 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:9191 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:9191 check inter 2000 rise 2 fall 5
# keystone_admin_internal_api服务
listen keystone_admin_cluster
bind 192.168.0.10:35357
balance source
option tcpka
option httpchk
option tcplog
server master1 192.168.0.11:35357 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:35357 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:35357 check inter 2000 rise 2 fall 5
# keystone_public _api服务
listen keystone_public_cluster
bind 192.168.0.10:5000
balance source
option tcpka
option httpchk
option tcplog
server master1 192.168.0.11:5000 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:5000 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:5000 check inter 2000 rise 2 fall 5
# 兼容aws ec2-api
listen nova_ec2_api_cluster
bind 192.168.0.10:8773
balance source
option tcpka
option tcplog
server master1 192.168.0.11:8773 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:8773 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:8773 check inter 2000 rise 2 fall 5
listen nova_compute_api_cluster
bind 192.168.0.10:8774
balance source
option tcpka
option httpchk
option tcplog
server master1 192.168.0.11:8774 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:8774 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:8774 check inter 2000 rise 2 fall 5
listen nova_placement_cluster
bind 192.168.0.10:8778
balance source
option tcpka
option tcplog
server master1 192.168.0.11:8778 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:8778 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:8778 check inter 2000 rise 2 fall 5
listen nova_metadata_api_cluster
bind 192.168.0.10:8775
balance source
option tcpka
option tcplog
server master1 192.168.0.11:8775 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:8775 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:8775 check inter 2000 rise 2 fall 5
listen nova_vncproxy_cluster
bind 192.168.0.10:6080
balance source
option tcpka
option tcplog
server master1 192.168.0.11:6080 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:6080 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:6080 check inter 2000 rise 2 fall 5
listen neutron_api_cluster
bind 192.168.0.10:9696
balance source
option tcpka
option httpchk
option tcplog
server master1 192.168.0.11:9696 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:9696 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:9696 check inter 2000 rise 2 fall 5
listen cinder_api_cluster
bind 192.168.0.10:8776
balance source
option tcpka
option httpchk
option tcplog
server master1 192.168.0.11:8776 check inter 2000 rise 2 fall 5
server master2 192.168.0.12:8776 check inter 2000 rise 2 fall 5
server master3 192.168.0.13:8776 check inter 2000 rise 2 fall 5
3、 配置内核参数
全部控制节点修改内核参数;
net.ipv4.ip_nonlocal_bind:是否允许no-local ip绑定,关系到haproxy实例与vip能否绑定并切换;
net.ipv4.ip_forward:是否允许转发
echo "net.ipv4.ip_nonlocal_bind = 1" >>/etc/sysctl.conf
echo "net.ipv4.ip_forward = 1" >>/etc/sysctl.conf
sysctl -p
4、启动Haproxy
开机启动是否设置可自行选择,利用pacemaker设置haproxy相关资源后,pacemaker可控制各节点haproxy服务是否启动
systemctl enable haproxy
systemctl restart haproxy
systemctl status haproxy
访问:http://192.168.0.10:1080/
5、设置pcs资源
任意控制节点操作即可;
添加资源lb-haproxy-clone
pcs resource create lb-haproxy systemd:haproxy --clone
pcs resource
设置资源启动顺序,先vip再lb-haproxy-clone;
通过“cibadmin --query --scope constraints”可查看资源约束配置
pcs constraint order start vip then lb-haproxy-clone kind=Optional
官方建议设置vip运行在haproxy active的节点,通过绑定lb-haproxy-clone与vip服务,将两种资源约束在1个节点;
约束后,从资源角度看,其余暂时没有获得vip的节点的haproxy会被pcs关闭
pcs constraint colocation add lb-haproxy-clone with vip
pcs resource
至此,Haproxy安装配置完成。
下一篇:安装配置keystone认证服务,敬请关注。
本文为原创内容,转载请注明作者+出处+原文链接,禁止商用、禁止修改内容,未经授权不得二次分发,违规必究。
如需联系作者,请联系rancel#stsoo.com(PS:将#替换为@)