在centos7 ubuntu15.04 上通过bosh-lite 搭建单机环境cloudfoundry
Bosh-lite简介
bosh-lite 是一个单机部署cloudfoundry的实验性工具,用于开发人员做poc 验证。Bosh-lite目前支持仅MAC OS X和Linux系统。Bosh-lite使用Vagrant管理虚拟机,所以目前只支持VirtualBox和VMWare Fusion (MAC OS X)虚拟机平台。
如下图所示,Bosh客户端CLI运行在宿主机(HOST OS)上,通过Bosh CLI,我们可以把Bosh和Cloud Foundry的各个component部署在VirtualBox的虚拟机上,Bosh和CloudFoundry的各个Component,例如UAA,Router等,都是运行在Warden容器(Warden Container)中。
2, 环境准备
笔者采用的事Cent OS 7.0 与 ubuntu 15.04 作为宿主机的操作系统,vmware 作为虚拟平台。 centos7 与 ubuntu15.04 都是装在vmware中的虚拟机。 必须将vmware 中的Inetl VT-X 打开,因为vagrant的box是64位,如果不打开VT-X 作为provide 的virtualbox 无法运行64位镜像。 设置方法vmware 选中虚拟机,然后在菜单中选中虚拟机菜单,在虚拟机设置中选择处理器设置,在右边打开VT-X选项
2.1 安装软件包
centos 准备内容
# rpm -Uvh http://mirror.pnl.gov/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
# yum install -y vim git screen kernel* libX11 qt SDL SDL-devel libxml2-devel libvpx libpng libXt libXmu libxslt libxslt-devel openssl openssl-devel libXcursor libXinerama
qt qt-devel wget gcc unzip ntpdate net-tools
ubuntu 15.04 准备内容
sudo apt-get install build-essential libxml2-dev libsqlite3-dev libxslt1-dev libpq-dev libmysqlclient-dev
2.2 安装Ruby环境
笔者使用rbenv来安装和管理ruby
- $ 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
- $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
- $ source ~/.bash_profile
- $ rbenv install 2.1.3
- $ rbenv global 2.1.3
- $ gem sources --remove https://rubygems.org/
- $ gem sources -a https://ruby.taobao.org/
- $ gem sources -l
- $ gem install bundle
- $ gem install nokogiri -- --use-system-libraries
2.3安装Vagrant
centos 安装方法
- # wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm
- # rpm -Uvh vagrant_1.7.2_x86_64.rpm
ubuntu 安装方法
sudo apt-get install vagrant -y
验证vagrant
- # vagrant --version
- Vagrant 1.6.3
2.4 安装VirtualBox
centos 安装方法
- # wget http://download.virtualbox.org/virtualbox/4.3.26/VirtualBox-4.3-4.3.26_98988_el7-1.x86_64.rpm
- # # 安装virtualbox时需要linux kernel的源代码,设置KERN_DIR环境变量指示kernel源代码路径
- # export KERN_DIR=/usr/src/kernels/3.10.0-229.4.2.el7.x86_64
- # rpm -Uvh VirtualBox-4.3-4.3.26_98988_el7-1.x86_64.rpm
sudo apt-get install virtualbox -y
验证virtualbox是否安装成功
- # VBoxManage --version
- 4.3.14r95030
3, 部署CloudFoundry
3.1 安装Bosh CLI
- # gem install bosh_cli
3.2 安装manifest merge工具
- # wget https://github.com/cloudfoundry-incubator/spiff/releases/download/v1.0.3/spiff_linux_amd64.zip
- # unzip spiff_linux_amd64.zip -d /usr/bin
3.3 Checkout bosh-lite和cf-release
bosh-lite和cf-release这两个代码库必须放在同一级目录下,这里的workspace文件夹名称必须是workspace,且路径也必须在用户的根目录。即~目录下,原因是bosh-lite 文件夹下的bin/make_manifest_spiff 中有下面这一句。为了避免路径错误,需要将文件夹明明为workspace 并且放在~目录下。
BOSH_RELEASES_DIR=${BOSH_RELEASES_DIR:-~/workspace}
- # mkdir ~/workspace
- # cd ~/workspace
- # git clone https://github.com/cloudfoundry/bosh-lite
- # git clone https://github.com/cloudfoundry/cf-release
3.4 启动VirtualBox虚拟机
- # cd ~/workspace/bosh-lite
- # vagrant up --provider=virtualbox
![](https://images0.cnblogs.com/blog2015/493330/201507/311255303149609.png)
出现上述错误console, 在对应的GUI 界面启动virtualbox错误如下图
![](https://images0.cnblogs.com/blog2015/493330/201507/311259335793458.png)
遇到上述错误之后,需要删除以前的vagrant的虚拟机,重新启动。
vagrant halt
vagrant destroy
vagrant up
启动成功后可以运行下面的命令去查看虚拟机的状态
- # vagrant global-status
启动后的vagrant box 虚拟机配置了两块网卡,一块用来连接CloudFoundry网络,使用10.244.0.0/19;一块用来和宿主机通信,使用IP 192.168.50.4
因此在宿主机centos7 或者ubuntu150.4 需要添加访问CloudFoundry网络的路由。这两个ip的配置一个在 bosh-lite/template/vagrant-local.tpl中。bosh-lite 本人也有addrout.sh addroute.bat 这个命令。
- # route add -net 10.244.0.0/19 gw 192.168.50.4
3.5部署CloudFoundry
如果配置了HTTP或者HTTPS的代理,请先运行下面这条命令
- export no_proxy=192.168.50.4,xip.io
3.5.1把bosh指向当前的bosh-lite的Director
- # bosh target 192.168.50.4 lite
这里login的用户名密码为
用户名:admin
密码: admin
查看bosh的状态
- # bosh status
- Config
- /root/.bosh_config
- Director
- Name Bosh Lite Director
- URL https://192.168.50.4:25555
- Version 1.2811.0 (00000000)
- User admin
- UUID c6f166bd-ddac-4f7d-9c57-d11c6ad5133b
- CPI vsphere
- dns disabled
- compiled_package_cache enabled (provider: local)
- snapshots enabled
- Deployment
- not set
Bosh-lite提供了一个脚本,可以一键式部署CloudFoundry
- # cd ~/workspace/bosh-lite
- # bin/provision_cf
![](https://images0.cnblogs.com/blog2015/493330/201507/311512070013343.png)
检验CloudFoundry是否部署成功
- # bosh vms
- Deployment `cf-warden'
- Director task 9
- Task 9 done
- +------------------------------------+---------+---------------+--------------+
- | Job/index | State | Resource Pool | IPs |
- +------------------------------------+---------+---------------+--------------+
- | api_z1/0 | running | large_z1 | 10.244.0.134 |
- | etcd_z1/0 | running | medium_z1 | 10.244.0.42 |
- | ha_proxy_z1/0 | running | router_z1 | 10.244.0.34 |
- | hm9000_z1/0 | running | medium_z1 | 10.244.0.138 |
- | loggregator_trafficcontroller_z1/0 | running | small_z1 | 10.244.0.146 |
- | loggregator_z1/0 | running | medium_z1 | 10.244.0.142 |
- | nats_z1/0 | running | medium_z1 | 10.244.0.6 |
- | postgres_z1/0 | running | medium_z1 | 10.244.0.30 |
- | router_z1/0 | running | router_z1 | 10.244.0.22 |
- | runner_z1/0 | running | runner_z1 | 10.244.0.26 |
- | uaa_z1/0 | running | medium_z1 | 10.244.0.130 |
- +------------------------------------+---------+---------------+--------------+
- VMs total: 11
虚拟机重启之后,有可能导致很多服务无法使用。此时需要使用bosh cck 即 bosh cloudcheck 命令来进行检查,然后选择2 重用上次的信息。
![](https://images0.cnblogs.com/blog2015/493330/201508/031746494395609.jpg)
![](https://images0.cnblogs.com/blog2015/493330/201508/031747174706545.jpg)
参考文献 http://blog.csdn.net/maingalaxy/article/details/46013393