版本: icehouse
(1) 安装配置
1 控制节点:
vi /etc/neutron/neutron.conf
service_plugins=router,lbaas
[service_providers]
service_provider=LOADBALANCER:Haproxy:neutron.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default
重启服务
service neutron-server restart
2 网络节点:
apt-get install neutron-lbaas-agent haproxy
vi /etc/neutron/neutron.conf
service_plugins=router,lbaas
[service_providers]
service_provider=LOADBALANCER:Haproxy:neutron.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default
vi /etc/neutron/lbaas_agent.ini
verbose = True
interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
device_driver =neutron.services.loadbalancer.drivers.haproxy.namespace_driver.HaproxyNSDriver
[haproxy]
user_group = haproxy
重启相关服务
service neutron-plugin-openvswitch-agentrestart
service neutron-lbaas-agent restart
3 计算节点: 不需要配置
4 Dashboard上显示’负载均衡器’
openstack dashboard node: 我们的dashboard安装在controller节点上
vi/etc/openstack-dashboard/local_settings.py
OPENSTACK_NEUTRON_NETWORK = {
'enable_lb': True
重启服务
service apache2 restart
service memcached restart
(2) 测试验证
创建两台同样的机器同时运行tomcat服务,工作在8080端口
基本的使用步骤为:
1 租户创建一个pool,初始时的member个数为0;
2 租户在该pool内创建一个或多个 member
3 租户创建一个或多个 healthmonitor
4 租户将health monitors与pool关联
5 租户使用pool创建vip
6 vip绑定floating ip
其中vip绑定Floating IP Dashboard中暂时不支持,只能通过命令行去做
为vip绑定一个floating ip
查找vip的端口号
neutron port-list | grep vip
| 9d2ccba8-8436-4e37-a519-3b365934ac25| vip-8a9c768b-fd41-4cf2-8373-25a637f25244| fa:16:3e:e1:8e:68 | {"subnet_id":"011ae103-3ee6-4bef-975a-b6c8a5e91c9d", "ip_address":"192.168.1.102"} |
创建一个floating ip
neutron floatingip-create ext-net
Created a new floatingip:
…
| floating_ip_address | 10.17.48.175 || id | d4b24ee4-fbda-4253-b1c4-1ac81d37e4ff|…
执行绑定
neutronfloatingip-associate d4b24ee4-fbda-4253-b1c4-1ac81d37e4ff 9d2ccba8-8436-4e37-a519-3b365934ac25
查看haproxy配置
ps -ef | grep haprox
haproxy -f/var/lib/neutron/lbaas/a6886bb4-becd-44ba-86f0-9e388b1942a0/conf -p/var/lib/neutron/lbaas/a6886bb4-becd-44ba-86f0-9e388b1942a0/pid -sf 20917
查看配置/var/lib/neutron/lbaas/a6886bb4-becd-44ba-86f0-9e388b1942a0/conf
global
daemon
user nobody
group haproxy
log /dev/log local0
log /dev/log local1 notice
stats socket/var/lib/neutron/lbaas/a6886bb4-becd-44ba-86f0-9e388b1942a0/sock mode 0666level user
defaults
log global
retries 3
option redispatch
timeout connect 5000
timeout client 50000
timeout server 50000
frontend8a9c768b-fd41-4cf2-8373-25a637f25244
option tcplog
bind 192.168.1.102:8080
mode http
default_backend a6886bb4-becd-44ba-86f0-9e388b1942a0
option forwardfor
backend a6886bb4-becd-44ba-86f0-9e388b1942a0
mode http
balance roundrobin
option forwardfor
timeout check 20s
option httpchk GET /
http-check expect rstatus 200
cookie SRV insert indirect nocache
server 7a55068e-6da9-4da0-bfb8-96a97ee1617c 192.168.1.241:8080 weight100 check inter 10s fall 3 cookie 0
server 24948b51-81e2-40b0-b1ca-cc01159623e8 192.168.1.242:8080 weight100 check inter 10s fall 3 cookie 1
1. 在“frontend” 下的“bind 192.168.1.102:8080 ”是VIP, “backend” 下的“cookie SRVinsert indirect nocache ” 和“server” 行中的”cookie”对应着VIP对象的持久性方法HTTP_COOKIE。“server” 行中的”cookie”值表示Haproxy用来记住某个客户端正在访问哪个后台服务用的。
2. 在“backend”下的“timeoutcheck 20s ”和“option httpchk GET /”是monitor对象的内容;
3. 在“backend”下的“server” 代表Member对象;
4. 在“backend”下的“balance roundrobin ”代表Pool对象的负载均衡方法。
(3)验证Haproxy 的负载均衡,负载均衡方式可以在创建pool时设定
使用curl方法
curl 10.17.48.175:8080/index.jsp --usertomcat:tomcat -D - -o /dev/zero –s
结果:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 19 Mar 2015 08:02:45 GMT
Set-Cookie: SRV=1; path=/
Cache-control: private
再次执行
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 19 Mar 2015 08:02:51 GMT
Set-Cookie: SRV=0; path=/
Cache-control: private
再次执行
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Thu, 19 Mar 2015 08:02:52 GMT
Set-Cookie: SRV=1; path=/
Cache-control: private
观察到SRV=0 SRV=1 交替出现,验证结果是roundrobin均衡生效