LoginSignup
7
14

More than 5 years have passed since last update.

RancherOSを試してみた

Last updated at Posted at 2019-02-27

はじめに

手軽にコンテナを運用するために、CentOSのKVM上にRancherOSをインストールしてみました。

謝辞

作業にあたって以下のサイトを参考にさせていただきました。
ありがとうございます☺
【Docker】RancherOSで本格的な自宅サーバーを構築しよう(2) ~ rancher-serverをインストール ~
KVMゲストとしてRancherOSをインストール
Rancherで作る お手軽コンテナ運用環境!! ~ Kubenetes牧場でコンテナ牛を飼おう!~
RancherOS で インストール後パスワードでログインする方法

前提

  • CentOS上にKVMが動作していること
  • OSバージョン:CentOS Linux release 7.6.1810

目標

RancherOSをローカルストレージから起動できるようにする。

構築手順

0.イメージファイル作成

検証なので10Gで作成しました。

$ sudo qemu-img create -f qcow2 /var/lib/libvirt/images/rancher.img 10G
Formatting '/var/lib/libvirt/images/rancher.img', 
fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 lazy_refcounts=off 

1.ISOをダウンロードする

$ cd /var/iso/rancheros
$ sudo wget https://releases.rancher.com/os/latest/rancheros.iso

2.ISOから起動

# virt-install \
  --name rancher \
  --vcpus 2 \
  --cpu host \
  --memory 2048,maxmemory=4096 \
  --os-variant virtio26 \
  --cdrom /var/iso/rancheros/rancheros.iso \
  --network network=default,model=virtio \
  --disk /var/lib/libvirt/images/rancher.img \
  --graphics none

