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
Linux

Linux(Ubuntu)練習 – 鳥哥基礎篇6.1-6.3檔案與目錄配管理

檔案及目錄

變換目錄(change directory): cd

變換目錄
$ cd [絕對/相對路徑]
變換到某個使用者的家目錄
$ cd 波浪符[使用者名]

顯示所在目錄(print working directory): pwd

顯示確實路徑,而非連結路徑
$ pwd -P

建立目錄(make directory): mkdir

遞回建立多層目錄,即使原本都不存在
$ mkdir -p layer1/layer2/layer3
建立目錄,且同時設定權限(不使用預設權限)
$ mkdir -m 777 [目錄名稱]

刪除目錄(remove directory): rmdir

遞回刪除多層"空"目錄
$ rmdir -p layer1/layer2/layer3

執行檔路徑: $PATH

加入新的路徑(例如:/root)到執行檔路徑中
$ PATH="${PATH}:/root"

檢視檔案及目錄(list): ls

常用[-a]:列出所有檔案包含隱藏檔
常用[-d]:僅列出目錄本身,不列出目錄內檔案
常用[-l]:列出長串的完整屬性,包含權限等
$ ls [-aAdfFhilnrRSt] 檔名或目錄名稱..
$ ls [--color={never,auto,always}] 檔名或目錄名稱..
$ ls [--full-time] 檔名或目錄名稱..
$ ls -l 等同於 $ ll

複製檔案及目錄(copy): cp

常用[-a]:完整複製
常用[-i]:目標已存在時,會詢問是否覆蓋
常用[-p]:連同檔案的屬性(權限、用戶、時間)一起複製過去,而非使用預設屬性(備份常用)
常用[-r]:遞迴持續複製整個目錄
$ cp [-adfilprsu] 來源檔 目標檔

刪除檔案及目錄(remove): rm

常用[-f]:指的是force,不存在的檔案就忽略,不會詢問
常用[-i]:刪除前會詢問
常用[-r]:遞回刪除整個目錄(危險!)
$ rm [-fir] 目標檔

移動檔案及目錄(move): mv

常用[-f]:指的是force,存在同樣的檔案就覆蓋,不會詢問
常用[-i]:目標存在時,會詢問
常用[-u]:來源較新時就覆蓋
(利用mv指令也可以做到更名的動作)
$ mv [-fiu] 來源檔 目標檔

取得路徑的檔名、目錄名: basename、dirname

取得路徑的檔名 testfile
$ basename /etc/testdir/testfile
取得路徑的目錄名 /etc/testdir
$ dirname /etc/testdir/testfile

檔案內容查閱

 直接檢視檔案內容(Concatenate): cat

常用[-b]:列印行號(不包含空白行)
常用[-n]:列印行號(包含空白行)
$ cat [-AbEnTv] 檔案名

反向檢視檔案內容: tac

$ tac 檔案名

添加行號列印: nl

效果類似$ cat -b
$ nl 檔案名

可翻頁檢視: more、less

只能往後翻頁
$ more 檔案名
能夠前後翻頁,更加彈性
$ less 檔案名

擷取資料前幾行: head

$ head [-n number] 檔案名
擷取前n行
$ head -n 10 first10.txt
擷取不包含後面n行
$ head -n -10 exceptLast10.txt

擷取後面幾行: tail

$ tail [-n number] 檔案名
擷取後n行
$ tail -n 10 last10.txt
擷取第n行之後的所有
$ tail -n +10 exceptFirst10.txt
擷取第11行到第20行(利用管線|)
$ head -n 20 file.txt | tail -n 10

檢視非文字檔: od

$ od [-t TYPE] 檔案名
按照ASCII輸出
$ od -t oCc 檔案名
直接查詢文字的ASCII編碼
$ echo word | od -t oCc

修改檔案時間、開新檔案: touch

修改檔案時間
$ touch [-acdmt] 檔案名
開新(空白)檔案
$ touch 檔案名

文章參考資料

  1. 鳥哥的linux私房菜 – Linux檔案與目錄管理6.1-6.3
Linux

Linux(Ubuntu)練習 – 鳥哥基礎篇5.檔案權限、目錄配置

