首页 > 代码库 > 中小企业openstack私有云布署实践【4.1 上层代理haproxy配置 (科兴环境)】
中小企业openstack私有云布署实践【4.1 上层代理haproxy配置 (科兴环境)】
官方文档上的高可用配置,它推荐的是使用haproxy的上层代理来实现服务组件的主备访问、或者负载均衡访问
一开始我也是使用haproxy来做的,但后来方式改了
测试环境:haproxy + nginx
科兴环境:haproxy
先抛开测试环境,等下我再在4.2节中解说一下配置
两边的kxcontroller主备控制节点均安装
yum install -y haproxy
创建目录
mkdir -p /home/haproxy/log && mkdir -p /home/haproxy/run/
赋予目录权限
chown -R haproxy:haproxy /home/haproxy
在kxcontroller1上的配置示例
[root@kxcontroller1 ~]# vi /etc/haproxy/haproxy.cfg
#全局配置
global
chroot /home/haproxy/log
daemon
group haproxy
maxconn 20000
pidfile /home/haproxy/run/haproxy.pid
user haproxy
defaults
log global
maxconn 20000
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout check 10s
#dashboard界面,不考虑VIP在谁身上,这个服务可以负载均衡访问
listen dashboard_cluster_80
bind 10.120.42.10:80
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:80 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:80 check inter 2000 rise 2 fall 5
#数据库集群访问,使用backup访问实现只访问kxcontroller1,而当1挂了的时候才去访问kxcontroller2
listen galera_cluster_3306
bind 10.120.42.10:3306
mode tcp
balance source
option tcpka
option httpchk
server kxcontroller1 10.120.42.1:3306 check port 9200 inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:3306 backup check port 9200 inter 2000 rise 2 fall 5
#队列 RabbitMQ 访问,使用访问实现只访问1台,当VIP在kxcontroller1上时,它的只访问kxcontroller1上的rabbitmq
listen rabbitmq_cluster_5672
bind 10.120.42.10:5672
mode tcp
balance roundrobin
server kxcontroller1 10.120.42.1:5672 check inter 2000 rise 2 fall 5
#镜像Glance API 访问,使用访问实现只访问1台,无论VIP在谁身上时,它只访问kxcontroller2上的Glance API ,kxcontroller1每天凌晨定时向controller2同步image文件,当kxcontroller2有故障时做手工冷备切换至controller1
listen glance_api_cluster_9292
bind 10.120.42.10:9292
balance source
option tcpka
option httpchk
option tcplog
# server kxcontroller1 10.120.42.1:9292 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:9292 check inter 2000 rise 2 fall 5
#镜像Glance 注册 访问,使用访问实现只访问1台,无论VIP在谁身上时 ,它只访问kxcontroller2上的 Glance 注册 ,kxcontroller1每天凌晨定时向controller2同步image文件,当kxcontroller2有故障时做手工冷备切换至controller1
listen glance_registry_cluster_9191
bind 10.120.42.10:9191
balance source
option tcpka
option tcplog
# server kxcontroller1 10.120.42.1:9191 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:9191 check inter 2000 rise 2 fall 5
#keystone 35357访问,使用访问实现只访问1台,当VIP在kxcontroller1上时,它只访问kxcontroller1上的 keystone 35357
listen keystone_admin_cluster_35357
bind 10.120.42.10:35357
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:35357 check inter 2000 rise 2 fall 5
# server kxcontroller2 10.120.42.2:35357 check inter 2000 rise 2 fall 5
#keystone 5000访问,使用访问实现只访问1台,当VIP在kxcontroller1上时,它只访问kxcontroller1上的 keystone 5000
listen keystone_public_internal_cluster_5000
bind 10.120.42.10:5000
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:5000 check inter 2000 rise 2 fall 5
# server kxcontroller2 10.120.42.2:5000 check inter 2000 rise 2 fall 5
#nova api访问,不考虑VIP在谁身上,这个服务可以负载均衡访问
listen nova_compute_api_cluster_8774
bind 10.120.42.10:8774
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:8774 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8774 check inter 2000 rise 2 fall 5
#nova 元数据 访问,不考虑VIP在谁身上,这个服务可以负载均衡访问
listen nova_metadata_api_cluster_8775
bind 10.120.42.10:8775
balance source
option tcpka
option tcplog
server kxcontroller1 10.120.42.1:8775 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8775 check inter 2000 rise 2 fall 5
#cinder 块存储访问,虽然这里VIP开启,但后端服务我没开启,暂时挂在这里
listen cinder_api_cluster_8776
bind 10.120.42.10:8776
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:8776 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8776 check inter 2000 rise 2 fall 5
#ceilometer 访问,虽然这里VIP开启,但后端服务我没开启,暂时挂在这里
listen ceilometer_api_cluster_8777
bind 10.120.42.10:8777
balance source
option tcpka
option tcplog
server kxcontroller1 10.120.42.1:8777 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8777 check inter 2000 rise 2 fall 5
#nova VNC访问,不考虑VIP在谁身上,这个后端 服务可以负载均衡访问
listen nova_vncproxy_cluster_6080
bind 10.120.42.10:6080
balance source
option tcpka
option tcplog
server kxcontroller1 10.120.42.1:6080 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:6080 check inter 2000 rise 2 fall 5
#neutron api访问,不考虑VIP在谁身上,这个后端服务可以负载均衡访问
listen neutron_api_cluster_9696
bind 10.120.42.10:9696
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:9696 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:9696 check inter 2000 rise 2 fall 5
#swift 块存储访问,虽然这里VIP开启,但后端服务我没开启,暂时挂在这里
listen swift_proxy_cluster_8080
bind 10.120.42.10:8080
balance source
option tcplog
option tcpka
server kxcontroller1 10.120.42.1:8080 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8080 check inter 2000 rise 2 fall 5
#展示普能用户可用于查询的页面http://10.120.42.10:8888/stats 用户和密码admin:admin
listen admin_stats
bind 0.0.0.0:8888
option httplog
#由于defaut没有声明,默认使用tcp,所以在里要额外配置mode http
mode http
stats refresh 30s
stats uri /stats
stats realm Haproxy Manager
stats auth admin:admin
#展示管理员 admin 页面可供修改页面http://10.120.42.10:8008/admin-venic 用户和密码venic:venic8888
listen stats_auth 0.0.0.0:8008
#由于defaut没有声明,默认使用tcp, 所以在listen里要额外配置 mode http
mode http
stats enable
stats uri /admin-venic
stats auth venic:venic8888
stats admin if TRUE
[root@kxcontroller2 ~]# vi /etc/haproxy/haproxy.cfg
#全局配置
global
chroot /home/haproxy/log
daemon
group haproxy
maxconn 20000
pidfile /home/haproxy/run/haproxy.pid
user haproxy
defaults
log global
maxconn 20000
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout check 10s
#dashboard界面,不考虑VIP在谁身上,这个服务可以负载均衡访问
listen dashboard_cluster_80
bind 10.120.42.10:80
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:80 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:80 check inter 2000 rise 2 fall 5
#数据库集群访问,使用backup访问实现只访问kxcontroller1,而当1挂了的时候才去访问kxcontroller2
listen galera_cluster_3306
bind 10.120.42.10:3306
mode tcp
balance source
option tcpka
option httpchk
server kxcontroller1 10.120.42.1:3306 check port 9200 inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:3306 backup check port 9200 inter 2000 rise 2 fall 5
#队列 RabbitMQ 访问,使用访问实现只访问1台,当VIP在kxcontroller2上时,它只访问kxcontroller2上的rabbitmq
listen rabbitmq_cluster_5672
bind 10.120.42.10:5672
mode tcp
balance roundrobin
server kxcontroller1 10.120.42.1:5672 check inter 2000 rise 2 fall 5
#镜像Glance API 访问,使用访问实现只访问1台,无论VIP在谁身上时,它只访问kxcontroller2上的Glance API ,kxcontroller1每天凌晨定时向controller2同步image文件,当kxcontroller2有故障时做手工冷备切换至controller1
listen glance_api_cluster_9292
bind 10.120.42.10:9292
balance source
option tcpka
option httpchk
option tcplog
# server kxcontroller1 10.120.42.1:9292 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:9292 check inter 2000 rise 2 fall 5
#镜像Glance 注册 访问,使用访问实现只访问1台,无论VIP在谁身上时 ,它只访问kxcontroller2上的 Glance 注册 ,kxcontroller1每天凌晨定时向controller2同步image文件,当kxcontroller2有故障时做手工冷备切换至controller1
listen glance_registry_cluster_9191
bind 10.120.42.10:9191
balance source
option tcpka
option tcplog
# server kxcontroller1 10.120.42.1:9191 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:9191 check inter 2000 rise 2 fall 5
#keystone 35357访问,使用访问实现只访问1台,当VIP在kxcontroller2上时,它只访问kxcontroller2上的 keystone 35357
listen keystone_admin_cluster_35357
bind 10.120.42.10:35357
balance source
option tcpka
option httpchk
option tcplog
# server kxcontroller1 10.120.42.1:35357 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:35357 check inter 2000 rise 2 fall 5
#keystone 5000访问,使用访问实现只访问1台,当VIP在kxcontroller1上时,它只访问kxcontroller2上的 keystone 5000
listen keystone_public_internal_cluster_5000
bind 10.120.42.10:5000
balance source
option tcpka
option httpchk
option tcplog
# server kxcontroller1 10.120.42.1:5000 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:5000 check inter 2000 rise 2 fall 5
#nova api访问,不考虑VIP在谁身上,这个服务可以负载均衡访问
listen nova_compute_api_cluster_8774
bind 10.120.42.10:8774
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:8774 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8774 check inter 2000 rise 2 fall 5
#nova 元数据 访问,不考虑VIP在谁身上,这个服务可以负载均衡访问
listen nova_metadata_api_cluster_8775
bind 10.120.42.10:8775
balance source
option tcpka
option tcplog
server kxcontroller1 10.120.42.1:8775 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8775 check inter 2000 rise 2 fall 5
#cinder 块存储访问,虽然这里VIP开启,但后端服务我没开启,暂时挂在这里
listen cinder_api_cluster_8776
bind 10.120.42.10:8776
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:8776 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8776 check inter 2000 rise 2 fall 5
#ceilometer 访问,虽然这里VIP开启,但后端服务我没开启,暂时挂在这里
listen ceilometer_api_cluster_8777
bind 10.120.42.10:8777
balance source
option tcpka
option tcplog
server kxcontroller1 10.120.42.1:8777 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8777 check inter 2000 rise 2 fall 5
#nova VNC访问,不考虑VIP在谁身上,这个后端 服务可以负载均衡访问
listen nova_vncproxy_cluster_6080
bind 10.120.42.10:6080
balance source
option tcpka
option tcplog
server kxcontroller1 10.120.42.1:6080 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:6080 check inter 2000 rise 2 fall 5
#neutron api访问,不考虑VIP在谁身上,这个后端服务可以负载均衡访问
listen neutron_api_cluster_9696
bind 10.120.42.10:9696
balance source
option tcpka
option httpchk
option tcplog
server kxcontroller1 10.120.42.1:9696 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:9696 check inter 2000 rise 2 fall 5
#cinder 块存储访问,虽然这里VIP开启,但后端服务我没开启,暂时挂在这里
listen swift_proxy_cluster_8080
bind 10.120.42.10:8080
balance source
option tcplog
option tcpka
server kxcontroller1 10.120.42.1:8080 check inter 2000 rise 2 fall 5
server kxcontroller2 10.120.42.2:8080 check inter 2000 rise 2 fall 5
#展示普能用户可用于查询的页面http://10.120.42.10:8888/stats 用户和密码admin:admin
listen admin_stats
bind 0.0.0.0:8888
option httplog
#由于defaut没有声明,默认使用tcp,所以在里要额外配置mode http
mode http
stats refresh 30s
stats uri /stats
stats realm Haproxy Manager
stats auth admin:admin
#展示管理员 admin 页面可供修改页面http://10.120.42.10:8008/admin-venic 用户和密码venic:venic8888
listen stats_auth 0.0.0.0:8008
#由于defaut没有声明,默认使用tcp, 所以在listen里要额外配置 mode http
mode http
stats enable
stats uri /admin-venic
stats auth venic:venic8888
stats admin if TRUE
两个科兴的控制主备节点配置好后,
systemctl start haproxy.service
systemctl enable haproxy.service
测试监控页面是否生效,以判断haproxy是否正常工作
http://10.120.42.10:8888/stats
http://10.120.42.10:8008/admin-venic
启动时,没有获取到VIP备节点会发现haproxy服务启动不了。原因如下,
haproxy启动时提示失败:
[ALERT] 164/1100300 (11606) : Starting proxy linuxyw.com: cannot bind socket
修复前,在主备节点上执行 netstat -anp | grep haproxy,检测VIP的端口是否都在监听。
这个问题,其实就是因为你的haproxy没有得到VIP的原因,而你的配置文件又绑定了当前不存在VIP地址,所以会提示以上错误
当然,我们要确保的haproxy服务要提前先启动,不然等故障时,到去手动启动haproxy服务,就无法高可用了。
解决方法:
修改内核参数:
vi /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind=1
保存结果,使内核参数生效
sysctl -p
再启动haproxy就可以启动了
中小企业openstack私有云布署实践【4.1 上层代理haproxy配置 (科兴环境)】
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。