上記コマンドを実行後、ずらーっとコンソールにログが流れます。

               ,        , ______                 _                 _____ _____TM
  ,------------|'------'| | ___ \               | |               /  _  /  ___|
 / .           '-'    |-  | |_/ /__ _ _ __   ___| |__   ___ _ __  | | | \ '--.
 \/|             |    |   |    // _' | '_ \ / __| '_ \ / _ \ '__' | | | |'--. \
   |   .________.'----'   | |\ \ (_| | | | | (__| | | |  __/ |    | \_/ /\__/ /
   |   |        |   |     \_| \_\__,_|_| |_|\___|_| |_|\___|_|     \___/\____/
   \___/        \___/     RancherOS amd64 4.14.85-rancher

         RancherOS v1.5.1  ttyS0

Autologin default

無事牛さんが現れました🐄

3.Rancherユーザのパスワード設定

SSH公開鍵を転送するためにパスワードを設定します。

$ sudo passwd rancher
[任意のパスワード]

4.SSH接続用の鍵を配置

以下、ローカルで作業します。

$ ssh-keygen -t ed25519
$ cd ~/.ssh/
$ cp id_ed25519.pub cloud_config.yml
$ vim cloud-config.yml 
$ cat cloud-config.yml 
#cloud-config
ssh_authorized_keys:
  - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBL1uzHCLiBvuCDcVEzDdh8VQxvn2IDc0VWV/r8iURyF [ユーザ名]@localhost.localdomain
hostname: rancher
$ scp ./cloud-config.yml rancher@192.168.122.74:~

RancherOS上で転送したファイルのフォーマットチェック。

$ ls
cloud-config.yml
$ sudo ros config validate -i cloud-config.yml

何も表示されなければOKです。

5.ローカルストレージにインストール

こちらの記事にある通り、インストールコマンド実行時にパスワードを設定します。
4.までの手順でSSH接続は可能ですが、何らかの理由でSSH接続できなくなった場合、詰むので確実に設定します。

$ sudo ros install -c cloud-config.yml -d /dev/vda --append "rancher.password=rancher"
INFO[0000] No install type specified...defaulting to generic
Installing from rancher/os:v1.5.1
Continue [y/N]: y
INFO[0002] start !isoinstallerloaded
INFO[0002] trying to load /bootiso/rancheros/installer.tar.gz
503e53e365f3: Loading layer  5.793MB/5.793MB
be4565044bd7: Loading layer   17.1MB/17.1MB
aba473c857a1: Loading layer   5.12kB/5.12kB
5832a0a1723a: Loading layer  13.64MB/13.64MB
740d67c0ae68: Loading layer  1.645MB/1.645MB
0617e3efc463: Loading layer  1.536kB/1.536kB
0b53db7286a2: Loading layer   2.56kB/2.56kB
417d4c7a93a5: Loading layer  3.072kB/3.072kB
Loaded image: rancher/os-installer:latest
INFO[0004] Loaded images from /bootiso/rancheros/installer.tar.gz
INFO[0004] starting installer container for rancher/os-installer:latest (new)
Installing from rancher/os-installer:latest
mke2fs 1.44.5 (15-Dec-2018)
64-bit filesystem support is not enabled.  The larger fields afforded by this feature enable full-strength checksumming.  Pass -O 64bit to rectify.
Creating filesystem with 2620928 4k blocks and 2621440 inodes
Filesystem UUID: 25599e4f-cab9-4c77-9bb3-9dfd32ee8bbc
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

Continue with reboot [y/N]: y
INFO[0020] Rebooting
INFO[0020] Setting reboot timeout to 60 (rancher.shutdown_timeout set to 60)
.....^[            ] reboot:info: Setting reboot timeout to 60 (rancher.shutdown_timeout set to 60)
.=.[            ] reboot:info: Stopping /docker : b9b4c6b7b7d9
............D...........[            ] reboot:info: Stopping /ntp : 3799c8b57b90
..@...[            ] reboot:info: Stopping /network : 41f0c72fe2d7
..<..[            ] reboot:info: Stopping /udev : f04a912c1409
..C..[            ] reboot:info: Stopping /system-cron : f540a3bfb619
..=..[            ] reboot:info: Stopping /acpid : fe95cdde9d2a
...?...[            ] reboot:info: Stopping /syslog : 56def79881a9
..H.[            ] reboot:info: Console Stopping [/console] : 7fa626960b96
[  876.639035] reboot: Restarting system

仮想マシンの作成が完了しました。
ゲストを再起動しています。

6.接続確認

ホストOS(CentOS)からSSH接続をしてみます。

$ ssh rancher@192.168.122.74
$ hostname
rancher

無事接続できました😃

ハマったポイント

手順「5.ローカルストレージにインストール」での、"-d" の指定

ISOイメージから起動したRancherOS上で、 df コマンドを実行しても、"/dev/sda" 、 "/dev/vda"は存在しません。

$ sudo df -h
Filesystem                Size      Used Available Use% Mounted on
overlay                 977.3M    203.2M    774.1M  21% /
tmpfs                     1.9G         0      1.9G   0% /dev
tmpfs                   949.8M         0    949.8M   0% /sys/fs/cgroup
tmpfs                   978.8M         0    978.8M   0% /mnt
tmpfs                   977.8M         0    977.8M   0% /media
none                      1.4G    752.0K      1.4G   0% /run
none                      1.4G    752.0K      1.4G   0% /var/run
devtmpfs                  1.9G         0      1.9G   0% /host/dev
shm                      64.0M         0     64.0M   0% /host/dev/shm
tmpfs                   977.3M    203.2M    774.1M  21% /etc/hostname
shm                      64.0M         0     64.0M   0% /dev/shm
devtmpfs                  1.9G         0      1.9G   0% /dev
shm                      64.0M         0     64.0M   0% /dev/shm

しかし、 /dev ディレクトリ以下にはしっかり vda が存在します。

$ ls /dev | grep *da
vda

初歩的なミスですが、備忘のために記載しておきます・・。

手順や認識に不備等あれば、ご指摘お願いします!

7
14
2

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
7
14