列出所有檔案的檔名其他詳細屬性(包含隱藏檔): ls -la

$ ls -la
-rw-r--r--. 1 root root 1993 May 10 18:01 install.cfg
運行結果依序為: [1.權限][2.連結][擁有者][群組][檔案容量(Bytes)][修改日期] [檔名]
  1. 權限(permission)
    • 第一位: 檔案類型
      • [ d ]是目錄(directory)
      • [ ]是檔案(file)
      • [ l ]是連結檔(link file);
      • [ b ]是裝置檔裡面的可供儲存的周邊設備(可隨機存取裝置)
      • [ c ]是裝置檔裡面的序列埠設備,例如鍵盤、滑鼠(一次性讀取裝置)
    • [第一組]第二位~第四位: 檔案擁有者的權限
    • [第二組]第五位~第七位: 檔案所屬群組的權限
    • [第三組]第八位~第十位: 其他人的權限
      檔案的權限預設用rwx分別表示讀、寫、執行,目錄的權限預設用rwx分別表示可查詢(ls)、可修改刪除檔名、可進入該目錄,沒有權限則用-表示。
  2. 有多少檔名連結到此節點(i-node)

改變檔案的權限: chmod

關於權限的9個字母,是每3個一組的,一共三組,每一組都是由r、w、x所組成。
每個權限的分數分別為r:4、w:2、x:1,總和為7。
例如: -rwxrwxrwx 表示的方式為777、-rwxr–r–表示的方式為744

基本設定方式
$ chmod [-R] xyz 檔案或目錄
$ chmod 777 init.conf
可用三個字母u(user)、g(group)、o(others)表示對象,用=做設定,rwx表示權限
$ chmod u=rwx,go=rx init.conf
可用字母a(all)做為對象,用+、-做加入或刪減,rwx表示權限
$ chmod a+w init.conf
$ chmod a-x init.conf

改變檔案擁有者: chown

基本設定方式
$ chown [-R] 帳號名稱 檔案或目錄
$ chown baddychiang init.conf
同時變更群組方式
$ chown [-R] 帳號名稱:群組名稱 檔案或目錄
$ chown root:root init.conf

改變檔案所屬群組: chgrp

基本設定方式
$ chgrp [-R] 群組名稱 檔案或目錄
$ chgrp testgroup init.conf

目錄樹結構圖

目錄樹架構示意圖


文章參考資料

  1. 鳥哥的Linux私房菜 – Linux檔案權限與 目錄配置
Linux

Linux(Ubuntu)練習 – 鳥哥基礎篇4.基本指令及熱鍵

指令

日期時間: date

完整日期時間
$ date
年/月/日
$ date +%Y/%m/%d
時間
$ date +%H:%M

月曆: cal

當月份月曆
$ cal
特定年月月曆
$ cal [month][year]
$ cal 10 2016

計算機: bc

啟動計算機
$ bc
設定小數點位數
$ scale=3

求助說明

$ [指令] --help

manual(man page)、info操作說明

尋找第一筆符合的說明
$ man [指令]
尋找所有符合的說明
$ man -f [指令]
尋找所有包含此指令(關鍵字)的說明
$ man -k [指令]
另一個尋找說明的方式(會分層分頁)
$ info [指令]

簡易文書編輯器: nano

$ nano [檔名]

資料同步寫入硬碟: sync

$ sync

關機指令: shutdown

關機
$ shutdown
多久後關機
$ shutdown -h [時間]
關機後多久再重開機
$ shutdown -r [時間]
某個時間發出關機警訊,但不會真的關機
$ shutdown -k [時間] [警告訊息]
取消關機
$ shutdown -c

重新開機: reboot

$ reboot

熱鍵

捲動console畫面

[Shift]+[PgUp]/[PgDn] 


答錯題目詳解

  • 在 man 的時候, man page 顯示的內容中,指令(或檔案)後面會接一組數字,這個數字若為 1, 5, 8 ,表示該查詢的指令(或檔案)意義為何?
    1) 一般使用者可以使用的指令或可執行檔案
    5)一些設定檔的檔案內容格式
    8)系統管理員能夠使用的管理指令
  • man page 顯示的內容的檔案是放置在哪些目錄中?
    放置在 /usr/share/man/ 與 /usr/local/man 等預設目錄中。

