本帖最后由 52Pig 于 2014-10-8 22:53 编辑
阅读导读:
1.HOT的spec文档包含哪些内容?
2.public网络和路由器是通过什么相连的?
理解好了hello world HOT 模板,然后接下来就可以看HOT的spec文档了,包括Structure,PGS,PS,RS,OS以及Intrinsic Functions
现在Heat支持的Resource类型可以在http://docs.openstack.org/develo ... uide/openstack.html上找到,下面主要探索advancedservices(LB,FW,VPN)的相关模板,需要在阅OpenStack Resource Types 以及的前提下,才能了解下面模板的具体含义。
Loadbalancer 模板
接下来首先根据下手做一个Loadbalancer模板,网络拓扑图如下:
如上图所示,我们的服务器网络的网址范围为10.0.0.0/24,负载均衡器网络的网址范围是192.168.40.0/24,public网络链接办公网络,网址范围是192.168.10.224/28。路由器链接了所有三个网络。public网络和路由器是通过路由器的”网关臂(NeutronAPI中router的gateway)”相连的。路由器把服务器网络和负载均衡器网络的IP地址SNAT成路由器的”网关臂”在public网络的地址。这样他们就可以访问办公网络的IP啦。但是如果要想从办公网络访问服务器网络和负载均衡器网络,我们还需要动态地址(FloatingIP)。
Network 设备及拓扑
- public_net: 192.168.10.224/28
-
- lb_net: 192.168.40.0/24
-
- server_net: 10.0.0.0/24
-
- router: {
-
- gateway: <from public_net>,
-
- interface1: lb_net,
-
- interface2: server_net
-
- }
复制代码
根据以上信息:设置LB网络拓扑图模板network_topology.template如下,注意在这之前你可能需要清理网络拓扑环境,然后设置合适的br-ex配置(sudo ifconfig br-ex 192.168.10.225netmask 255.255.224.0 up),方能够访问public_net:
复制代码 #heat template-validate--template-file ./network_topology.template然后运行如下CLI命令,则自动生成相应的网络拓扑,省去不少命令行敲字,而且实验结束,直接heatstack-delete 掉即可。
#heat stack-create -f./network_topology.template lb-net-topology
网络拓扑用到的Resource资源如下:
- OS::Neutron::Net: http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Neutron::Net
-
- OS::Neutron::Subnet:
-
- http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Neutron::Subnet
-
- OS::Neutron::Router:
-
- http://docs.openstack.org/developer/heat/template_guide/openstack.html#OS::Neutron::Router
复制代码
接下来开始部署LB了, 主要有下面个资源:
- Pool:
-
- VIP:
-
- Floating IP for VIP
-
- HealthMonitor:
-
- 2 Pool Member instances (内部运行简单的web server):
复制代码
根据以上信息设计LB模板如下:
- heat_template_version: 2013-05-23
-
- description: >
- LB service deployment HOT template reference to
- http://www.ustack.com/blog/neutron_loadbalance/
-
- parameters:
- image_name:
- type: string
- label: Image Name
- description: Image to be used for compute instance
- default: cirros-0.3.0-i386-uec
- instance_type:
- type: string
- label: Instance Type
- description: Type of instance (flavor) to be used
- default: m1.tiny
- health_monitor_type:
- type: string
- label: Type of HealthMonitor
- constraints:
- - allowed_values: [PING, TCP, HTTP, HTTPS]
- default: HTTP
- pool_name:
- type: string
- label: The Name of Pool
- default: pool
- lb_method:
- type: string
- label: The Algorithm used to distribute load between the memebers of pool
- constraints:
- - allowed_values: [ROUND_ROBIN, LEAST_CONNECTIONS, SOURCE_IP]
- default: ROUND_ROBIN
- pool_protocol:
- type: string
- label: Protocol for Pool Balancing
- constraints:
- - allowed_values: [HTTP, HTTPS, TCP]
- default: HTTP
- lb_subnet_id:
- type: string
- label: Loadbalancer Subnet uuid
- vip_name:
- type: string
- label: Name of VIP
- default: vip
- vip_address:
- type: string
- label: Address of VIP which must be within lb_subnet
- session_persistence_type:
- type: string
- label: Session Persistence Type
- constraints:
- - allowed_values: [SOURCE_IP, HTTP_COOKIE, APP_COOKIE]
- default: HTTP_COOKIE
- vip_protocol_port:
- type: number
- label: VIP protocol port
- default: 8080
- member_protocol_port:
- type: number
- label: Member protocol port
- default: 8080
- public_net_id:
- type: string
- label: Public Network uuid
- server_net_id:
- type: string
- label: Web Servers Network uuid
-
-
- outputs:
- vip_floating_ip:
- description: FloatingIP of VIP
- value: {get_attr: [floatingip, floating_ip_address]}
- member1_ip_address:
- description: IP address of member1
- value: {get_attr: [member1, first_address]}
- member2_ip_address:
- description: IP address of member2
- value: {get_attr: [member2, first_address]}
- vip:
- description: VIP info
- value: {get_attr: [pool, vip]}
- lb_keypair_private_key:
- description: private key of KeyPair for 'ssh-add use'
- value: {get_attr: [lb_keypair, private_key]}
-
-
- resources:
- lb_keypair:
- type: OS::Nova::KeyPair
- properties:
- name: lb_keypair
- save_private_key: True
- health_monitor:
- type: OS::Neutron::HealthMonitor
- properties:
- delay: 10
- expected_codes: "200"
- http_method: GET
- max_retries: 3
- timeout: 20
- type: {get_param: health_monitor_type}
- url_path: /
- pool:
- type: OS::Neutron::Pool
- depends_on: health_monitor
- properties:
- admin_state_up: False
- name: {get_param: pool_name}
- lb_method: {get_param: lb_method}
- protocol: {get_param: pool_protocol}
- monitors: [{get_resource: health_monitor}]
- subnet_id: {get_param: lb_subnet_id}
- vip:
- session_persistence:
- type: {get_param: session_persistence_type}
- name: {get_param: vip_name}
- address: {get_param: vip_address}
- protocol_port: {get_param: vip_protocol_port}
- member1:
- type: OS::Nova::Server
- properties:
- name: server1
- key_name: {get_resource: lb_keypair}
- image: {get_param: image_name}
- flavor: {get_param: instance_type}
- networks:
- - {network: {get_param: server_net_id}}
- member2:
- type: OS::Nova::Server
- properties:
- name: server2
- key_name: {get_resource: lb_keypair}
- image: {get_param: image_name}
- flavor: {get_param: instance_type}
- networks:
- - {network: {get_param: server_net_id}}
- pool_member1:
- type: OS::Neutron::PoolMember
- depends_on: [pool, member1]
- properties:
- address: {get_attr: [member1, first_address]}
- pool_id: {get_resource: pool}
- protocol_port: {get_param: member_protocol_port}
- weight: 100
- pool_member2:
- type: OS::Neutron::PoolMember
- depends_on: [pool, member2]
- properties:
- address: {get_attr: [member2, first_address]}
- pool_id: {get_resource: pool}
- protocol_port: {get_param: member_protocol_port}
- weight: 100
- floatingip:
- type: OS::Neutron::FloatingIP
- depends_on: pool
- properties:
- fixed_ip_address: {get_param: vip_address}
- floating_network_id: {get_param: public_net_id}
- port_id: {get_attr: [pool, vip, port_id]}
复制代码
stack@vm:~/hot-files$ heat stack-create lbaas -f ./lbaas.template -P"public_net_id=842a7996-b8ca-4f75-8bfa-72d930780694;lb_subnet_id=f33b03a9-0f39-4c25-a9fa-94d63042f206;server_net_id=33c2e2db-121f-489e-bdc0-
06d091472727;vip_address=192.168.40.3"然后运行如下命令部署lb模板:
Note: 可能注意到了现在Poo的admin_state_up是False状态,这是由于LBaaS Haproxy的一个bug,如果不设置,会导致vip直接返回Error,导致Heat模板运行中断,所以暂时设置为False,等部署好后,再打开admin_state_up,打开后发现Member是INACTIVE状态的,因为现在member还没有开启web server,我用很多方法试图用String,template,以及get_file将user_data注入到VM中,但不知道为什么都失败了,所以你只能自己进到VM中启动一个简单的web服务器了,我的如下所示:
- $ while true
-
- > do
-
- > echo -e 'HTTP/1.0 200 OK\r\n\r\n<serverX>' | nc -l -p 8080
-
- > done
复制代码
启动后就看到Member变为ACTIVE状态了。
拿到VIP的floatingIP,然后就可以测试LB的运行状态了,结果如下:
LB成功运行!
另外: Keypair的用法:你可以import a keypair,将你的操作console的public key引入,也可以像上面lb模板创建一个keypair,然后将lb_private_key保存到一个文件(lb_private_key.pem)中,然后给VM加一个floatingIP
- #eval `ssh-agent`
-
- #ssh-add lb_private_key.pem
复制代码
然后你就可以通过ssh访问VM了,其他可以进noVNC界面对VM进行相关操作。
LB模板用到的resources有: OS::Nova::Server, OS::Nova::KeyPair, OS::Neutron::Pool, OS::Neutron::PoolMember, OS::Neutron::HealthMonitor, OS::Neutron::FloatingIP
用的不方便的地方:
1.Template查错功能有待提高,阐释不清楚或者错误张冠李戴
2.没有类似于action-continue –force的功能,比如LBaaS创建的VIP状态返回error是由于haproxy内部的一个bug,这类人类可控的错误希望能够just 忽略掉然后继续运行。
3.不知道为什么,用heat一直不能把user_data注入VM中
相关内容:
OpenStack Heat 模板学习一 之hello world
|