25
Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved HACK! THE Juju/MAAS デデデデ デデデデデデ デデデデデデ デデ デデ

Hack the juju_maas_interop用デモ資料

Embed Size (px)

Citation preview

Page 1: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

HACK! THE Juju/MAAS デモ資料

ビットアイル・エクイニクス山下 祐生

Page 2: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

自己紹介

•名前:山下祐生•年齢: 25 歳•所属:ビットアイル・エクイニクス•職種: OpenStack Enginner•社会人歴: 3 年•経歴:某大手 NIer に新卒入社し 3 年勤務したあと、 4 月からビットアイルに入社•最近ハマっていること

Juju/MAAS

2

Page 3: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved 3

Page 4: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

デモ構成

Page 5: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

OS インストールアプリデプロイ

Page 6: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

OS インストールアプリデプロイ

デモではリレーションを実施す

Page 7: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

Juju/MAASの何が嬉しいの?

Page 8: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

Juju/MAAS の嬉しいところ

•MAAS API がある ノードをタグやスペックで管理ができる MAAS のセグメントにつなげたマシンの電源を入れるだけで登録さ

れる 様々な OS のデプロイが可能

•Juju とりあえず試してみたいプロダクトをらくらくインストール 複雑なサーバ間の連携もコマンド一発 Ubuntu コミュニティのナレッジ簡単アクセス

8

Page 9: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

付録

Page 10: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

デモ環境を作成ハンズオン

•用意するもの‣一台の Ubuntu14.04 Desktop マシン (GUI が無いと大変です )

• CPU : 2Core 4Thread IntelVT 対応• MEM : 8GB• DISK : 100GB• Ubuntu14.04.4LTS

‣Ubuntu 14.04.4LTS の iso• http://releases.ubuntu.com/14.04/

※ コマンドの色分けホストマシンで実行の手順は黒文字MAAS インスタンス上で実行の手順はオレンジ

10

Page 11: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

1. パッケージインストールと初期設定

・ KVM installsudo apt-get install libvirt-bin virtinst virt-manager

・ maas-client installsudo apt-get install maas-cli

・ juju-core installsudo apt-get install juju-core

・鍵の設定ssh-keygenmv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keyssudo chmod 600 ~/.ssh/authorized_keyssudo chmod 600 ~/.ssh/id_rsa

11

Page 12: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

2.KVM 設定

・ default ネットワークを変更するvirsh net-edit default<dhcp></dhcp> で囲われている部分をすべて削除※MAAS が DHCP を流すために OFF にする必要がある

・設定の反映sudo virsh net-define /etc/libvirt/qemu/networks/default.xml

・ wget してきた ubuntu image を所定のディレクトリに配置sudo mv ~/Download/ubuntu-14.04.4-server-amd64.iso /var/lib/libvirt/images/

12

Page 13: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

3.MAAS インストール

・ virt-manager を使ってインスタンスを作成‣ ISO でインストールを選択‣ スペックは CPU2Core,Mem:2048,Disk30GB(qcow2),netowrk:NAT(default ネットワーク )‣ IP address は 192.168.122.2 を設定、 gateway は 192.168.122.1 、 DNS は 8.8.8.8

※Ubuntu のインストールは普段使っているオプションでの Ubuntu のインストールで OK

・ MAAS のレポジトリをインストールsudo apt-get install software-properties-commonsudo add-apt-repository ppa:maas/stable

・ MAAS のインストールsudo apt-get install maas

13

Page 14: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

4.MAAS の設定

・ MAAS アカウントの作成sudo maas-region-admin createadmin※ ユーザー名は ubuntu でお願いします

・ maas コマンドのセットアップの準備sudo maas-region-admin apikey --username=ubuntu※apikey をメモっておく

・ホストマシンで maas コマンドのセットアップmaas login m http://192.168.122.2/MAAS/api/1.0 [apikey]

・イメージのインポート実行maas m boot-source-selections create 1 os="ubuntu" release="trusty" arches="amd64" subarches="*" labels="*"maas m boot-source-selections create 1 os="ubuntu" release="xenial" arches="amd64" subarches="*" labels="*“maas m boot-resources import

14

Page 15: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

4.MAAS の設定

・ MAAS がデプロイするサーバ用の公開鍵作成cat ~/.ssh/authorized_keys |xargs -I% maas m sshkeys new key="%“

