初めに
実用レベルでは無いと思いますが、とりあえず安価にRancherを
活用して個人開発環境を作るために作成します。
構成
構成 | ツール名 | バージョン |
---|---|---|
ハード | Raspberry Pi | 3 Model B |
OS | Rancher OS | v1.4.1 |
環境構築は全てMac OSにて行いました。
※SDカードは32GBを使用しましたが、もっと少なくても動くと思います
Rancher OSとは
日本語の公式ドキュメントがありますが、軽く記載します。
http://fromalto.sakura.ne.jp/rancher/docs/os/v1.x/ja/
特徴
- Docker を活用するための最小かつ最も簡単な手段
- 全てがDockerコンテナで作成されている
- 常に最新バージョンの Docker を扱うよう設計されている
- System DockerとUser Dockerの2つのDockerが存在
OSそのものをコンテナ用に使用しよう!的なスタンスらしい。
で、何が出来るの?
「Docker を活用するための最小かつ最も簡単な手段」と書いてあるので
結論として「手っ取り早くDockerを使いたい」、「コンテナを活用してサービスを立ち上げたい」
と言う時に活用できそう。
Rancher OSをダウンロード
以下より、Rancher OSを入手します。
https://github.com/rancher/os/releases
今回は「rancheros-raspberry-pi64.zip」を使用します。
ダウンロード後、解凍すると「rancheros-raspberry-pi64.img」が現れます。
Rancher OSインストール
以下、Raspberry Pi公式ページに沿ってOSをSDカードに書き込みます。
https://www.raspberrypi.org/documentation/installation/installing-images/mac.md
Windowsの方はお手数ですが公式を参考にSDカードに書き込んでみてください。
https://www.raspberrypi.org/documentation/installation/installing-images/windows.md
$ diskutil list
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *31.0 GB disk2
1: EFI EFI 209.7 MB disk2s1
2: Microsoft Basic Data RPI 30.8 GB disk2s2
私の環境では「dev/disk2」がSDカードでした。
# アンマウント
$ sudo diskutil umountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
# 書き込み
# ifはダウンロードしたRancher OSのimg
# ofは自分のSDカード
$ sudo dd bs=1m if=/Users/xxxx/Downloads/build/rancheros-raspberry-pi64.img of=/dev/disk2 conv=sync
2048+0 records in
2048+0 records out
2147483648 bytes transferred in 164.588263 secs (13047611 bytes/sec)
イメージが2.15GBほどあるのでそこそこ時間かかります。
いざ、Raspberry Pi3にmicro SDを挿して起動!!!
ラズベリーと牛さんが無事に表示されました。
起動後、以下のユーザーとパスワードでログインできました。
ユーザー:rancher
パスワード:rancher
もちろん、LANに繋いでいればSSHも可能です。
SDカード全体を使用する
デフォルトではSDカード全体を使用できないらしいので、公式の手順に沿って設定します。
https://rancher.com/docs/os/v1.x/en/installation/running-rancheros/server/raspberry-pi/
以下の設定は必須では無いかもしれないです。
# sshにて接続後に実行
[rancher@rancher ~]$ sudo fdisk /dev/mmcblk0
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (3,4, default 3):
First sector (4194304-60637183, default 4194304):
Last sector, +sectors or +size{K,M,G,T,P} (4194304-60
Last sector, +sectors or +size{K,M,G,T,P} (4194304-60637183, default 60637183):
Created a new partition 3 of type 'Linux' and of size 26.9 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
[rancher@rancher ~]$ sudo reboot
# 以下、再起動後
[rancher@rancher ~]$ sudo mkdir /mnt/docker
[rancher@rancher ~]$ sudo ros config set rancher.docker.extra_arg [-g,/mnt/docker]
[rancher@rancher ~]$ sudo mkfs.ext4 /dev/mmcblk0p3
mke2fs 1.43.9 (8-Feb-2018)
Discarding device blocks: done
Creating filesystem with 7055360 4k blocks and 1766016 inodes
Filesystem UUID: 1b5a72f8-8d99-4295-9fc7-f2eb2806b6eb
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[rancher@rancher ~]$ sudo ros config set mounts "[['/dev/mmcblk0p3','/mnt/docker','ext4','']]"
[rancher@rancher ~]$ sudo mount /dev/mmcblk0p3 /mnt/docker
[rancher@rancher ~]$ sudo system-docker restart docker
docker
[rancher@rancher ~]$ sudo cp -R /var/lib/docker/ /mnt
# 一応コピー確認
[rancher@rancher ~]$ sudo ls /mnt/docker/
builder containerd containers image network overlay2 plugins runtimes swarm tmp trust volumes
[rancher@rancher ~]$ sudo system-docker restart docker
docker
# マウント確認
[rancher@rancher ~]$ df
〜 長いので省略 〜
/dev/mmcblk0p3 27646916 45348 26174112 0% /mnt/docker
実際に使ってみる
実際にRancher Serverを立ち上げて使用してみます。
・・・と、思いますが続きは別記事に記載します。
残念ながら、Raspberry Pi3ではメモリが足りないため、Rancher Serverの起動ができませんでした。
悔しいのでとりあえず簡単に動きそうなRedmineを起動してみました。
# postgres起動
$ docker run -d --name some-postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_USER=redmine postgres
# Redmine起動
# 80番ポートを使用すれば外部アクセスも可能なはず
$ docker run -d --name some-redmine --link some-postgres:postgres -p 80:3000 redmine
しばらく待ってから、Raspberry PiのIPアドレスでブラウザ表示
例) http://192.168.1.5
起動成功!!!
因みに軽く動かしてみましたが、意外とサクサク動きます。
以上です。