从OpenStack Pike版本开始,Octavia现在是一个独立服务,为OpenStack提供负载平衡服务。
本指南将向您展示如何创建启用了Octavia API的devstack。
阶段1:创建DevStack + 2个nova实例
首先,设置一个至少8 GB RAM和16 GB磁盘空间的vm,确保它已更新。 安装git和您认为有用的任何其他开发人员工具。
Install devstack
git clone https://git.openstack.org/openstack-dev/devstack cd devstack/tools sudo ./create-stack-user.sh cd ../.. sudo mv devstack /opt/stack sudo chown -R stack.stack /opt/stack/devstack
这将在本地克隆当前的devstack代码,然后设置devstack服务将在其下运行的"stack"帐户。 最后,它会将devstack移动到/opt/stack/devstack中的默认位置。
编辑/opt/stack/devstack/local.conf看起来像
[[local|localrc]] enable_plugin octavia https://git.openstack.org/openstack/octavia # If you are enabling horizon, include the octavia dashboard # enable_plugin octavia-dashboard https://git.openstack.org/openstack/octavia-dashboard.git # If you are enabling barbican for TLS offload in Octavia, include it here. # enable_plugin barbican https://github.com/openstack/barbican.git # If you have python3 available: # USE_PYTHON3=True # ===== BEGIN localrc ===== DATABASE_PASSWORD=password ADMIN_PASSWORD=password SERVICE_PASSWORD=password SERVICE_TOKEN=password RABBIT_PASSWORD=password # Enable Logging LOGFILE=$DEST/logs/stack.sh.log VERBOSE=True LOG_COLOR=True # Pre-requisite ENABLED_SERVICES=rabbit,mysql,key # Horizon - enable for the OpenStack web GUI # ENABLED_SERVICES+=,horizon # Nova ENABLED_SERVICES+=,n-api,n-crt,n-obj,n-cpu,n-cond,n-sch,n-api-meta,n-sproxy ENABLED_SERVICES+=,placement-api,placement-client # Glance ENABLED_SERVICES+=,g-api,g-reg # Neutron ENABLED_SERVICES+=,q-svc,q-agt,q-dhcp,q-l3,q-meta,neutron ENABLED_SERVICES+=,octavia,o-cw,o-hk,o-hm,o-api # Cinder ENABLED_SERVICES+=,c-api,c-vol,c-sch # Tempest ENABLED_SERVICES+=,tempest # Barbican - Optionally used for TLS offload in Octavia # ENABLED_SERVICES+=,barbican # ===== END localrc =====
运行stack.sh并进行一些健全性检查
sudo su - stack cd /opt/stack/devstack ./stack.sh . ./openrc openstack network list # should show public and private networks
创建两个我们可以用作测试http服务器的nova实例:
#create nova instances on private network openstack server create --image $(openstack image list | awk '/ cirros-.*-x86_64-.* / {print $2}') --flavor 1 --nic net-id=$(openstack network list | awk '/ private / {print $2}') node1 openstack server creeate --image $(openstack image list | awk '/ cirros-.*-x86_64-.* / {print $2}') --flavor 1 --nic net-id=$(openstack network list | awk '/ private / {print $2}') node2 openstack server list # should show the nova instances just created #add secgroup rules to allow ssh etc.. openstack security group rule create default --protocol icmp openstack security group rule create default --protocol tcp --dst-port 22:22 openstack security group rule create default --protocol tcp --dst-port 80:80
在每个实例上设置一个简单的Web服务器。 ssh到每个实例(用户名'cirros',密码'cubswin :)'或'gocubsgo')并运行
MYIP=$(ifconfig eth0|grep 'inet addr'|awk -F: '{print $2}'| awk '{print $1}') while true; do echo -e "HTTP/1.0 200 OK\r\n\r\nWelcome to $MYIP" | sudo nc -l -p 80 ; done&
阶段2:创建负载均衡器
确保你有'openstack loadbalancer'命令:
pip install python-octaviaclient
创建负载均衡器:
openstack loadbalancer create --name lb1 --vip-subnet-id private-subnet openstack loadbalancer show lb1 # Wait for the provisioning_status to be ACTIVE. openstack loadbalancer listener create --protocol HTTP --protocol-port 80 --name listener1 lb1 openstack loadbalancer show lb1 # Wait for the provisioning_status to be ACTIVE. openstack loadbalancer pool create --lb-algorithm ROUND_ROBIN --listener listener1 --protocol HTTP --name pool1 openstack loadbalancer show lb1 # Wait for the provisioning_status to be ACTIVE. openstack loadbalancer healthmonitor create --delay 5 --timeout 2 --max-retries 1 --type HTTP pool1 openstack loadbalancer show lb1 # Wait for the provisioning_status to be ACTIVE. openstack loadbalancer member create --subnet-id private-subnet --address <web server 1 address> --protocol-port 80 pool1 openstack loadbalancer show lb1 # Wait for the provisioning_status to be ACTIVE. openstack loadbalancer member create --subnet-id private-subnet --address <web server 2 address> --protocol-port 80 pool1
请注意:<web server#address>字段是在阶段1中创建的nova服务器的IP地址。另请注意,直接使用API,您可以在一次API调用中执行上述所有命令。
阶段3:测试负载均衡器
openstack loadbalancer show lb1 # Note the vip_address curl http://<vip_address> curl http://<vip_address>
这应显示每个成员服务器的“欢迎使用<IP>”消息。