CloudFoundry in 1 Box簡介:Lattice篇

Pivotal Web Service主管工程師 產品經理 吳疆


本篇是《CloudFoundry in 1 Box簡介》系列最後一篇,在前面兩篇中,我們介紹了Bosh-lite和pcf-dev的架構和部署。在本篇中,我們將詳細描述另一個CloudFoundry in 1 Box解決方案Lattice。


1. Lattice簡介


Lattice是一個很有意思的項目,設計目標是爲Cloud Foundry的開發人員提供一個最小的App運行時環境,所以它只選擇了Cloud Foundry中與App運行相關的組件,從而組成了一個最簡化的開發測試Cloud Foundry App的環境。

wKiom1ce0-OghM03AAzQuwBRpM0849.png


如上圖所示,Lattice僅包含如下組件


  • Router:負責訪問App請求的routing

  • Diego:Cloud Foundry App的運行時環境

  • Blob store: App staging的存儲空間

  • loggregator:log服務器,供app開發者查看app運行時日誌


下面我們就來一步一步搭建一個Lattice環境


2. 環境準備


筆者採用的事Cent OS 7.2作爲宿主機的操作系統,VirtualBox爲虛擬機平臺


2.1 安裝以來的軟件包


# 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


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.3.0 
# rbenv global 2.1.3
# gem install bundle
# gem install nokogiri — --use-system-libraries


2.3安裝Vagrant


# wget https://releases.hashicorp.com/vagrant/1.8.1/vagrant_1.8.1_x86_64.rpm
# rpm -Uvh vagrant_1.8.1_x86_64.rpm


驗證vagrant


# vagrant --version
Vagrant 1.8.1


2.4 安裝VirtualBox


# wget http://download.virtualbox.org/virtualbox/5.0.16/VirtualBox-5.0-5.0.16_105871_el7-1.x86_64.rpm
# #安裝virtualbox時需要linux kernel的源代碼,設置KERN_DIR環境變量指示kernel源代碼路徑
# export KERN_DIR=/usr/src/kernels/<your kernel dir>
# rpm -Uvh VirtualBox-5.0-5.0.16_105871_el7-1.x86_64.rpm


驗證virtualbox是否安裝成功


# VBoxManage --version
5.0.16r105871


3. 部署Lattice


3.1 從github上下載最新的lattice release


# wget https://github.com/cloudfoundry-incubator/lattice-release/releases/latest


3.2 解壓Lattice


#  gunzip lattice-bundle-<version>.zip


3.3 啓動Lattice


# cd <lattice>/vagrant
# vagrant up --provider=virtualbox


3.4 查看PCF-dev component


# cd <lattice>/vagrant
# vagrant ssh ##登陸pcf-dev虛擬機

# 登陸之後的pcf-dev虛擬機
$ sudo -i
# monit summary
root@agent-id-pcfdev-0:~# monit summary
The Monit daemon 5.2.4 uptime: 17m

Process 'auctioneer'                running
Process 'receptor'                  running
Process 'bbs'                       running
Process 'converger'                 running
Process 'file_server'               running
Process 'route_emitter'             running
Process 'ssh_proxy'                 running
Process 'rep'                       running
Process 'rootfses'                  running
Process 'garden'                    running
File 'haproxy_config'               accessible
Process 'haproxy'                   running
Process 'router_configurer'         running
Process 'tcp_emitter'               running
Process 'routing-api'               running
Process 'consul_agent'              running
Process 'doppler'                   running
Process 'gorouter'                  running
Process 'loggregator_trafficcontroller' running
Process 'metron_agent'              running
Process 'nats'                      running
Process 'route_registrar'           running
Process 'etcd'                      running
System 'system_lattice-colocated-0' running


啓動後的Lattice虛擬機配置了兩塊網卡,一塊用來連接CloudFoundry網絡,使用10.0.2.15/24;一塊用來和宿主機通信,使用IP 192.168.11.11. Lattice默認的域名爲local.lattice.cf

如果設有http/https proxy,需要執行如下步驟


export no_proxy=192.168.11.11,local.lattice.cf


至此,Lattice環境準備完畢。


4. 部署app到Lattice


4.1 安裝Lattice CLI


