BOSH是CloudFoundry提供的用来安装部署和升级CloudFoundry的自动化工具,可是说是CloudFoundry的一部分。总体来说,BOSH是Client/Server结构, BOSH客户端称作BOSH CLI,BOSH服务器端由BOSH Director,NATS,HealthMonitor等组件组成, 详见http://docs.cloudfoundry.org/bosh/
完整的BOSH是一个分布式的环境,本文为了简化BOSH的安装,将BOSH所有的组件安装在一个虚拟机上,BOSH的这种部署方式称为MicroBOSH。
将描述如果在CentOS环境下部署BOSH客户端和在OpenStack环境上部署MicroBOSH工具。
3.1 安装ruby环境
3.1.1 作者使用rbenv来管理ruby,所以安装rbenv和ruby 环境 (如果rbenv已经安装完成或者使用rvm可跳过此步)
[python] view plaincopy
- # rm -rf $HOME/.rbenv
- # git clone git://github.com/sstephenson/rbenv.git $HOME/.rbenv
- # git clone https://github.com/sstephenson/ruby-build.git $HOME/.rbenv/plugins/ruby-build
- # echo ‘export PATH="$HOME/.rbenv/bin:$PATH"‘ >> ~/.bash_profile
- # source ~/.bash_profile
- # echo ‘eval "$(rbenv init -)"‘ >> ~/.bash_profile
- # source ~/.bash_profile
- # rbenv install 1.9.3-p547
- # rbenv global 1.9.3-p547
3.1.2 安装bosh客户端
[python] view plaincopy
- # rbenv rehash
- # gem update --system
- # gem pristine rake
- # gem install bundler OpenSSL
- # gem install nokogiri -- --use-system-libraries
- # gem install pg -- --use-system-libraries
- # gem install bosh_cli
- # gem install bosh_cli_plugin_micro
3.1.3 为安置MicroBosh和CloudFoundry配置SecurityGroup
(1) 创建BOSH security group,允许bosh访问
[python] view plaincopy
- # nova secgroup-create bosh "security group for bosh access”
- # nova secgroup-add-rule bosh udp 53 53 0.0.0.0/0
- # nova secgroup-add-rule bosh tcp 4222 4222 0.0.0.0/0
- # nova secgroup-add-rule bosh udp 68 68 0.0.0.0/0
- # nova secgroup-add-rule bosh tcp 25555 25555 0.0.0.0/0
- # nova secgroup-add-group-rule bosh bosh tcp 1 65535
- # nova secgroup-add-rule bosh tcp 6868 6868 0.0.0.0/0
- # nova secgroup-add-rule bosh tcp 53 53 0.0.0.0/0
- # nova secgroup-add-rule bosh tcp 25250 25250 0.0.0.0/0
- # nova secgroup-add-rule bosh tcp 25777 25777 0.0.0.0/0
(2) 创建security group, 允许SSH 访问
[python] view plaincopy
- # nova secgroup-create ssh "security group for ssh access”
- # nova secgroup-add-rule ssh icmp -1 -1 0.0.0.0/0
- # nova secgroup-add-rule ssh tcp 22 22 0.0.0.0/0
- # nova secgroup-add-rule ssh udp 68 68 0.0.0.0/0
(3) 创建Cloudfoundry内网security group
[python] view plaincopy
- # nova secgroup-create cf-private "cf internal security group"
- # nova secgroup-add-rule cf-private udp 68 68 0.0.0.0/0
- # nova secgroup-add-rule cf-private udp 3456 3456 0.0.0.0/0
- # nova secgroup-add-group-rule cf-private bosh tcp 1 65535
(4) 创建CloudFoundry外网访问security group
[python] view plaincopy
- # nova secgroup-create cf-public "security group for cloudfoundry public access"
- # nova secgroup-add-rule cf-public tcp 443 443 0.0.0.0/0
- # nova secgroup-add-rule cf-public udp 68 68 0.0.0.0/0
- # nova secgroup-add-rule cf-public tcp 80 80 0.0.0.0/0
3.2 部署MicroBosh
3.2.1 创建microbosh keypair
[python] view plaincopy
- # nova keypair-add microbosh > microbosh.cer
- # chmod 400 microbosh.cer
3.2.2 创建工作目录
[python] view plaincopy
- # mkdir -p ~/bosh-workspace/deployments/microbosh-openstack
- # cd ~/bosh-workspace/deployments/microbosh-openstack
3.2.3 为microbosh创建一个floating ip
[python] view plaincopy
- # nova floating-ip-create public
- +--------------+-----------+----------+--------+
- | Ip | Server Id | Fixed Ip | Pool |
- +--------------+-----------+----------+--------+
- | 172.24.4.229 | | - | public |
- +--------------+-----------+----------+--------+
3.2.4 创建并且编辑部署描述文件microbosh.yml
[ruby] view plaincopy
- ---
- name: microbosh-openstack
- logging:
- level: DEBUG
- network:
- type: dynamic
- vip: 172.24.4.229
- cloud_properties:
- net_id: bfc9b30b-8b44-4f97-a762-c39b2f774d78
- resources:
- persistent_disk: 16384
- cloud_properties:
- instance_type: m1.medium
- cloud:
- plugin: openstack
- properties:
- openstack:
- auth_url: http://<ip>:5000/v2.0
- username: demo
- api_key: 73b3b497ca3a42d1
- tenant: demo
- default_security_groups: ["ssh", "bosh"]
- default_key_name: microbosh
- private_key: $HOME/microbosh.cer
- apply_spec:
- properties:
- director:
- max_threads: 3
- hm:
- resurrector_enabled: true
- ntp: # This example uses the North American NTP servers. Edit for your region.
- - <ntp server ip>
下面简单介绍一下此部署文件的含义
* network 描述了Openstack中network的属性
在笔者的Openstack环境中,网络为openstack neutron network,所以在内网使用dhcp获取ip, 因此type为dynamic。cloud_properties中的net_id是可以使用dhcp获得ip的内网地址,此id可以使用neutron net-list得到
[python] view plaincopy
- # neutron net-list
- +--------------------------------------+---------+--------------------------------------------------+
- | id | name | subnets |
- +--------------------------------------+---------+--------------------------------------------------+
- | 0fbe7f27-e732-4954-9134-5486d7617727 | public | 110583d9-a905-428a-a494-3c95e4a6bca6 |
- | bfc9b30b-8b44-4f97-a762-c39b2f774d78 | private | 052030e6-626a-4a57-b8dc-b8ab239f419d 10.0.0.0/24 |
- +--------------------------------------+---------+--------------------------------------------------+
为了能够从外网访问microbosh,我们需要为bosh director指定一个floating ip, bosh会自动把这个ip关联到bosh director
* resource描述了为micro bosh director分配多少资源,instance_type定义了此虚拟机的openstack flavor,persistent_disk定义了为此虚拟机挂接多大的永久磁盘
* cloud描述了如何访问openstack,其中大部分内容可以从安装产生的keystonerc_demo中找到,
[python] view plaincopy
- # cat $HOME/keystonerc_demo
- export OS_USERNAME=demo
- export OS_TENANT_NAME=demo
- export OS_PASSWORD=73b3b497ca3a42d1
- export OS_AUTH_URL=http://<ip>:35357/v2.0/
- export PS1=‘[\[email protected]\h \W(keystone_demo)]\$ ‘
* apply_spec定义了Micro bosh得属性,这里面我们只需要修改一项,那就是时间服务器的地址<ntp server ip>, 例如修改为time.asia.apple.com
3.2.5 下载microbosh的虚拟机模板(stemcell)
(1) 由于GFW的缘故,把下面这句加到/etc/hosts中
54.231.244.8 s3.amazonaws.com
(2) 创建stemcell目录
[python] view plaincopy
- # mkdir -p ~/bosh-workspace/stemcells
- # cd ~/bosh-workspace/stemcells
(3) 下载micro bosh的stemcell
[python] view plaincopy
- # bosh public stemcells | grep -i openstack
- | bosh-stemcell-2427-openstack-kvm-ubuntu.tgz |
- | bosh-stemcell-2624-openstack-kvm-centos.tgz |
- | bosh-stemcell-2624-openstack-kvm-ubuntu-lucid.tgz |
- | bosh-stemcell-2749-openstack-kvm-centos-go_agent.tgz |
- | bosh-stemcell-2749-openstack-kvm-ubuntu-trusty-go_agent.tgz |
- | bosh-stemcell-2652-openstack-kvm-ubuntu-lucid-go_agent.tgz |
- | bosh-stemcell-2719.1-openstack-kvm-centos-go_agent.tgz |
- | bosh-stemcell-2719.1-openstack-kvm-ubuntu-trusty-go_agent.tgz |
- | bosh-stemcell-2719.2-openstack-kvm-centos-go_agent.tgz |
- | bosh-stemcell-2719.2-openstack-kvm-ubuntu-trusty-go_agent.tgz |
- | bosh-stemcell-2719.3-openstack-kvm-ubuntu-trusty-go_agent.tgz |
[python] view plaincopy
- # bosh download public stemcell bosh-stemcell-2652-openstack-kvm-ubuntu-lucid-go_agent.tgz
这个stemcell虽然不是最新版,但是笔者验证通过,更新版本的stemcell笔者没有尝试
(4) 部署Micro Bosh
*设置部署描述文件
[python] view plaincopy
- # cd ~/bosh-workspace/deployments
- # bosh micro deployment microbosh-openstack
* 部署Micro Bosh
[python] view plaincopy
- # bosh micro deploy ~/bosh-workspace/stemcells/bosh-stemcell-2652-openstack-kvm-ubuntu-lucid-go_agent.tgz
(5) 验证Micro Bosh
[python] view plaincopy
- # bosh target <microbosh ip address>
其中的microbosh ip address是预先申请的floating ip
(6) 使用ssh访问micro bosh
[python] view plaincopy
- # ssh -i <path to microbosh private key> [email protected]<microbosh ip>