LoginSignup
12
12

More than 5 years have passed since last update.

格安なScaleway C2サーバでmicroPCF(自分専用Cloud Foundry)を構築

Last updated at Posted at 2016-03-12

はじめに

microPCFとは

Cloud Foundryの環境をローカルでVagrantを使って構築出来るツールで、アプリ開発者がローカルで実験するのに便利です。

参考:
BLOG.IK.AM MicroPCFでローカルCloudFoundry環境を作る
microPCFを使ってみよう

ScalewayのC2サーバとは

2016年3月10日時点で知ったのですが、ARMのマシン貸しで一部で話題になったScalewayの新サービスとして
C2サーバと呼ばれるx86-64の最小プラン11.99ユーロ(1500円程?)で
4core 8GBメモリという比較的魅力的なサービスが開始されたようです。

この目標

ARMのマシンを借りられるC1のプランは以前に試したことがあったので、
今回はさくっとC2を借りてmicroPCFを使い
『格安の自分専用Cloud Foundry環境を立てられないか?』というモチベーションで試してみました。

構築

サーバ作成

c2サーバのubuntu trustyのイメージを選択します

c2-server-create.PNG

※追加情報(2016/3/27)
実際にCloud Foundryを動かしてアプリをいくつかあげて
数日様子を見ていたのですが、やはりVagrantのsnapshotや同時に立ち上げているService Broker用のdockerなどによって、ディスクサイズがデフォルトの50GBのみだとディスクが足りなくなるようです。

その為、50GBあたり⁺1ユーロとなり2ユーロ余分にかかってしまいますが、最初にマシンを作成する際に100GB以上のディスクをアタッチするのをお勧めします。

ssh接続

事前にScalewayのダッシュボードのCredentialsにSSH用の公開鍵を登録していたので、作成したマシンの情報ページにあるHOW TO CONNECT ?の情報で接続できました。

$ ssh root@YOUR_MACHINE_PUBLIC_IP_ADDRESS
               _
 ___  ___ __ _| | _____      ____ _ _   _
