目的
DevStack 環境を Vagrant 経由で VirtualBox 上の Ubuntu 12.04(Precise) に、vagrant up
コマンドでインストールする。
おことわり
OpenStack 自体の使用方法については記載しません。
必要なもの
- VirtualBox で 4GB 程度の 64bit 仮想マシンが起動できる環境。Linux でも Mac でも OK。
- Vagrant
-
VirtualBox で起動した仮想マシンが、直接外部のインターネットと接続できるLAN環境。例えば仮想マシンがUbuntuなら、
sudo apt-get update
の実行が普通にできること。http接続にプロキシが必要な環境は、今回考慮していません。
準備
仮想マシンの登録
Vagrantbox.es から base box を取得して登録しておきます。
$ vagrant box add precise64 http://files.vagrantup.com/precise64.box
Downloading or copying the box...
Extracting box...te: 5406k/s, Estimated time remaining: 0:00:01)
Successfully added box 'precise64' with provider 'virtualbox'!
$ vagrant box list
precise64 (virtualbox)
$
Vagrantfile の編集
適当なディレクトリで vagrant init precise64
を実行する。
$ mkdir devstack
$ cd devstack/
$ vagrant init precise64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
$
Vagrantfile を以下のように編集します。
# -*- coding: utf-8 -*-
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "precise64" # 使用する box 名
config.vm.define :vm00 do |conf|
conf.vm.hostname = "vm00" # 仮想マシンホスト名
conf.vm.network :public_network, # 仮想マシンのIPアドレス
ip: "192.168.1.220" # 使用しているLAN環境に合わせる
conf.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id,
"--memory", "3072", # 2048(MB)は必須。4096(MB)以上を推奨
"--nicpromisc2", "allow-all"] # promiscuous モード有効
# v.gui = true # VirtualBox の GUI が必要なら true に
end
conf.vm.provision :chef_solo do |c|
c.add_recipe "devstack" # 使用するレシピ名
end
end
end
cookbooks の作成
Vagrantfile のあるディレクトリに、以下のように cookbooks ディレクトリを作成する。
$ ls
Vagrantfile
$ mkdir -p cookbooks/devstack/recipes
$ mkdir -p cookbooks/devstack/files/default
$ find Vagrantfile cookbooks
Vagrantfile
cookbooks
cookbooks/devstack
cookbooks/devstack/recipes
cookbooks/devstack/files
cookbooks/devstack/files/default
レシピと必要なファイルを用意する。
※注意: vagrant
と ALL=(ALL:ALL)
の間はタブにしておいて下さい。
#
# Cookbook Name:: devstack
# Recipe:: default
#
# Copyright 2013, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
bash "change_sudoer" do
code <<-EOH
if ! fgrep -q vagrant /etc/sudoers; then
sed -e '/^root/a vagrant ALL=(ALL:ALL) NOPASSWD:ALL' /etc/sudoers > /tmp/sudoers
chmod 0660 /etc/sudoers
mv /tmp/sudoers /etc/sudoers
chmod 0440 /etc/sudoers
fi
EOH
end
package "git" do
end
directory "/home/vagrant/bootlog" do
owner "vagrant"
group "vagrant"
mode 0755
end
directory "/home/vagrant/servicelog" do
owner "vagrant"
group "vagrant"
mode 0755
end
git "/home/vagrant/devstack" do
repository "git://github.com/openstack-dev/devstack.git"
end
cookbook_file "/home/vagrant/devstack/localrc" do
source "localrc.sh"
owner "vagrant"
group "vagrant"
mode 0644
end
bash "change_file_user" do
cwd "/home/vagrant"
code <<-EOH
chown -R vagrant:vagrant devstack
EOH
end
bash "kick_devstack" do
environment 'USER' => "vagrant"
user "vagrant"
group "vagrant"
cwd "/home/vagrant/devstack"
code <<-EOH
./stack.sh
EOH
end
HOST_IP=`ip addr show dev eth1 | \
sed -n '/inet /s/^ *inet \([0-9\.]*\)\/.*$/\1/p'`
#USE_SCREEN=False
API_RATE_LIMIT=False
LOGFILE=/home/vagrant/bootlog/stack.sh.log
SCREEN_LOGDIR=/home/vagrant/servicelog
MYPASS=openstack
DATABASE_PASSWORD=$MYPASS
RABBIT_PASSWORD=$MYPASS
SERVICE_PASSWORD=$MYPASS
ADMIN_PASSWORD=$MYPASS
SERVICE_TOKEN=servcetoken66a3d6b56c1f479c8b4e70ab5c2000f5
# Nova network
disable_service n-net
# Neutron
enable_service q-svc q-agt q-dhcp q-l3 q-meta
#enable_service q-vpn
#enable_service q-lbaas
#enable_service q-fwaas
#disable_service tempest
# Swift
enable_service s-proxy s-object s-container s-account
SWIFT_HASH=servicehash66a3d6b56c1f479c8b4e70ab5c2000f5
MY_BRANCH=stable/havana
CEILOMETER_BRANCH=$MY_BRANCH
CINDER_BRANCH=$MY_BRANCH
GLANCE_BRANCH=$MY_BRANCH
HEAT_BRANCH=$MY_BRANCH
HORIZON_BRANCH=$MY_BRANCH
KEYSTONE_BRANCH=$MY_BRANCH
NOVA_BRANCH=$MY_BRANCH
NEUTRON_BRANCH=$MY_BRANCH
SWIFT_BRANCH=$MY_BRANCH
TEMPEST_BRANCH=$MY_BRANCH
TROVE_BRANCH=$MY_BRANCH
用意した各種設定ファイルの確認
$ ls -F
Vagrantfile cookbooks/
$ find Vagrantfile cookbooks
Vagrantfile
cookbooks
cookbooks/devstack
cookbooks/devstack/recipes
cookbooks/devstack/recipes/default.rb
cookbooks/devstack/files
cookbooks/devstack/files/default
cookbooks/devstack/files/default/localrc.sh
実行
Vagrantfile のあるディレクトリで vagrant up
を実行
$ vagrant up
Bringing machine 'vm00' up with 'virtualbox' provider...
[vm00] Importing base box 'precise64'...
[vm00] Matching MAC address for NAT networking...
[vm00] Setting the name of the VM...
[vm00] Clearing any previously set forwarded ports...
[vm00] Creating shared folders metadata...
[vm00] Clearing any previously set network interfaces...
[vm00] Preparing network interfaces based on configuration...
[vm00] Forwarding ports...
[vm00] -- 22 => 2222 (adapter 1)
[vm00] Running 'pre-boot' VM customizations...
[vm00] Booting VM...
[vm00] Waiting for machine to boot. This may take a few minutes...
[vm00] Machine booted and ready!
[vm00] Setting hostname...
[vm00] Configuring and enabling network interfaces...
[vm00] Mounting shared folders...
[vm00] -- /vagrant
[vm00] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks
[vm00] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
stdin: is not a tty
[2013-10-26T06:21:21+00:00] INFO: *** Chef 10.14.2 ***
[2013-10-26T06:21:21+00:00] INFO: Setting the run_list to ["recipe[devstack]"] from JSON
[2013-10-26T06:21:21+00:00] INFO: Run List is [recipe[devstack]]
[2013-10-26T06:21:21+00:00] INFO: Run List expands to [devstack]
[2013-10-26T06:21:21+00:00] INFO: Starting Chef Run for vm00
[2013-10-26T06:21:21+00:00] INFO: Running start handlers
[2013-10-26T06:21:21+00:00] INFO: Start handlers complete.
[2013-10-26T06:21:21+00:00] INFO: bash[change_sudoer] ran successfully
[2013-10-26T06:21:33+00:00] INFO: directory[/home/vagrant/bootlog] created directory /home/vagrant/bootlog
[2013-10-26T06:21:33+00:00] INFO: directory[/home/vagrant/bootlog] owner changed to 1000
[2013-10-26T06:21:33+00:00] INFO: directory[/home/vagrant/bootlog] group changed to 1000
[2013-10-26T06:21:33+00:00] INFO: directory[/home/vagrant/bootlog] mode changed to 755
[2013-10-26T06:21:33+00:00] INFO: directory[/home/vagrant/servicelog] created directory /home/vagrant/servicelog
[2013-10-26T06:21:33+00:00] INFO: directory[/home/vagrant/servicelog] owner changed to 1000
[2013-10-26T06:21:33+00:00] INFO: directory[/home/vagrant/servicelog] group changed to 1000
[2013-10-26T06:21:33+00:00] INFO: directory[/home/vagrant/servicelog] mode changed to 755
[2013-10-26T06:21:34+00:00] INFO: git[/home/vagrant/devstack] cloning repo git://github.com/openstack-dev/devstack.git to /home/vagrant/devstack
[2013-10-26T06:21:39+00:00] INFO: git[/home/vagrant/devstack] checked out branch: HEAD reference: f7cfa0c6e7a965949441ded6a789e12e5bc58039
[2013-10-26T06:21:39+00:00] INFO: cookbook_file[/home/vagrant/devstack/localrc] owner changed to 1000
[2013-10-26T06:21:39+00:00] INFO: cookbook_file[/home/vagrant/devstack/localrc] group changed to 1000
[2013-10-26T06:21:39+00:00] INFO: cookbook_file[/home/vagrant/devstack/localrc] mode changed to 644
[2013-10-26T06:21:39+00:00] INFO: cookbook_file[/home/vagrant/devstack/localrc] created file /home/vagrant/devstack/localrc
[2013-10-26T06:21:39+00:00] INFO: bash[change_file_user] ran successfully
[2013-10-26T06:33:01+00:00] INFO: bash[kick_devstack] ran successfully
[2013-10-26T06:33:01+00:00] INFO: Chef Run complete in 699.85697 seconds
[2013-10-26T06:33:01+00:00] INFO: Running report handlers
[2013-10-26T06:33:01+00:00] INFO: Report handlers complete
$
上記の以下の部分を見ればわかるように、それなりに時間がかかります。
[2013-10-26T06:21:39+00:00] INFO: bash[change_file_user] ran successfully
[2013-10-26T06:33:01+00:00] INFO: bash[kick_devstack] ran successfully
[2013-10-26T06:33:01+00:00] INFO: Chef Run complete in 699.85697 seconds
DevStack の stack.sh の実行状況をリアルタイムで知りたい場合は、 vagrant ssh
で
作成した仮想マシンにログインして、tail -f ~/bootlog/stack.sh.log
を実行してみてください。
エラーが発生しなければ、以下のようなログが最後に現れます。
Horizon is now available at http://192.168.1.220/
Keystone is serving at http://192.168.1.220:5000/v2.0/
Examples on using novaclient command line is in exercise.sh
The default users are: admin and demo
The password: openstack
This is your host ip: 192.168.1.220
※stack.sh 内の処理によっては、異なるメッセージで終了する場合もありえます。
2013-10-26 07:13:50 stack.sh completed in 164 seconds.
エラーでなければ気にしないでください。
注意点
- DevStack や OpenStack は日々更新されるので、もしかしたらこの環境が動作しない日もあるかもしれません。
- 使用している仮想マシンの box の環境自体が更新されていないと、期待した動作が得られない場合があります。DevStack を
~/devstack/unstack.sh
で一度停止させたあと、sudo apt-get update && sudo apt-get -y dist-upgrade
で環境を更新し、改めて~/devstack/stack.sh
を実行してみて下さい。 - VirtualBox が動作するホストで、アンチウィルスソフトの Web アクセス保護機能のようなものが動作していると、DevStack が途中で失敗する場合があります。