文章參考資料

  1. 鳥哥的Linux私房菜 – 第四章、首次登入與線上求助
MAAS

MAAS Management, Concepts and Terms

Management summary

MAAS提供了三種方式來管理機器:

  • GUI (web interface): 異於操作的介面、較為基本的設定
  • CLI (text-based terminal): 提供完整(可更進階)的設定、可與API互動
  • API (involves programming): 通常用於大型自動化

Concepts and terms

Deploy

在 GUI 及 Juju 中所指的都是「佈署一個服務或應用(deploy a service or an application)」。

Nodes

maas

Node指的是已經連接在網路上的所有物件(networked object),通常包含下列三者:

  • Controllers
    • region controller: 可被視為是負責做數據中心,其組成如下:
      1. the REST API server
      2. the PostgreSQL database
      3. DNS
      4. caching HTTP proxy
      5. a web UI
    • rack controller: 需要連接到每個“fabric”(下方有詳述)。顧名思義,常見的設置是在每個數據中心架設rack controller,其組成如下:
      1. DHCP
      2. FTP
      3. HTTP (for images)
      4. iSCSI
      5. power management.
  • Machines: 可以被佈署的機器節點
  • Devices: 不能被佈署應用程式的裝置節點

所有的節點都可以指定其父節點,當父節點被刪除時,所有的子節點也得跟著刪除。(可以用來管理 VM 或是在 MAAS 上運行的containers)

  • SAN (Storage Area Network): 儲存區域網路,是一種連線外接儲存裝置和伺服器的架構,架構的特點是,連線到伺服器的儲存裝置,將被作業系統視為直接連線的儲存裝置
  • iSCSI (Internet Small Computer System Interface): Internet小型電腦系統介面,使用 TCP/IP 協定,讓兩個主機通過 IP 網路相互協商然後交換 SCSI 命令。這樣一來,iSCSI 就是用廣域網路模仿了一個高效能的本地儲存匯流排,從而建立了一個SAN。

Zones (physical zones)

Zone 是一個包含了節點的組織型單位,它可協助容錯率(fault-tolerance)以及服務的表現(performance of services)。在 HA 的方面,它們可以被視為 availability zones (AZs)。

Regions

Regions 是一層在Zone之上的組織型單位,它包含任何在此區域(zone)中運行的機器信息(information)。特別是,PostgreSQL 資料庫就是在這個水平上運行,並維護所有機器的狀態。

Fabrics

Fabrics 是一組彼此連接且能互相溝通的 VLANs 集合。

Spaces

Spaces 是一組彼此能互相溝通的子網域羅集群組(logical grouping of subnets)的集合,值得一提的是,在同一個 Space 中的不同 subnets ,不一定附屬於同一個 Fabrics 。


Architectural overview

intro-arch-overview


文章參考資料

  1. MAAS 管理方式介紹
  2. MAAS 概念及術語
  3. wiki – SAN
  4. wiki – iSCSI
  5. MAAS – 架構圖
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
OpenStack

OpenStack Overview

What is OpenStack?

OpenStack is a cloud operating system that controls large pools of compute, storage, and networking resources throughout a datacenter, all managed through a dashboard that gives administrators control while empowering their users to provision resources through a web interface.


OpenStack core services

  • Keystone → Identity: 身分驗證、Token驗證
  • Nova → Compute: 計算、管理VM
    • Nova-api: 接受與回應user,負責API的呼叫
    • Nova-compute: 一個worker daemon,透過hypervisor的API建立VM,流程如下:
      1. 從Queue接受命令後,啟動KVM,並到DB更新狀態
      2. 與nova-volume及Ceph關係緊密
    • Nova-volume: 管理、增減volume到instance上
      (Cinder is a replacement of nova-volume)
    • Nova-network: 從Queue接收命令後,掌管網路的操作
      (Neutron is a replacement of nova-network)
    • Nova-scheduler: 從Queue接收instance的請求,負責決定要由哪一台host來執行(最佳化)
  • Neutron → Networking: 網路通訊
    • 特色如下:
      1. 可以讓user配置自己的網路
      2. pluggable backend
      3. 負責Layer 1-Layer 3的網路部分
      4. 提供HAProxy達到Load Balance as a Service
    • 組成如下:
      1. Neutron-server: 接受API請求,並路由到指定的plugin
      2. Neutron plugins and agents: 負責實際的網路運作
      3. Queue: 訊息傳遞
  • Glance → Image Service: 管理Image metadata
  • Swift → Object Storage: 儲存物件(ex: virtual disks, images, backup archiving),避免SPOF(Single Point Of Failure),自我修復
  • Cinder → Block Storage: 儲存區塊(ex: volumn, snapshot),但較缺乏scaling的部分
  • Queue → Message: 提供daemon之間的訊息傳遞,優點是可以buffer large workload
  • Database → State: 記錄各種狀態、時間資訊

