簡介:mysql
BOSH是一個分佈式雲軟件的工程發佈、部署和生命週期管理的項目。BOSH能夠在數百個虛擬機上配置和部署軟件。它也能夠從零到最小的宕機時間內執行監控、故障恢復和軟件更新。linux
雖然BOSH是爲部署Cloud Foundry PaaS而開發的,但它也可用於部署幾乎任何其餘軟件(例如Hadoop)。BOSH特別適用於大型分佈式系統。此外,BOSH支持多種基礎架構即服務(IaaS)提供商,如VMware vSphere,Google Cloud Platform,Amazon Web Services EC2,Microsoft Azure和OpenStack。雲提供商接口(CPI)使用戶可以擴展BOSH以支持其餘IaaS提供商,如Apache CloudStack和VirtualBox。c++
組件:git
CLI:bosh命令行管理工具,用於和director互動github
Director:bosh的核心組件,負責VM的建立、部署和其餘軟件、服務的生命週期管理sql
NATS:輕量級消息處理系統,包括兩類消息:vm的配置和進程健康情況的監控信息json
Agent:運行在每一個已建立的VM上,和director通訊獲取配置信息並執行tasksubuntu
health monitor:從agent接收狀態和生命週期信息,併發送警告消息centos
registry:director建立或更新vms時,將vms的配置信息存儲於registry,以便於vms啓動時調用api
blobstore:用來存儲用戶上傳的release,stemcells,logs及部署結果等
Database:存儲director關於stemcells、releases和deployments的需求狀態信息,默認是postgresql
CPI:cloud provider interface,封裝了IaaS的api,用於在iaas上建立和管理stemcells、vms和disks,因此會因運營商不一樣而不一樣。
經過BOSH CLI(指令界面,用ruby編寫)能夠與BOSH Director交互。BOSH開始部署系統以前,須要準備好三項內容:stemcell,release(要安裝的軟件),和一個部署清單(manifest)。
bosh部署過程以下:
1,更新cloud config這個yaml文件
2,構建deployment manifest文件
3,上傳deployment manifest涉及的stemcell到Director
4,上傳release到Director,若未上傳,則會自動按release的url下載並上傳
5,開始bosh deploy
基本元素
cloud file:是一個yaml文件,定義了IaaS的特殊配置參數,例如vm類型、磁盤、網絡等參數,會被director和全部的deployments使用。每一個IaaS提供商都有各自的標準
stemcell:一個集成了OS image和bosh agent的VM版本化鏡像,由bosh cli上傳,經bosh director經過CPI建立虛擬機時使用。stemcell有bosh官方維護,可在不一樣IaaS間通用
deployment:即包含特定release、disks的vms的集合
release:即job包含的源碼、二進制文件、配置模板和啓動腳本等一塊的package打包,是stemcell之上包含應用的一層
manifest:stemcell和release都靜態組件,deployment manifest將它們捆綁到一塊部署,可涉及多個stemcell和release。manifest定義了部署時資源的參數值,包括虛擬機池及其網絡,須要激活release中的job,job的生命週期、實例數、網絡及存儲要求等
快速上手
centos上依賴包
yum install gcc gcc-c++ ruby ruby-devel mysql-devel postgresql-devel postgresql-libs sqlite-devel libxslt-devel libxml2-devel patch openssl
gem install yajl-ruby
Ubuntu上依賴包
apt-get install -y build-essential zlibc zlib1g-dev ruby ruby-dev openssl libxslt-dev libxml2-dev libssl-dev libreadline6 libreadline6-dev libyaml-dev libsqlite3-dev sqlite3
linux上安裝bosh cli(推薦ubuntu16.04)
wget https://github.com/cloudfoundry/bosh-cli/releases/download/v5.4.0/bosh-cli-5.4.0-linux-amd64
mv bosh-cli-5.4.0-linux-amd64 bosh
mv bosh /usr/local/bin
chmod 0755 /usr/local/bin/bosh
bosh -v 出現如下信息,CLI即安裝成功
version 5.4.0-891ff634-2018-11-14T00:22:02Z
Succeeded
Director本地安裝
bosh lite是一個可運行在virtualbox上的Director VM(本地系統Ubuntu16.04,其上安裝virtualbox、vagrant(可選))
1,安裝CLI,同上
2,安裝virtualbox,5.1版本以上
3,安裝director VM
mkdir -p ~/workspace
git clone https://github.com/cloudfoundry/bosh-deployment ~/workspace/bosh-deployment
安裝
bosh create-env ~/workspace/bosh-deployment/bosh.yml \
--state ./state.json \
-o ~/workspace/bosh-deployment/virtualbox/cpi.yml \
-o ~/workspace/bosh-deployment/virtualbox/outbound-network.yml \
-o ~/workspace/bosh-deployment/bosh-lite.yml \
-o ~/workspace/bosh-deployment/bosh-lite-runc.yml \
-o ~/workspace/bosh-deployment/uaa.yml \
-o ~/workspace/bosh-deployment/credhub.yml \
-o ~/workspace/bosh-deployment/jumpbox-user.yml \
--vars-store ./creds.yml \
-v director_name=bosh-lite \
-v internal_ip=192.168.50.6 \
-v internal_gw=192.168.50.1 \
-v internal_cidr=192.168.50.0/24 \
-v outbound_network_name=NatNetwork
安裝時間按網速來定,大約20分鐘安裝好
4,設bosh環境變量便於登陸director
export BOSH_ENVIRONMENT=192.168.50.6
export BOSH_CA_CERT="$(bosh int creds.yml --path /director_ssl/ca)"
export BOSH_CLIENT=admin
export BOSH_CLIENT_SECRET="$(bosh int creds.yml --path /admin_password)"
export BOSH_GW_HOST=$BOSH_ENVIRONMENT
$ bosh env 安裝成功顯示如下信息
Using environment '192.168.50.6' as client 'admin'
Name bosh-e
UUID 7a4c28c1-5c96-4576-ab64-e5e3334ba33c
Version 268.7.0 (00000000)
Director Stemcell ubuntu-xenial/250.29
CPI warden_cpi
Features compiled_package_cache: disabled
config_server: disabled
local_dns: enabled
power_dns: disabled
snapshots: disabled
User admin
Succeeded
詳細信息可參考官網
https://bosh.io/docs/bosh-lite/
經常使用bosh命令:
bosh stemcells 查看stemcell列表
bosh vms 查看vm運行狀態
bosh releases 查看releases列表
bosh delete releasename 刪除release
bosh upload release ~/xx.tgz 上傳release
bosh deployments 查看應用
bosh tasks 顯示運行的任務
bosh logs deploymentname 查看代理日誌
bosh官方文檔
https://bosh.io/docs/update-cloud-config/
利用嶄新的director部署一個簡單的http server應用:
1,獲取release並上傳
cd ~/workspaces
git clone https://github.com/mariash/learn-bosh-release
cd learn-bosh-release
bosh create-release 建立release,至關於打包
bosh upload-release 上牀release到director
bosh releases 查看上傳成功的release
2,上傳stemcell
bosh upload-stemcell https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-trusty-go_agent
bosh stemcells 查看上傳成功的stemcell
3,由於manifest文件已作好,可直接按照其部署
bosh -d learn-bosh deploy manifest.yml
bosh vms 可看到運行vm IP爲10.244.0.2
bosh instances --ps 查看運行的實例
4,驗證效果
當前咱們在director上,director的IP是192.168.50.6,vm的網段查看manifest可知是10.244.0.2
本地添加一條訪問路由
route add -net 10.244.0.0/16 gw 192.168.50.6
curl 10.244.0.2:8080 顯示信息
Hello, Maria form 。。。
curl 10.244.0.2:8080/kill
bosh logs 查看
bosh instances 可看到實例自動重啓了,這個是Health Monitor自動修復,可用bosh update-resurrection off關掉
bosh -d learn-bosh cloud-check手動修復,bosh cck
5,刪除應用
bosh delete-deployment -d learn-bosh --force -n
6,修改應用
vi src/simple_server/app.rb
name = 「you」
properties: {port: 8090}
bosh create-release --force 從新建立release
bosh upload-release 上傳
bosh -d learn-bosh deploy mainifest.yml 從新部署
curl 10.244.0.2:8090 測試
Hello, you form 。。。
7,擴展部署
vi manifest.yml
將instances數量1改成2,添加靜態IP 10.244.0.6
部署
bosh -d learn-bosh deploy manifest.yml
bosh instances 查看實例狀態
驗證
curl 10.244.0.2:8090
hello, you from ...
curl 10.244.0.6:8090
hello, you from ...