/ __|/ __/ _` | |/ _ \ \ /\ / / _` | | | |
\__ \ (_| (_| | |  __/\ V  V / (_| | |_| |
|___/\___\__,_|_|\___| \_/\_/ \__,_|\__, |
                                    |___/

microPCFの準備

Vagrant環境準備

まずはvirtualbox環境を準備します

# echo 'deb http://download.virtualbox.org/virtualbox/debian trusty contrib' >> /etc/apt/sources.list
# wget https://www.virtualbox.org/download/oracle_vbox.asc
# apt-key add oracle_vbox.asc
# apt-get update

そのままだとkernelが新しいものが使われている為?か
linux-headersまわりのエラーが出てVirutualBoxがすんなり入ってくれなかったので以下を実施した。

※参考: https://github.com/scaleway/kernel-tools

# apt-get install build-essential libssl-dev

以下をコピペしてたたく

# Determine versions
arch="$(uname -m)"
release="$(uname -r)"
upstream="${release%%-*}"
local="${release#*-}"

# Get kernel sources
mkdir -p /usr/src
wget -O "/usr/src/linux-${upstream}.tar.xz" "https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-${upstream}.tar.xz"
tar xf "/usr/src/linux-${upstream}.tar.xz" -C /usr/src/
ln -fns "/usr/src/linux-${upstream}" /usr/src/linux
ln -fns "/usr/src/linux-${upstream}" "/lib/modules/${release}/build"

# Prepare kernel
zcat /proc/config.gz > /usr/src/linux/.config
printf 'CONFIG_LOCALVERSION="%s"\nCONFIG_CROSS_COMPILE=""\n' "${local:+-$local}" >> /usr/src/linux/.config
wget -O /usr/src/linux/Module.symvers "http://mirror.scaleway.com/kernel/${arch}/${release}/Module.symvers"
make -C /usr/src/linux prepare modules_prepare

virtualbox-5.0を入れる

# apt-get install virtualbox-5.0

VirtualBox_Extension_Packを入れる

# wget http://download.virtualbox.org/virtualbox/5.0.16/Oracle_VM_VirtualBox_Extension_Pack-5.0.16-105871.vbox-extpack
# VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.0.16-105871.vbox-extpack

続いてvagrant環境の準備

# wget https://releases.hashicorp.com/vagrant/1.8.1/vagrant_1.8.1_x86_64.deb
# dpkg -i vagrant_1.8.1_x86_64.deb

micropcfの起動
https://github.com/pivotal-cf/micropcf

# wget https://github.com/pivotal-cf/micropcf/releases/download/v0.6.0/micropcf-v0.6.0.zip
# apt-get install zip
# unzip micropcf-v0.6.0.zip
# cd micropcf-v0.6.0/
# vagrant up --provider=virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'micropcf/micropcf' could not be found. Attempting to find and install.
..
    default: Box Provider: virtualbox
    default: Box Version: 0.14.0
==> default: Loading metadata for box 'micropcf/micropcf'
    default: URL: https://atlas.hashicorp.com/micropcf/micropcf
==> default: Adding box 'micropcf/micropcf' (v0.14.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/micropcf/boxes/micropcf/versions/0
.14.0/providers/virtualbox.box
==> default: Successfully added box 'micropcf/micropcf' (v0.14.0) for 'virtualbox'!
==> default: Importing base box 'micropcf/micropcf'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'micropcf/micropcf' is up to date...
==> default: Setting the name of the VM: micropcf-v060_default_1457781886195_16572
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: stdin: is not a tty
==> default: Waiting for services to start...

==> default: MicroPCF is now running.
==> default: To begin using MicroPCF, please run:
==> default:    cf api api.local.micropcf.io --skip-ssl-validation
==> default:    cf login
==> default: Email: admin
==> default: Password: admin
==> default: Don't have the cf command line utility? Download it from https://github.com/cloudfoundry/cli/releases

==> default: Waiting for services to start... の部分でおそらくCPUがそこまでハイスペックでない為10-20分?ほど進捗が止まっているように見えましたがそのまま待ちます。

Cloud Foundryのcliの導入

ひとまず最新版のv6.16.1を入れます
https://github.com/cloudfoundry/cli/releases

# wget -O cf-cli-installer_6.16.1_x86-64.deb "https://cli.run.pivotal.io/stable?release=debian64&version=6.16.1&source=github-rel"
# dpkg -i cf-cli-installer_6.16.1_x86-64.deb
# cf -v
cf version 6.16.1+924508c-2016-02-26

Cloud Foundryにログイン

# cf login -a api.local.micropcf.io -u admin -p admin --skip-ssl-validation

cf-login-ok.PNG

Cloud Foundryを使ってみる

アプリをpush

試しにCloud Foundryの検証でよく使われるdoraというアプリをCloud Foundry上にpushします

gitを入れる

# apt-get install git -y

ソースをcloneする

# git clone https://github.com/cloudfoundry/cf-acceptance-tests.git
# cd cf-acceptance-tests/assets/dora/

doraをpush

# cf push dora

scaleway-push-dora-ok.PNG

アプリにアクセス

# curl dora.local.micropcf.io
Hi, I'm Dora!

curl-dora-ok.PNG

成功しました!

microPCFを立てる目的は達したので、後はScaleway C2サーバがどんな感じの構成かを確認してみました。

コマンドから見えるマシン情報

uname

# uname -a
Linux scw-2ac7be 4.4.4-std-3 #1 SMP Tue Mar 8 17:31:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

cpuinfo

root@scw-2ac7be:~/micropcf-v0.6.0# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 77
model name      : Intel(R) Atom(TM) CPU  C2550  @ 2.40GHz
stepping        : 8
microcode       : 0x127
cpu MHz         : 2393.902
cache size      : 1024 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch ida arat epb dtherm tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms
bugs            :
bogomips        : 4787.80
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 77
model name      : Intel(R) Atom(TM) CPU  C2550  @ 2.40GHz
stepping        : 8
microcode       : 0x127
cpu MHz         : 2393.902
cache size      : 1024 KB
physical id     : 0
siblings        : 4
core id         : 1
cpu cores       : 4
apicid          : 2
initial apicid  : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch ida arat epb dtherm tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms
bugs            :
bogomips        : 4787.80
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 2
vendor_id       : GenuineIntel
cpu family      : 6
model           : 77
model name      : Intel(R) Atom(TM) CPU  C2550  @ 2.40GHz
stepping        : 8
microcode       : 0x127
cpu MHz         : 2393.902
cache size      : 1024 KB
physical id     : 0
siblings        : 4
core id         : 2
cpu cores       : 4
apicid          : 4
initial apicid  : 4
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch ida arat epb dtherm tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms
bugs            :
bogomips        : 4787.80
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

processor       : 3
vendor_id       : GenuineIntel
cpu family      : 6
model           : 77
model name      : Intel(R) Atom(TM) CPU  C2550  @ 2.40GHz
stepping        : 8
microcode       : 0x127
cpu MHz         : 2393.902
cache size      : 1024 KB
physical id     : 0
siblings        : 4
core id         : 3
cpu cores       : 4
apicid          : 6
initial apicid  : 6
fpu             : yes
fpu_exception   : yes
cpuid level     : 11
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes rdrand lahf_lm 3dnowprefetch ida arat epb dtherm tpr_shadow vnmi flexpriority ept vpid tsc_adjust smep erms
bugs            :
bogomips        : 4787.80
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

meminfo

# cat /proc/meminfo
MemTotal:        8130800 kB
MemFree:          130376 kB
MemAvailable:    3625532 kB
Buffers:            9140 kB
Cached:          3588808 kB
SwapCached:            0 kB
Active:           701624 kB
Inactive:        2967872 kB
Active(anon):      73156 kB
Inactive(anon):    12580 kB
Active(file):     628468 kB
Inactive(file):  2955292 kB
Unevictable:        1460 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:              1904 kB
Writeback:             0 kB
AnonPages:         73108 kB
Mapped:          4137400 kB
Shmem:             12660 kB
Slab:             197008 kB
SReclaimable:     150408 kB
SUnreclaim:        46600 kB
KernelStack:        2272 kB
PageTables:        11084 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     4065400 kB
Committed_AS:    4327064 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
DirectMap4k:       11264 kB
DirectMap2M:     8339456 kB

まとめ

  • まだユーザ数が少ない為?wgetの速度など体感では比較的速い
  • ただし場所がヨーロッパ?にある為、pingの応答は250ms程にはなってします
  • 自分用のCloud Foundry環境を試すのであれば11.99ユーロ(2016/3/12時点では1500円ちょっと)で格安で十分に遊べるスペックなのオススメ!
12
12
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
12
12