Revo.io – Quick Customize Your Vagrantfile

螢幕快照 2014-10-30 上午5.10.39.png


Rove.io 這個網站可以讓你客製化你要的環境,然後幫你產生 Vagrantfile 和 Cheffile (需要另外預先安裝好 library-chef:gem install library-chef),下載後解壓縮進入資料夾,輸入 curl -L http://rove.io/ | bash,就會自動下載 box 並安裝好你客製化的軟體 (應該跟 Docker 一樣是堆疊方式),vagrant ssh 就可以連入測試了

1.jpg
2.jpg

After Generate:

3.jpg
螢幕快照 2014-10-30 上午5.21.12.png
螢幕快照 2014-10-30 上午5.21.55.png

After curl -L install http://revo.io | bash finished:
NOTE:基本上過程沒有錯誤的話,curl 結束後就會完成安裝,就可以直接 vagrant ssh 進去了

5.jpg

但是如果中途有斷掉過,你可能需要手動執行套件下載和安裝
librarian-chef install

NOTE: 此時,因為 curl 已經(或可能)讓 vm 已經 run 起來,因此需要先 vagrant halt 才能安裝客製化的應用程式

6.jpg

接著要 vagrant provision
這個動作才會真的 Setting the run_list to ["recipe[apt]", "recipe[vim]", "recipe[git]", "recipe[apache2]", "recipe[mysql::server]"] from JSON,將 chef cookbook 設定且下載的應用程式裝載 vm 中

7.jpg

最後 vagrant up,然後 vagrant ssh 後:

  • curl 時遇到問題:
/usr/local/Cellar/ruby/2.1.4/lib/ruby/2.1.0/net/http.rb:920:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

花了很久時間嘗試,終於解決了!!!!!!!!
因為我是在 Mac 上安裝 Vagrant
原來在 Mac 上要這樣指定 SSL_CERT_FILE:export SSL_CERT_FILE='/usr/local/etc/openssl/osx_cert.pem'
不是指定到 /usr/local/etc/certs/cacert.pem
(osx_cert.pem 是另外下載安裝的)

  • vagrant up 遇到的問題:
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 3000 is already in use
on the host machine.

To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 3000, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.

這表示你有沒關掉的 vargant instance,導致預設要綁定的 port 已經被某個 process 佔用了,因此請先用 ps aux | grep vm 來看:

veck            78729   1.1  5.6  3000248 471340   ??  U     4:45AM   2:08.39 /Applications/VirtualBox.app/Contents/MacOS/VBoxHeadless --comment rove-27c8af801d4c671e25f2791b7311bbe0_default_1414614223406_26774 --startvm 541cafa7-5bb3-45d7-bd27-899a824a3e74 --vrde config

再用 kill -9 [PID] 砍掉 Process,然後重新 vagrant up 就可以了

Docker – Linux Container Management Tool

Docker 是一個 Linux Container 的管理工具

docker pull ubuntu // get images, first time to create an image use

>sudo docker pull ubuntu
Pulling repository ubuntu
58faa899733f: Download complete 
ea7d6801c538: Download complete 
3db9c44f4520: Download complete 
463ff6be4238: Download complete 
195eb90b5349: Download complete 
c5881f11ded9: Download complete 
e54ca5efa2e9: Download complete 
511136ea3c5a: Download complete 
e7d62a8128cf: Download complete 
2c2b6e9ee5ba: Download complete 
6c3df001ea12: Download complete 
3af9d794ad07: Download complete 
d7ac5e4f1812: Download complete 
65b7e9ccb809: Download complete 
f127542f0b61: Download complete 
bac448df371d: Download complete 
6cfa4d1f33fb: Download complete 
fae16849ebe2: Download complete 
f8dd6bd14f58: Download complete 
a343823119db: Download complete 
0f4aac48388f: Download complete 
209ea56fda6d: Download complete 
dfaad36d8984: Download complete 
5796a7edb16b: Download complete 
b7c6da90134e: Download complete 
47dd6d11a49f: Download complete 
2f4b4d6a4a06: Download complete 
83ff768040a0: Download complete 
6c37f792ddac: Download complete 

docker images // list all images

>sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              14.10               58faa899733f        2 weeks ago         196 MB
ubuntu              utopic              58faa899733f        2 weeks ago         196 MB
ubuntu              12.04               ea7d6801c538        3 weeks ago         127.5 MB
ubuntu              precise             ea7d6801c538        3 weeks ago         127.5 MB
ubuntu              12.10               c5881f11ded9        3 weeks ago         172.2 MB
ubuntu              quantal             c5881f11ded9        3 weeks ago         172.2 MB
ubuntu              13.04               463ff6be4238        3 weeks ago         169.4 MB
ubuntu              raring              463ff6be4238        3 weeks ago         169.4 MB
ubuntu              13.10               195eb90b5349        3 weeks ago         184.7 MB
ubuntu              saucy               195eb90b5349        3 weeks ago         184.7 MB
ubuntu              trusty              e54ca5efa2e9        3 weeks ago         276.5 MB
ubuntu              14.04               e54ca5efa2e9        3 weeks ago         276.5 MB
ubuntu              latest              e54ca5efa2e9        3 weeks ago         276.5 MB
<none>              <none>              a7cf8ae4e998        11 weeks ago        171.3 MB
busybox             latest              2d8e5b282c81        11 weeks ago        2.489 MB
ubuntu              10.04               3db9c44f4520        12 weeks ago        183 MB
ubuntu              lucid               3db9c44f4520        12 weeks ago        183 MB

docker run [image] -i -t ubuntu // run a command in a new container

>sudo docker run -t -i ubuntu:12.04 bash
root@96c5f0b2c4ef:/# 

Other Commands

    attach    Attach to a running container
    build     Build a container from a Dockerfile
    commit    Create a new image from a container's changes
    cp        Copy files/folders from the containers filesystem to the host path
    diff      Inspect changes on a container's filesystem
    events    Get real time events from the server
    export    Stream the contents of a container as a tar archive
    history   Show the history of an image
    images    List images
    import    Create a new filesystem image from the contents of a tarball
    info      Display system-wide information
    inspect   Return low-level information on a container
    kill      Kill a running container
    load      Load an image from a tar archive
    login     Register or Login to the docker registry server
    logs      Fetch the logs of a container
    port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
    ps        List containers
    pull      Pull an image or a repository from the docker registry server
    push      Push an image or a repository to the docker registry server
    restart   Restart a running container
    rm        Remove one or more containers
    rmi       Remove one or more images
    run       Run a command in a new container
    save      Save an image to a tar archive
    search    Search for an image in the docker index
    start     Start a stopped container
    stop      Stop a running container
    tag       Tag an image into a repository
    top       Lookup the running processes of a container
    version   Show the docker version information
    wait      Block until a container stops, then print its exit code

Docker 可以讓你用類似 Git 的方式 commit 目前 container 的狀態
並且可以 push 到 Docker Hub

Reference:

  1. Docker:http://www.docker.com
  2. Vagrant:http://www.vagrantup.com/
  3. Docker vs Vagrant
    http://stackoverflow.com/questions/16647069/should-i-use-vagrant-or-docker-io-for-creating-an-isolated-environment
  4. http://www.codedata.com.tw/social-coding/docker-layman-abc/

LXC Start Problem and Solution on Mint

解決了在 Mint 上無法找到 Template 的問題,接著建立好一個 VM,就準備要啟動它了!

但是就在期待中輸入 lxc-start -n test-lxc -d ( -d : launch as daemon)

竟然出現了:

lxc-start: command get_init_pid failed to receive response

以為只是某個 Calling 失敗,所以還是試著用 lxc-console 連看看,果然是 test-lxc is not running

同樣是 PTT 上 soom 大大提供的資料,在 The Linux Mint Distribution 網站
有人提報了這個問題:https://bugs.launchpad.net/linuxmint/+bug/1257109

一樣是相依套件的問題,所以額外在安裝了:

sudo apt-get install bridge-utils cgroup-lite cloud-image-utils distro-info distro-info-data euca2ools libaio1 libboost-thread1.53.0 liblxc0 librados2 librbd1 libseccomp1 python-boto python-distro-info python-m2crypto python3-lxc qemu-utils sharutils

如此就成功 launch 並且可以連入 VM 了!

Terminal_001.png

相關連結:
– KVM:http://www.linux-kvm.org/page/Main_Page
– LXC:https://linuxcontainers.org/
– Docker:https://www.docker.io/
– Linux KVM 研究室:http://linuxkvm.blogspot.tw/
– Mr. Q – Linux Container (lxc) – 物美價廉的 Virtualization