OpenStack optional services

  • Horizon → Dashboard: 儀表板(Web UI),stateless,init API calls
  • Ceilometer → Telemetry: 收費、benchmark、擴充性、統計
  • Heat → Orchestration: 透過一些模板做查詢等

文章參考資料

  1. OpenStack 官方Overview
  2. aboutyun論壇 – 一分钟快速入门openstack
  3. Mastering Openstack – Omar Khedher (ISBN:978-1-78439-564-3)
Sublime

Sublime Text 3 使用筆記

主選單功能

  • View→Layout 畫面切割
  • View→Slidbar 側邊攔
  • Goto→Goto Anything 尋找檔案或資料夾
  • Goto→Goto Anything :50 尋找檔案或資料夾,並跳到第50行
  • Goto→Goto Symbol 尋找特定標籤(id、class等)

熱鍵

  • Ctrl+[ 、 Ctrl+] 向左向右縮排
  • Ctrl+Enter 插入至下一行
  • Ctrl+Shift+Enter 插入至上一行
  • Ctrl+L 選取單行
  • Ctrl + D  選擇下個相同程式碼
  • Alt+ F3 全選相同相同程式碼
  • Ctrl+` 開啟命令視窗
  • Ctrl+Shift+P→[install package] 安裝package

常用套件

  • Emmet  (HTML、CSS快速輸入語法)
  • HTMLPrettify (HTML、CSS、JS排版)
  • Trailing Spaces (檢測是否有多餘空白)
  • Emmet LiveStyle (同步新增CSS內容)
  • Goto-CSS-Declaration (追蹤CSS,熱鍵:微軟+.)
  • ColorPicker (CSS色盤,熱鍵:Ctrl+Shift+C。)

 

文章參考資料

  1. 一小時上手 Sublime Text 3 網頁編輯器
  2. 常用熱鍵及套件之投影片
  3. Subtime Text 3 官方套件列表
Markdown

Markdown in WordPress 使用筆記

強調 (Emphasis)

*斜體*
**粗體**

斜體

粗體


超連結 & Reference寫法

[估狗](www.google.com)

這是 [參考文章1][1] 還有 [參考文章2][2].
[1]: http://example.com/"Title"
[2]: http://example.org/"Title"

估狗

這是 參考文章1 還有 參考文章2.


圖片 & Reference圖片

![圖片比超連結多一個驚嘆號](image.png)

![圖片比超連結多一個驚嘆號][1]
[1]:image.png

註解

註解會 [^1] 在最下面

[^1]: 註解的內容在最下面

註解會 1 在最下面


ul (unsorted list) & ol (ordered list)

* 無排序1
* 無排序2

1. 有排序1
2. 有排序2
  • 無排序1
  • 無排序2
  1. 有排序1
  2. 有排序2

 引用文字 (Blockquotes)

> 引用了這段文字

引用了這段文字


保持文字原始間隔 (Preformatted)

每行前面留兩個空白再     開    始

每行前面留兩個空白再     開    始


Code & Code Block & 強調Syntext

`code`

四個~
code block
四個~

```css
#button {
border: none;
}
```

code

#button {
border: none;
}

標題 (Header)

# h1 #
## h2 ##
### h3 ###

h1

h2

h3


文章參考資料

  1. WordPress官方MarkDown規格
  2. Code Syntext支援列表

 

 


  1. 註解的內容在最下面