RaspberryPi2でプライベートクラウド（2） --CloudStack編--

ここからは前回RaspberryPi2（以降Rpi2と表記）にインストールしたUbuntu上でCloudStackをビルドしていきます。

　CloudStackはIA用パッケージは既に入手できるのですが、ARM用のパッケージは用意されていないため自前でソースからビルドする必要があります。また、Raspbianではビルドは可能ですが、動作時にTomcat6のバージョンが動作要件から外れるのでUbuntuを選んでいます。
　CloudStackのビルドに関してはRpi2でも可能ですが、ビルドにかかる時間が2時間以上になります。PC上のUbuntuでビルドしたパッケージでもそのままRpi2にはインストールできます。手順は全く同じです。

ビルドに関しては[こちら](http://docs.cloudstack.apache.org/projects/cloudstack-installation/en/4.4/building_from_source.html)を参考にしています。
それでは説明していきたいと思います。


###ビルドに必要なパッケージの準備

・まずはビルドに必要なパッケージをインストールします。

```shell:console
ubuntu@ubuntu:~$ sudo apt-get install git ant debhelper openjdk-7-jdk tomcat6 libws-commons-util-java genisoimage python-mysqldb libcommons-codec-java libcommons-httpclient-java liblog4j1.2-java maven
```

・次にgitを利用して、CloudStackのソースをCloneします。

```shell:console
ubuntu@ubuntu:~$ git clone https://git-wip-us.apache.org/repos/asf/cloudstack.git
```

・CloudStackディレクトリに移動して、ブランチを変更します。最新は4.5.1と4.4.2なのですが、ビルドに失敗してしまうので4.3.2をビルドすることにします。

```shell:console
ubuntu@ubuntu:~$ cd cloudstack/
ubuntu@ubuntu:~/cloudstack$ git tag -l |less
ubuntu@ubuntu:~/cloudstack$ git checkout -b ver4.3.2 refs/tags/4.3.2
```

・ビルドします。Rpi2だと1時間くらいかかります。

```shell:console
ubuntu@ubuntu:~/cloudstack$ mvn -P deps clean install
.
.
.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Apache CloudStack ................................. SUCCESS [2:06.775s]
[INFO] Apache CloudStack Maven Conventions Parent ........ SUCCESS [0.287s]
[INFO] Apache CloudStack Framework - Managed Context ..... SUCCESS [40.826s]
[INFO] Apache CloudStack Utils ........................... SUCCESS [1:27.911s]
[INFO] Apache CloudStack Framework ....................... SUCCESS [0.273s]
[INFO] Apache CloudStack Framework - Event Notification .. SUCCESS [42.497s]
[INFO] Apache CloudStack Framework - Configuration ....... SUCCESS [23.982s]
[INFO] Apache CloudStack API ............................. SUCCESS [1:38.078s]
[INFO] Apache CloudStack Framework - REST ................ SUCCESS [38.895s]
[INFO] Apache CloudStack Framework - IPC ................. SUCCESS [35.427s]
[INFO] Apache CloudStack Cloud Engine .................... SUCCESS [0.286s]
[INFO] Apache CloudStack Cloud Engine API ................ SUCCESS [37.304s]
[INFO] Apache CloudStack Core ............................ SUCCESS [57.762s]
[INFO] Apache CloudStack Agents .......................... SUCCESS [1:18.971s]
[INFO] Apache CloudStack Framework - Clustering .......... SUCCESS [19.750s]
[INFO] Apache CloudStack Framework - Event Notification .. SUCCESS [12.358s]
[INFO] Apache CloudStack Cloud Engine Schema Component ... SUCCESS [1:59.850s]
[INFO] Apache CloudStack Framework - Jobs ................ SUCCESS [38.155s]
[INFO] Apache CloudStack Cloud Engine Internal Components API  SUCCESS [26.620s]
[INFO] Apache CloudStack Server .......................... SUCCESS [8:46.914s]
[INFO] Apache CloudStack Usage Server .................... SUCCESS [48.495s]
[INFO] Apache XenSource XAPI ............................. SUCCESS [40.832s]
[INFO] Apache CloudStack Cloud Engine Orchestration Component  SUCCESS [1:02.775s]
[INFO] Apache CloudStack Cloud Services .................. SUCCESS [0.264s]
[INFO] Apache CloudStack Secondary Storage Service ....... SUCCESS [41.489s]
[INFO] Apache CloudStack Engine Storage Component ........ SUCCESS [46.984s]
[INFO] Apache CloudStack Engine Storage Volume Component . SUCCESS [35.256s]
[INFO] Apache CloudStack Engine Storage Image Component .. SUCCESS [28.268s]
[INFO] Apache CloudStack Engine Storage Data Motion Component  SUCCESS [29.661s]
[INFO] Apache CloudStack Engine Storage Cache Component .. SUCCESS [26.290s]
[INFO] Apache CloudStack Engine Storage Snapshot Component  SUCCESS [47.968s]
[INFO] Apache CloudStack Cloud Engine API ................ SUCCESS [21.942s]
[INFO] Apache CloudStack Cloud Engine Service ............ SUCCESS [53.926s]
[INFO] Apache CloudStack Plugin POM ...................... SUCCESS [15.396s]
[INFO] Apache CloudStack Plugin - API Rate Limit ......... SUCCESS [41.465s]
[INFO] Apache CloudStack Plugin - API Discovery .......... SUCCESS [34.764s]
[INFO] Apache CloudStack Plugin - ACL Static Role Based .. SUCCESS [25.896s]
[INFO] Apache CloudStack Plugin - Host Anti-Affinity Processor  SUCCESS [25.047s]
[INFO] Apache CloudStack Plugin - Explicit Dedication Processor  SUCCESS [25.557s]
[INFO] Apache CloudStack Plugin - User Concentrated Pod Deployment Planner  SUCCESS [24.722s]
[INFO] Apache CloudStack Plugin - User Dispersing Deployment Planner  SUCCESS [24.933s]
[INFO] Apache CloudStack Plugin - Implicit Dedication Planner  SUCCESS [51.223s]
[INFO] Apache CloudStack Plugin - Skip Heurestics Planner  SUCCESS [24.460s]
[INFO] Apache CloudStack Plugin - Host Allocator Random .. SUCCESS [24.955s]
[INFO] Apache CloudStack Plugin - Dedicated Resources .... SUCCESS [46.441s]
[INFO] Apache CloudStack Plugin - Hypervisor OracleVM .... SUCCESS [31.957s]
[INFO] Apache CloudStack Plugin - Open vSwitch ........... SUCCESS [27.536s]
[INFO] Apache CloudStack Plugin - Hypervisor Xen ......... SUCCESS [1:18.625s]
[INFO] Apache CloudStack Plugin - Hypervisor KVM ......... SUCCESS [1:36.921s]
[INFO] Apache CloudStack Plugin - RabbitMQ Event Bus ..... SUCCESS [27.644s]
[INFO] Apache CloudStack Plugin - Hypervisor Baremetal ... SUCCESS [34.726s]
[INFO] Apache CloudStack Plugin - Hypervisor UCS ......... SUCCESS [28.920s]
[INFO] Apache CloudStack Plugin - Hypervisor Hyper-V ..... SUCCESS [44.223s]
[INFO] Apache CloudStack Plugin - Network Elastic Load Balancer  SUCCESS [29.151s]
[INFO] Apache CloudStack Plugin - Network Internal Load Balancer  SUCCESS [59.334s]
[INFO] Apache CloudStack Plugin - Network Juniper Contrail  SUCCESS [1:24.905s]
[INFO] Apache CloudStack Plugin - Palo Alto .............. SUCCESS [51.382s]
[INFO] Apache CloudStack Checkstyle Configuration ........ SUCCESS [1.570s]
[INFO] Apache CloudStack Plugin - Network Nicira NVP ..... SUCCESS [1:29.775s]
[INFO] Apache CloudStack Plugin - BigSwitch Virtual Network Segment  SUCCESS [42.392s]
[INFO] Apache CloudStack Plugin - Midokura Midonet ....... SUCCESS [1:41.335s]
[INFO] Apache Cloudstack Plugin - Stratosphere SSP ....... SUCCESS [43.995s]
[INFO] Apache CloudStack Plugin - Storage Allocator Random  SUCCESS [25.996s]
[INFO] Apache CloudStack Plugin - User Authenticator LDAP  SUCCESS [1:00.939s]
[INFO] Apache CloudStack Plugin - User Authenticator MD5 . SUCCESS [25.720s]
[INFO] Apache CloudStack Plugin - User Authenticator Plain Text  SUCCESS [24.411s]
[INFO] Apache CloudStack Plugin - User Authenticator SHA256 Salted  SUCCESS [35.302s]
[INFO] Apache CloudStack Plugin - Dns Notifier Example ... SUCCESS [24.212s]
[INFO] Apache CloudStack Plugin - Storage Image S3 ....... SUCCESS [28.741s]
[INFO] Apache CloudStack Plugin - Storage Image Swift provider  SUCCESS [27.232s]
[INFO] Apache CloudStack Plugin - Storage Image default provider  SUCCESS [26.476s]
[INFO] Apache CloudStack Plugin - Storage Image sample provider  SUCCESS [25.619s]
[INFO] Apache CloudStack Plugin - Storage Volume SolidFire Provider  SUCCESS [42.641s]
[INFO] Apache CloudStack Plugin - Storage Volume default provider  SUCCESS [27.298s]
[INFO] Apache CloudStack Plugin - Storage Volume sample provider  SUCCESS [27.281s]
[INFO] Apache CloudStack Plugin - SNMP Alerts ............ SUCCESS [37.268s]
[INFO] Apache CloudStack Plugin - Syslog Alerts .......... SUCCESS [31.757s]
[INFO] Apache CloudStack Plugin - Network VXLAN .......... SUCCESS [37.851s]
[INFO] Apache CloudStack Framework - Spring Life Cycle ... SUCCESS [15.391s]
[INFO] cloud-framework-spring-module ..................... SUCCESS [36.981s]
[INFO] Apache CloudStack Test ............................ SUCCESS [13.720s]
[INFO] Apache CloudStack Client UI ....................... SUCCESS [2:13.845s]
[INFO] Apache CloudStack Console Proxy - RDP Client ...... SUCCESS [45.691s]
[INFO] Apache CloudStack Console Proxy ................... SUCCESS [0.265s]
[INFO] Apache CloudStack Console Proxy - Server .......... SUCCESS [21.479s]
[INFO] Apache CloudStack Framework - QuickCloud .......... SUCCESS [1.629s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:05:54.281s
[INFO] Finished at: Thu May 21 22:23:59 UTC 2015
[INFO] Final Memory: 54M/164M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "deps" could not be activated because it does not exist.
ubuntu@ubuntu:~/cloudstack$
```

・ビルドに成功したらパッケージを作成します。これも1時間くらいかかります。

```shell:console
ubuntu@ubuntu:~/cloudstack$ dpkg-buildpackage -uc -us
.
.
.
dpkg-genchanges: warning: the current version (4.3.2) is earlier than the previous one (4.3.2-snapshot)
dpkg-genchanges: including full source code in upload
 dpkg-source --after-build cloudstack
dpkg-buildpackage: full upload; Debian-native package (full source is included)

ubuntu@ubuntu:~/cloudstack$ cd ..
ubuntu@ubuntu:~$ ls -l
total 1103672
drwxrwxr-x 36 ubuntu ubuntu      4096 May 22 09:06 cloudstack
-rw-r--r--  1 ubuntu ubuntu  40773118 May 22 09:21 cloudstack-agent_4.3.2_all.deb
-rw-r--r--  1 ubuntu ubuntu  68331112 May 22 09:28 cloudstack-awsapi_4.3.2_all.deb
-rw-r--r--  1 ubuntu ubuntu     52024 May 22 09:28 cloudstack-cli_4.3.2_all.deb
-rw-r--r--  1 ubuntu ubuntu  43870004 May 22 09:12 cloudstack-common_4.3.2_all.deb
-rw-r--r--  1 ubuntu ubuntu     51998 May 22 09:28 cloudstack-docs_4.3.2_all.deb
-rw-r--r--  1 ubuntu ubuntu 153895462 May 22 09:19 cloudstack-management_4.3.2_all.deb
-rw-r--r--  1 ubuntu ubuntu  39593298 May 22 09:23 cloudstack-usage_4.3.2_all.deb
-rw-rw-r--  1 ubuntu ubuntu       995 May 22 07:54 cloudstack_4.3.2.dsc
-rw-rw-r--  1 ubuntu ubuntu 783560221 May 22 07:52 cloudstack_4.3.2.tar.gz
-rw-rw-r--  1 ubuntu ubuntu      3278 May 22 09:30 cloudstack_4.3.2_armhf.changes
ubuntu@ubuntu:~$
```

完了すると一つ上のディレクトリにパッケージが出来上がっています。

・apt-getでインストールできるようにレポジトリを準備します。Apacheを使って設定していきます。このあとはrootで作業する方が楽になります。

```shell:console
ubuntu@ubuntu:/$ su -
Password:
root@ubuntu:~# apt-get install apache2
root@ubuntu:~# mkdir -p /var/www/html/cloudstack
root@ubuntu:~# mv *.deb /var/www/html/cloudstack/
root@ubuntu:~# cd /var/www/html/cloudstack/
root@ubuntu:/var/www/html/cloudstack# apt-ftparchive packages . > Packages
root@ubuntu:/var/www/html/cloudstack# apt-ftparchive release . > Release
root@ubuntu:/var/www/html/cloudstack# gzip -c9 Packages > Packages.gz
root@ubuntu:/var/www/html/cloudstack#
```

これでapt-getでCloudStackをインストールするための準備ができました。

次回はCloudStack-managementのインストールをしたいと思います。