LoginSignup
14
14

More than 5 years have passed since last update.

VagrantでさくらのクラウドにCoreOSを立ち上げる

Last updated at Posted at 2014-11-20

さくらのクラウドを Vagrant up した

この記事を参考に、Vagrant経由でさくらのクラウドにCoreOSを立ててみた。
記事が書かれてから結構期間が経っているからか、そのまま真似しても動かなかったのでそのあたりをメモ。

準備

Vagrantのプラグインを入れる

Vagrant Sakura Provider」を入れる。
Vagrantは通常VirtualBox上に仮想マシンを作るけど、代わりにさくらのクラウドに立ててくれる。

$ vagrant plugin install vagrant-sakura
Installing the 'vagrant-sakura' plugin. This can take a few minutes...
Installed the plugin 'vagrant-sakura (0.0.6)'!

ダミーのboxを落とす

Vagrantの仕様上、boxの指定が必要なので、さくらのクラウド用にダミーのboxをダウンロードしておく。小さいのですぐ。

$ vagrant box add dummy https://github.com/tsahara/vagrant-sakura/raw/master/dummy.box
==> box: Adding box 'dummy' (v0) for provider: 
    box: Downloading: https://github.com/tsahara/vagrant-sakura/raw/master/dummy.box
==> box: Successfully added box 'dummy' (v0) for 'sakura'!

さくらのクラウドにSSH公開鍵を登録

さくらのクラウドのコンソールから設定画面に行き、SSH公開鍵を登録しておく。その際に公開鍵のリソースIDが作られる。これはあとで使う。
vagrant sshしたときに、この公開鍵と対応した秘密鍵がないと繋がらない。たぶん。

APIキーを登録

同じく設定画面から、APIキーを登録する。
「ACCESS TOKEN」と「ACCESS TOKEN SECRET」の両方ともあとで必要になる。

Vagrantfileを書く

今回できたのはこんな感じ。

Vagrant.configure("2") do |config|
  config.vm.box = "dummy"
  config.ssh.username = "core" # CoreOSのユーザー名はcore
  config.ssh.private_key_path = File.expand_path "~/.ssh/id_rsa" # SSH秘密鍵のパス

  config.vm.provider :sakura do |sakura|
    sakura.server_name = 'honeniq_coreos' # なんかこのオプション効いてない気がする
    sakura.server_plan = '' # サーバーのプランID
    sakura.disk_source_archive = '' # ディスクアーカイブのID
    sakura.access_token = '' # ACCESS TOKEN
    sakura.access_token_secret = '' # ACCESS TOKEN SECRET
    sakura.sshkey_id = '' # 登録したSSH公開鍵のリソースID
    sakura.zone_id = 'is1b' # ゾーンID これは石狩第2
  end
end

プランIDとアーカイブIDの調べ方

プラグインについてくるvagrant sakura-list-idというコマンドを使う。

$ vagrant sakura-list-id
Zone: is1b

---- Archives ----
ID              Size  Name
112600899098    20GB  CentOS 5.11 64bit (基本セット)
112600898803    20GB  CentOS 6.6 64bit (基本セット)
112600140323    20GB  Scientific Linux 6.5 64bit (基本セット)
112500556903    20GB  FreeBSD 8.3 64bit (基本セット)
112600079735    20GB  FreeBSD 9.2 64bit (基本セット)
112600085506    20GB  FreeBSD 10.0 64bit (基本セット)
(略)

こんな感じで、有効なプランとアーカイブを一覧にしてくれる。

プラグインのインストール直後はエラーで使えなかったのに、ある程度Vagrantfileを書いたら使えるようになった。たぶん、Vagrantfileの中のアクセストークンを使ってるからなんじゃないかな?

立ち上げる

vagrant up --provider=sakuraする。
オプションでプロバイダを指定する必要があるので注意。providerとprovisionerがいつもごっちゃになります。

$ vagrant up --provider=sakura
Bringing machine 'default' up with 'sakura' provider...
==> default: Creating a server with the following settings...
==> default:  -- Server Name: default
==> default:  -- Server Plan: 1001
==> default:  -- Disk Plan: 4
==> default:  -- Disk Source Archive: 112600559854
==> default: Disk 112600909008 is migrating (0/20480)
==> default: Disk 112600909008 is migrating (0/20480)
(中略)
==> default: Disk 112600909008 is migrating (17408/20480)
==> default: Disk 112600909008 is migrating (17408/20480)
==> default: Waiting for SSH to become available...
==> default: Server is booted and ready for use!
==> default: Rsyncing folder: /Users/honeniq/sacloud/ => /vagrant

立ち上がった!
公開鍵をちゃんと設定しておけばvagrant sshでそのまま繋がります。

$ vagrant ssh
CoreOS (stable)
core@localhost ~ $ 

放っておくとお金もかかるので、ちゃんとvagrant destroyで殺しましょう。
vagrant haltだとシャットダウンしてるだけでVM自体は残ってしまいます。

$ vagrant destroy
    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Terminating the server...

以上!

14
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
14