# curl -O http://receptor.local.lattice.cf/v1/sync/linux/ltc
# chmod +x ltc


4.2 Lattice target


Lattice默認的域名爲local.lattice.cf, *.local.lattice.cf會被解析到192.168.11.11


# ping xyz.local.lattice.cf
PING xyz.local.pcfdev.io (192.168.11.11) 56(84) bytes of data.
64 bytes from 192.168.11.11: icmp_seq=1 ttl=64 time=0.818 ms
64 bytes from 192.168.11.11: icmp_seq=2 ttl=64 time=1.45 ms
64 bytes from 192.168.11.11: icmp_seq=3 ttl=64 time=1.33 ms
64 bytes from 192.168.11.11: icmp_seq=4 ttl=64 time=1.69 ms
64 bytes from 192.168.11.11: icmp_seq=5 ttl=64 time=1.25 ms
^C
--- xyz.local.pcfdev.io ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 0.818/1.311/1.696/0.292 ms
# lattice target local.pcfdev.io
API location set.


4.3 部署App


因爲lattice環境僅包含運行Cloud Foundry App的最小環境,不包含任何buildpack,所以使用Lattice運行Cloud Foundry App需要兩個步驟


  1. build Cloud Foundry droplet,在這個步驟中,需要顯示指定buildpack,以ruby app爲例


