Juju

Using Juju Charms 6~13 – Service(Scaling, Removing, Groups, HA, Bundle, Units, Actions, Storage)

Scaling Charms

Expanding service capacity

#增加一個service節點在本地host(不指定--to)
$ juju add-unit rabitmq-server
#增加一個service節點在machine 1
$ juju add-unit --to 1 rabitmq-server
#增加特定數量節點(n)、特定環境(e)
$ juju add-unit -n 10 mysql -e hpcloud

Scaling back

#刪除特定編號(ex: 2號)的節點
$ juju remove-unit mediawiki/2
#銷毀特定編號(ex: 1號)機器
$ juju destroy-machine 1

Removing services and environments

Remove a service

#刪除特定服務(ex: mysql),若有Relation存在則會斷開
$ juju remove-service mysql

Remove machines

#移除特定編號(ex: 1號)機器
$ juju remove-machine 1

Destroying the environment

#銷毀執行環境(移除所有節點及服務)
$ juju destroy-environment <environment>

Caveats

#解決units的error,讓其繼續運作,解除中斷的情況
$ juju resolved <unit>

Groups of Services

#替佈署的service命名
$ juju deploy mysql <name>
$ juju deploy mysql wikidb
#使用已命好的名稱建立連結(-n可以設定unit的數量,換句話說就是建立了一個群組)
$ juju deploy mysql masterdb
$ juju deploy mysql slavedb -n2
$ juju add-relation masterdb:master slavedb:slave
#可以針對命好名的群組作設定
$ juju set slavedb some_param=new_value

Service High Availability (HA)

Distribution groups

#若系統有啟用 Availability Zones 或 Availability Sets ,佈署數個Service時,就會存在HA的特性
$ juju deploy -n 10 <service>

Availability Zones

#機器佈署在不同的zone,可以達到HA(distribution groups)的效果
$ juju bootstrap --to zone=us-east-1b
$ juju add-machine zone=us-east-1c

Azure Availability Sets

Azure的預設HA機制,預設是開啟的,功能是要確保所有的unit不會在同一時間失效


Creating and using Bundles

Bundle 可以透過線上的store下載,也可以透過本地端yaml檔來安裝

Local deploy via command-line

#在本地端佈署Bundle yaml要使用juju quickstart,因此必須先行安裝
$ sudo add-apt-repository ppa:juju/stable
$ sudo apt-get install juju-quickstart
#務必使用bundle proof來確保可能會發生的錯誤
$ juju bundle proof ../path-your-bundle-name
#啟用本地bundle
$ juju quickstart bundle.yaml

Using Units

juju ssh

#遠端連線到某一個unit
$ juju ssh mysql/3

juju scp

#遠端複製檔案(從machine 2到本地)
$ juju scp 2:/var/file .
# 同時複製多個不同的遠端檔案
$ juju scp -v 2:/var/file 1:/var/file .
# 複製整個遠端的資料夾
$ juju scp -r 2:/var/log/ .
#複製本地的檔案到遠端
$ juju scp -e <environment> test.txt apache2/1:

juju run

#遠端下CLI指令(ex: uname)在所有machine上
$ juju run "uname -a" --all
# 遠端下CLI指令(ex: uptime)在特定machine上
$ juju run "uptime" --machine=2
# 遠端下CLI指令(ex: uptime)在所有運行此service的unit上
$ juju run "uptime" --service=mysql
# 遠端下CLI指令(ex: uptime)在特定unit上
$ juju run "uptime" --unit=nfs1/0

Juju Actions

#秀出service可執行的action
$ juju action defined mysql
backup: Take a backup of the database
...
# 命令service執行action
$ juju action do mysql/0 backup
Action queued with id: <ID>
#擷取某個action執行結果
$ juju action fetch <ID>
#查詢某個action目前的狀況
$ juju action status <ID>

Storage support

用juju storage指令,可以提出儲存媒體需求(storage requirements),進而使用制定的參數做規範。


文章參考資料

  1. Juju – Scaling Charms
  2. Juju – Removing services, units and environments
  3. Juju – Groups of Services
  4. Juju – Service High Availability (HA)
  5. Juju – Creating and using Bundles
  6. Juju – Using Units
  7. Juju – Juju Actions
  8. Juju – Storage support
Juju

Using Juju Charms 1~5 – Services(Deployment, Constraints, Configurations, Relations, Exposing)

Deploying Services

Juju的charm佈署來源大致上可分為兩個:從線上的charm store、從本地的repository

Deploying from the Charm Store

從charm store(cs)找到最新、最穩定的service版本來佈署

#精簡寫法
$ juju deploy mysql
#完整寫法
$ juju deploy <respository>:<series>/<service>
$ juju deploy cs:precise/mysql

Deploying from a local repository

使用時機:自己撰寫或修改charm、無法連網

#完整寫法(多了repository的環境參數)
$ juju deploy --repository=<path/to/files> :/
$ juju deploy --repository=/usr/share/charms/ local:trusty/vsftpd
#repository環境參數也可事先宣告,deploy時就不用再打了
$ export JUJU_REPOSITORY=/usr/share/charms/
$ juju deploy local:trusty/vsftpd
#series系列參數也可事先設定,deploy時就不用再打了(可從CLI設定,也可以從yaml檔設定)
$ juju set-env "default-series=trusty"
$ juju deploy --repository=. local:haproxy

