標籤:
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 部署MicroBosh3.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>
開源的PaaS方案:在OpenStack上部署CloudFoundry (三)部署BOSH