# ltc build-droplet helloruby https://github.com/cloudfoundry/ruby-buildpack
Uploading application bits...
Uploaded.
Submitted build of helloruby
04/20 22:30:00.57 [BUILD|0] Successfully created container
04/20 22:30:06.20 [DROPLET|0] Deleted http://local.lattice.cf:8444/blobs/helloruby-bits.zip.
04/20 22:30:06.22 [DROPLET|0] Exit status 0
04/20 22:30:06.39 [BUILD|0] Exit status 0
04/20 22:30:27.50 [BUILD|0] -------> Buildpack version 1.6.16
04/20 22:30:27.68 [BUILD|0]        Downloaded [https://pivotal-buildpacks.s3.amazonaws.com/ruby/binaries/shared/bundler-1.11.2.tgz]
04/20 22:30:31.68 [BUILD|0] -----> Compiling Ruby/Rack
04/20 22:30:32.38 [BUILD|0]        Downloaded [https://pivotal-buildpacks.s3.amazonaws.com/concourse-binaries/ruby/ruby-2.3.0-linux-x64.tgz]
04/20 22:31:07.03 [BUILD|0] -----> Using Ruby version: ruby-2.3.0
04/20 22:31:07.48 [BUILD|0] ###### WARNING:
04/20 22:31:07.48 [BUILD|0]        remove the `.bundle/` folder from your repo and add it to your `.gitignore` file.
04/20 22:31:07.48 [BUILD|0]        You have the `.bundle/config` file checked into your repository
04/20 22:31:07.48 [BUILD|0]        https://devcenter.heroku.com/articles/bundler-configuration
04/20 22:31:07.48 [BUILD|0]        It contains local state like the location of the installed bundle
04/20 22:31:07.48 [BUILD|0]        as well as configured git local gems, and other settings that should
04/20 22:31:07.48 [BUILD|0] -----> Installing dependencies using bundler 1.11.2
04/20 22:31:07.48 [BUILD|0]        not be shared between multiple checkouts of a single repo. Please
04/20 22:31:08.27 [BUILD|0]        Downloaded [https://pivotal-buildpacks.s3.amazonaws.com/ruby/binaries/cflinuxfs2/libyaml-0.1.6.tgz]
04/20 22:31:11.03 [BUILD|0]        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
04/20 22:31:14.33 [BUILD|0]        Fetching gem metadata from https://ruby.taobao.org/....
04/20 22:31:14.63 [BUILD|0]        Fetching version metadata from https://ruby.taobao.org/..
04/20 22:31:15.49 [BUILD|0]        Installing kgio 2.9.2 with native extensions
04/20 22:31:15.63 [BUILD|0]        Installing rake 10.4.2
04/20 22:31:15.82 [BUILD|0]        Installing rack 1.6.0
04/20 22:31:17.23 [BUILD|0]        Installing raindrops 0.13.0 with native extensions
04/20 22:31:17.40 [BUILD|0]        Installing rdiscount 2.1.7.1 with native extensions
04/20 22:31:54.47 [BUILD|0]        Installing tilt 1.4.1
04/20 22:31:54.77 [BUILD|0]        Using bundler 1.11.2
04/20 22:31:55.19 [BUILD|0]        Installing rack-protection 1.5.3
04/20 22:31:56.16 [BUILD|0]        Installing sinatra 1.4.5
04/20 22:32:38.00 [BUILD|0]        Bundle complete! 7 Gemfile dependencies, 10 gems now installed.
04/20 22:32:38.00 [BUILD|0]        Gems in the groups development and test were not installed.
04/20 22:32:38.00 [BUILD|0]        Bundled gems are installed into ./vendor/bundle.
04/20 22:32:38.04 [BUILD|0]        Bundle completed (87.00s)
04/20 22:32:38.06 [BUILD|0]        Cleaning up the bundler cache.
04/20 22:32:40.00 [BUILD|0] -----> Writing config/database.yml to read from DATABASE_URL
04/20 22:32:41.31 [BUILD|0] ###### WARNING:
04/20 22:32:41.31 [BUILD|0]        You have the `.bundle/config` file checked into your repository
04/20 22:32:41.31 [BUILD|0]        It contains local state like the location of the installed bundle
04/20 22:32:41.31 [BUILD|0]        as well as configured git local gems, and other settings that should
04/20 22:32:41.31 [BUILD|0]        not be shared between multiple checkouts of a single repo. Please
04/20 22:32:41.31 [BUILD|0]        remove the `.bundle/` folder from your repo and add it to your `.gitignore` file.
04/20 22:32:41.31 [BUILD|0]        https://devcenter.heroku.com/articles/bundler-configuration
04/20 22:32:58.50 [BUILD|0] Exit status 0
04/20 22:32:59.45 [DROPLET|0] Uploaded /tmp/droplet to http://local.lattice.cf:8444/blobs/helloruby-droplet.tgz.
04/20 22:32:59.49 [DROPLET|0] Exit status 0

# tc list-droplets
Droplet        Created At        Size
helloruby    04/20 14:32:59.00    20.3M


2. 啓動droplet


# ltc launch-droplet helloruby helloruby
No port specified. Defaulting to 8080.
Creating App: helloruby
.04/20 22:37:00.15 [APP|0] Creating container
.04/20 22:37:01.77 [APP|0] Successfully created container
..............04/20 22:37:16.10 [HEALTH|0] healthcheck failed
04/20 22:37:16.14 [HEALTH|0] Exit status 1
04/20 22:37:16.56 [SSH|0] {"timestamp":"1461163036.562246799","source":"sshd","message":"sshd.started","log_level":1,"data":{}}
04/20 22:37:16.81 [HEALTH|0] healthcheck failed
04/20 22:37:16.83 [HEALTH|0] Exit status 1
.04/20 22:37:17.54 [HEALTH|0] healthcheck failed
04/20 22:37:17.57 [HEALTH|0] Exit status 1
.04/20 22:37:18.04 [APP|0] I, [2016-04-20T14:37:18.041860 #10]  INFO -- : Refreshing Gem list
04/20 22:37:18.26 [APP|0] I, [2016-04-20T14:37:18.253960 #10]  INFO -- : listening on addr=0.0.0.0:8080 fd=9
04/20 22:37:18.27 [APP|0] I, [2016-04-20T14:37:18.266758 #10]  INFO -- : master process ready
04/20 22:37:18.27 [HEALTH|0] healthcheck passed
04/20 22:37:18.31 [APP|0] I, [2016-04-20T14:37:18.280764 #43]  INFO -- : worker=0 ready
04/20 22:37:18.32 [APP|0] I, [2016-04-20T14:37:18.284959 #49]  INFO -- : worker=2 ready
04/20 22:37:18.33 [APP|0] I, [2016-04-20T14:37:18.305195 #46]  INFO -- : worker=1 ready
04/20 22:37:18.35 [HEALTH|0] Exit status 0

helloruby is now running.
App is reachable at:
http://helloruby.local.lattice.cf
http://helloruby-8080.local.lattice.cf


Ruby App啓動成功,可以通過http://helloruby.local.lattice.cf訪問應用


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章