Deploying to specific machines and containers

#佈署service在特定machine(本機host=bootstrap node→machine 0)
$ juju deploy --to 0 mysql
#佈署service在特定machine(ex:24)、特定container(ex:3)
$ juju deploy mysql --to 24/lxc/3
#佈署service在特定machine(ex:25)、新增一個特定的container
$ juju deploy mysql --to lxc:25
#佈署在MAAS上的特定機器
$ juju deploy mysql --to host.mass
#用特定的network佈署service
$ juju deploy --networks db,monitor mysql

Status Overview

$ juju status

Machine Constraints

Working with constraints

–constraints可以對機器做一些限制,針對juju deploy 是對service做限制;針對juju bootstrap是對整個環境(environment)做限制。最常用的兩個限制就是CPU數量(cpu-cores)、記憶體大小(mem)

#Bootstrap Node環境限制
$ juju bootstrap --constraints="mem=4G"
#佈署Service的限制
$ juju deploy --constraints="cpu-cores=8 mem=4G" mysql
#取得環境限制
$ juju get-constraints
#取得特定service限制
$ juju get-constraints mysql

Service Configuration

Deploying with a configuration file(.yaml)

#對整個環境做配置
$ juju deploy --config=myconfig.yaml
#對Service做配置
$ juju deploy --config=myconfig.yaml mediawiki
#取得目前對Service的配置
$ juju get mediawiki
#對Service設定某幾個config屬性
$ juju set mediawiki skin=monoblock name='Baddy Wiki'
#對Service取消某幾個config屬性
$ juju unset mediawiki skin name

Managing Relationships

有的Service可以獨自運作,但有的需要數個Service一起才能服務。

#建立Service之間的Relation
$ juju add-relation mysql wordpress
#建立Service之間的"特定角色"之Relation(一個serviced可能存在著超過一種以上的Relation)
$ juju add-relation mediawiki:db mysql
#移除Relation
$ juju remove-relation mediawiki mysql

Exposing Services

Service預設都是沒有對外開放的,因此要解除某些防火牆的設定才能對外開放。

#對外開放Service
$ juju expose wordpress
#對外封鎖Service
$ juju unexpose wordpress

文章參考資料

  1. Juju – Deploying Services
  2. Juju – Machine Constraints
  3. Juju – Service Configuration
  4. Juju – Managing Relationship
  5. Juju – Exposing Service
MAAS

MAAS Overview

What is MAAS?

MAAS 全名為 Metal As A Service,它提供一些介面及方式,讓使用者可以用類似管理雲端虛擬機器(VM)的彈性方式,來管理實體的伺服器(bare metal),此外如 KVM 等虛擬機器也能被視為Node被管理。在此平台上,所有的機器都能夠快速的被調配及摧毀,如同Amazon AWS、Google GCE、Microsoft Azure提供的服務一樣。

MAAS 可以視為一個獨立的 PXE 服務,或者與其他技術相結合。尤其是,它與 Juju (the service and model management service)之間的工作相容性特別好。

完美的組合:使用 MAAS 管理機器(machines),並使用 Juju 管理在這些機器上運行的服務(services)。

MAAS 相當於是 Juju 的 backend (resource pool) ,換句話說也就是 Juju 的 “cloud provider"。 因此在 Juju 所做的操作也會衍伸影響到 MAAS 的狀態。例如: Juju 端移除了一台機器, MAAS 端也會有一台機器被釋放回pool。


What MAAS offers?

MAAS 能夠創建一個額外的單一資源池(single resource pool),去管理大量的實體機器。參與的機器都可以被自動配置(Debian preseed)和正常使用。當不再需要這些機器時,他們也會被釋放回池中。MAAS提供了一些必要的功能,包括:

  • web UI
  • API/CLI support
  • HA(high availability)
  • IPv6 support
  • open source IP address management (IPAM)
  • Ubuntu, CentOS, or Windows installation support
  • inventory of components
  • DHCP and DNS for other devices on the network
  • VLAN and fabric support

How MAAS works?

MAAS 管理節點(a pool of nodes)的流程,簡單分為幾個階段狀態:

  1. “Enlisting" state: 註冊新系統
  2. “Commissioning" state: 預備被用來開啟service
  3. “Ready" state: 已經準備完成
  4. “Allocated" state: 配置給user
  5. “Deployed" state: 佈署service
  6. “Releasing" state: 使用完畢後,可以釋放資源回到pool

MAAS 是透過如 IPMICisco UCS 這樣的介面來管理實體機器。

  • IPMI: 智慧平台管理介面(Intelligent Platform Management Interface),能夠橫跨不同的作業系統、韌體和硬體平台,可以智慧型的監視、控制和自動回報大量伺服器的運作狀況,以降低伺服器系統成本。
  • Cisco UCS: Cisco整合運算系統(Cisco Unified Computing System),與IPMI概念十分接近。

Key components and colocation of all services

MAAS 中最重要的兩個組件是 region controller 與 rack controller ,透過這兩個控制器才能完整的控制所有的部屬工作。
若要達成HA的話,在系統架構下,就要同時存在許多的region controller 與 rack controller。此外,DHCP的配置也是使服務能成功運作的關鍵。


文章參考資料

  1. MAAS 官方文件
  2. MAAS 運作流程
  3. wiki – IPMI