・ MAAS-DHCP の設定uuid=$(maas m node-groups list | grep uuid | cut -d\" -f4)maas m node-group-interface delete $uuid eth0maas m node-group-interfaces new $uuid \ip_range_high=192.168.122.200 \ip_range_low=192.168.122.10 \management=2 \static_ip_range_low=192.168.122.201 \name=eth0 \ip=192.168.122.2 \subnet_mask=255.255.255.0 \broadcast_ip=192.168.122.255 \static_ip_range_high=192.168.122.251 \interface=eth0

15

Page 16: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

4.MAAS の設定

・ DHCP の設定を確認maas m node-group-interface read $uuid eth0Success.Machine-readable output follows:{ "ip_range_high": "192.168.122.200", "ip_range_low": "192.168.122.10", "management": 2, "static_ip_range_low": "192.168.122.201", "name": "eth0", "ip": "192.168.122.2", "subnet_mask": "255.255.255.0", "broadcast_ip": "192.168.122.255", "static_ip_range_high": "192.168.122.251", "interface": "eth0"}

16

Page 17: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

4.MAAS の設定

・ virsh コマンドを maas がホストに対して叩ける用に鍵の設定scp ~/.ssh/authorized_keys [email protected]:~/.ssh/scp ~/.ssh/id_rsa [email protected]:~/.ssh/

・ホストマシンの DNS を MAAS に向けるsudo vim /etc/resolv.confnameserver 192.168.122.2

・ MAAS のディレクトリに鍵を配置sudo cp -p ~/.ssh/id_rsa ~/maas/.ssh/sudo chown maas. ~/maas/.ssh/sudo chmod 600 ~/maas/.ssh/

・ virsh が叩けることを確認sudo -u maas virsh -c qemu+ssh://[email protected]/system list

・再起動sudo reboot

17

Page 18: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

5.Juju のインストール

・ Juju の init をするjuju init

・ Juju のコンフィグファイル生成mv ~/.juju/environments.yaml ~/.juju/environments.yaml.bakvim ~/.juju/environments.yamldefault: cloud1

environments:

cloud1: type: maas

maas-server: 'http://192.168.122.2/MAAS'

maas-oauth: '[apikey の中身を入力 ]' bootstrap-timeout: 3600

18

Page 19: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

5.Juju のインストール

・ Juju の仮想マシンを作成sudo virt-install \--name juju \--ram=1024 \--disk path=/var/lib/libvirt/images/juju.img,size=15 \--vcpus 1 \--os-type linux \--network network=default \--noautoconsole \--graphics spice \--pxe

※MAAS に新しいマシンが NEW 状態で登録されたら、ダッシュボードから自動生成された名前から juju に変更する

・ juju マシンのパワーパラメータの変更maas m node update $(maas m nodes list hostname=juju|jq -r ".[].system_id") power_type=virsh power_parameters_power_address="qemu+ssh://[email protected]/system" power_parameters_power_id=juju

19

Page 20: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

5.Juju のインストール

・ Juju マシンが毎回 PXE ブートをするように修正sudo sed -i "s: <boot dev='hd'/>: <boot dev='network'/>:g" /etc/libvirt/qemu/juju.xmlsudo virsh define /etc/libvirt/qemu/juju.xml

・ Juju マシンのコミッショニングmaas m node commission $(maas m nodes list hostname=juju|jq -r ".[].system_id") enable_ssh=1※ コミッショニングが成功するまで待機

・ Juju マシンに bootstrap タグを付けるmaas m tags new name=bootstrapmaas m tag update-nodes juju add=$(maas m nodes list hostname=juju|jq -r ".[].system_id")

・ Juju を仮想マシンにデプロイjuju bootstrap --show-log --constraints tags=bootstrap --debug -e cloud1 --upload-tools=true

・ Juju がきちんと動いているか確認juju stat --format tabular

20

Page 21: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

6.Wordpress 用マシンの作成

・仮想マシンの作成sudo virt-install \--name wordpress \--ram=1024 \--disk path=/var/lib/libvirt/wordpress.img,size=15 \--vcpus 1 \--os-type linux \--network network=default \--noautoconsole \--graphics spice \--pxe

※MAAS に新しいマシンが NEW 状態で登録されたら、ダッシュボードで自動生成された名前から wordpress1 に変更する

・ wordpress マシンのパワーパラメータの変更maas m node update $(maas m nodes list hostname=wordpress1|jq -r ".[].system_id") power_type=virsh power_parameters_power_address="qemu+ssh://[email protected]/system" power_parameters_power_id=wordpress

21

Page 22: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

6.Wordpress 用マシンの作成

・ wordpress マシンが毎回 PXE ブートをするように修正sudo sed -i "s: <boot dev='hd'/>: <boot dev='network'/>:g" /etc/libvirt/qemu/wordpress.xmlsudo virsh define /etc/libvirt/qemu/wordpress.xml

・ wordpress マシンのコミッショニングmaas m node commission $(maas m nodes list hostname=wordpress1|jq -r ".[].system_id") enable_ssh=1※ コミッショニングが成功するまで待機

・ wordpress マシンに wordpress タグを付けるmaas m tags new name=wordpressmaas m tag update-nodes wordpress1 add=$(maas m nodes list hostname=wordpress1|jq -r ".[].system_id")

・ wordpress を仮想マシンにデプロイjuju deploy --constraints tags=wordpress wordpress

22

Page 23: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

7.DB 用マシンの作成

・仮想マシンの作成sudo virt-install \--name db \--ram=1024 \--disk path=/var/lib/libvirt/images/db.img,size=15 \--vcpus 1 \--os-type linux \--network network=default \--noautoconsole \--graphics spice \--pxe

※MAAS に新しいマシンが NEW 状態で登録されたら、ダッシュボードで自動生成された名前から db に変更する

・ DB マシンのパワーパラメータの変更maas m node update $(maas m nodes list hostname=db|jq -r ".[].system_id") power_type=virsh power_parameters_power_address="qemu+ssh://[email protected]/system" power_parameters_power_id=db

23

Page 24: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

7.DB 用マシンの作成

・ DB マシンが毎回 PXE ブートをするように修正sudo sed -i "s: <boot dev='hd'/>: <boot dev='network'/>:g" /etc/libvirt/qemu/db.xmlsudo virsh define /etc/libvirt/qemu/db.xml

・ DB マシンのコミッショニングmaas m node commission $(maas m nodes list hostname=db|jq -r ".[].system_id") enable_ssh=1※ コミッショニングが成功するまで待機

・ DB マシンに db タグを付けるmaas m tags new name=dbmaas m tag update-nodes db add=$(maas m nodes list hostname=db|jq -r ".[].system_id")

・ Mysql を仮想マシンにデプロイjuju deploy --constraints tags=db mysql

24

Page 25: Hack the juju_maas_interop用デモ資料

Copyright © 2016 Bit-isle Equinix Inc. All Rights Reserved

8. ここからデモ内容

・ wordpress と mysql の連携をさせるjuju add-relation wordpress mysql

ブラウザで wordpress.maas のアドレスを入れてみて画面が出てくれば成功です!

長い手順お疲れ様でした。

25