OpenStack 安装 LBaaS
- OpenStack 版本: Mitaka
- OpenStack Server OS: CentOS 7
网络节点:
安装包:
yum install haproxy
yum install openstack-neutron-lbaas
修改配置文件 /etc/neutron/lbaas_agent.ini
:
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver //启用基于OVS插件的LBaaS时需要Open vSwitch LBaaS驱动
device_driver = neutron_lbaas.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver //使用HAproxy作为LBaaS Driver
修改配置文件 /etc/neutron/neutron.conf
:
service_plugins = lbaas // 有其他的Plugins保留,添加 lbaas
启动LBaaS服务:
systemctl enable neutron-lbaas-agent.service
systemctl start neutron-lbaas-agent.service
控制节点:
安装包:
yum install python-neutron-lbaas
修改配置文件 /etc/neutron/neutron.conf
:
service_plugins = lbaas // 有其他的Plugins保留,添加 lbaas
[service_providers]
service_provider=LOADBALANCER:Haproxy:neutron_lbaas.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default // 使用HAproxy作为LBaaS Driver
重启 Neutron-Server 服务
systemctl restart neutron-server
修改配置文件 /etc/openstack-dashboard/local_settings
:
OPENSTACK_NEUTRON_NETWORK = {
...
'enable_lb': True
...
CLI
创建Pool:
neutron lb-pool-create --lb-method {ROUND_ROBIN,LEAST_CONNECTIONS,SOURCE_IP} --name NAME --protocol {HTTP,HTTPS,TCP} --subnet-id SUBNET
创建Member:
neutron lb-member-create --address ADDRESS --protocol-port PROTOCOL_PORT POOL
创建Healthmonitor:
neutron lb-healthmonitor-create --max-retries MAX_RETRIES --timeout TIMEOUT --type {PING,TCP,HTTP,HTTPS}
neutron lb-healthmonitor-associate HEALTH_MONITOR_ID POOL
创建VIP:
neutron lb-vip-create --name NAME --protocol-port PROTOCOL_PORT --protocol {TCP,HTTP,HTTPS} --subnet-id SUBNET POOL [--connection-limit CONNECTION_LIMIT]
VIP绑定Floating IP:
neutron floatingip-associate FLOATINGIP_ID VIP_PORT
验证
创建Pool:
neutron lb-pool-create --lb-method ROUND_ROBIN --name POOL_NAME --protocol TCP --subnet-id SUBNET_ID
创建Member:
neutron lb-member-create --address 172.168.0.13 --protocol-port 22 POOL_ID
neutron lb-member-create --address 172.168.0.14 --protocol-port 22 POOL_ID
neutron lb-member-create --address 172.168.0.15 --protocol-port 22 POOL_ID
创建VIP:
neutron lb-vip-create --name VIP_NAME --protocol-port 22 --protocol TCP --subnet-id SUBNET_ID POOL_ID
VIP创建结果:
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| address | 172.168.0.16 |
负载均衡池中运行了3个SSH Server,从验证结果可以看到SSH到VIP的流量被平均分配到了负载均衡池中的3个Member
查看LBaaS进程:
ps -ef | grep lbaas
neutron 1689 1 0 Jul29 ? 00:18:17 /usr/bin/python2 /usr/bin/neutron-lbaas-agent --config-file /usr/share/neutron/neutron-dist.conf --config-file /usr/share/neutron/neutron-lbaas-dist.conf --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/lbaas_agent.ini --config-dir /etc/neutron/conf.d/common --config-dir /etc/neutron/conf.d/neutron-lbaas-agent --log-file /var/log/neutron/lbaas-agent.log
nobody 25695 1 0 08:44 ? 00:00:00 haproxy -f /var/lib/neutron/lbaas/d34d253b-d72f-4a9f-9237-93020569c2fc/conf -p /var/lib/neutron/lbaas/d34d253b-d72f-4a9f-9237-93020569c2fc/pid
可以看到HAproxy配置文件在/var/lib/neutron/lbaas/d34d253b-d72f-4a9f-9237-93020569c2fc/conf
less /var/lib/neutron/lbaas/d34d253b-d72f-4a9f-9237-93020569c2fc/conf
global
daemon
user nobody
group haproxy
log /dev/log local0
log /dev/log local1 notice
stats socket /var/lib/neutron/lbaas/d34d253b-d72f-4a9f-9237-93020569c2fc/sock mode 0666 level user
defaults
log global
retries 3
option redispatch
timeout connect 5000
timeout client 50000
timeout server 50000
frontend 4bad7a5a-6367-4848-8953-8bff5010f0ab
option tcplog
bind 172.168.0.16:22
mode tcp
default_backend d34d253b-d72f-4a9f-9237-93020569c2fc
backend d34d253b-d72f-4a9f-9237-93020569c2fc
mode tcp
balance roundrobin
server 79599c10-43a8-4c48-9a72-c627829c682e 172.168.0.15:22 weight 1
server ccdc28ec-120b-47aa-8cf2-8a43433e1f31 172.168.0.14:22 weight 1
server f3508488-e0fb-4c62-b032-d386cf230b58 172.168.0.13:22 weight 1
- frontend 下的 bind 172.168.0.16:22 就是VIP
- backend 下的 server 就是Member对象
- backend 下的 balance roundrobin 就是Pool对象的负载均衡方法