Transcript
Page 1: PowerShell DSC と Linux

PowerShell DSC と LinuxSystem Center User Group Japan #15 (2016.09.10)

Kazuki Takai

Page 2: PowerShell DSC と Linux

自己紹介

高井 一輝 (Takai Kazuki)

某ISP勤務

クラウドサービスの開発、設計、設備維持

Windows Server / System Center / Linux / etc…

System Center User Group Japan (SCUGJ)

Twitter : @zhuky7 / Facebook : kazuki.takai

Blog : http://operationslab.wordpress.com/

2

Page 3: PowerShell DSC と Linux

Agenda

PowerShell DSC おさらい

PowerShell DSC を使用した Linux の構成

Azure Automation DSC を使用した Linux の構成

おまけ

PowerShell on Linux

3

Page 4: PowerShell DSC と Linux

はじめる前に

本資料の内容は個人的な検証結果に基づきます

所属する会社や組織、マイクロソフト社の公式な見解を記載するものではありません

表記や内容に誤りがあるなど、お気づきの点があれば、facebook 等でご連絡いただけると幸いです

この資料では Preview 版の製品、テクノロジーについて記載しています

今後のリリースで機能や動作が変更、削除される可能性があります

4

Page 5: PowerShell DSC と Linux

Review

PowerShell DSCPowerShell DSC おさらい

5

Page 6: PowerShell DSC と Linux

PowerShell DSC とは

Chef とか Puppet みたいなやつ

6

Page 7: PowerShell DSC と Linux

PowerShell DSC とは

Desired State Configuration

構成(Configuration)を特定の状態に保ち続けるための仕組み

あるべき状態を定義

定義に基づいて設定を変更

定期的に設定をチェックし正しい状態を維持

Configuration as Code を実現するもの

コード化することで、管理・自動化が容易

ソフトウェア開発のナレッジを適用可能

PowerShell / WMF 4.0 以降で利用可能

7

Page 8: PowerShell DSC と Linux

Infrastructure as Code

Infrastructure as Code (広義の): インフラのコード化は主に2種類

Infrastructure as Code (狭義の)

インフラ(ファブリック)の定義をコード化して、管理・自動構成する

Azure Resource Manager, Chef Provision, etc…

Configuration as Code

ファブリック上で動作する環境(OS/OSE、ミドルウェア、アプリケーションなど)の構成、設定をコード化して、管理・自動構成する

PowerShell DSC, Azure Automation DSC, Chef, Puppet, etc…

8

Page 9: PowerShell DSC と Linux

PowerShell DSC のメリット

構成が管理されている

あるべき状態が定義されている

定義が表現されている(頭の中ではなくコードとして)

構成を担保できる

あるべき状態に保つ(保ち続ける)

必ず「定義された状態」になる(オペミスしない)

構成状態をレポートできる

9

Page 10: PowerShell DSC と Linux

(例)PowerShell DSC でできること

サーバーの役割と機能の有効化または無効化

レジストリ設定の管理

ファイルとディレクトリの管理

プロセスとサービスの開始、停止、および管理

グループおよびユーザーアカウントの管理

新しいソフトウェアの展開

環境変数の管理

Windows PowerShell スクリプトの実行

望ましい状態からずれた構成の修正

特定のノードでの実際の構成状態の検出

10

DSC Resource を追加、作成することで構成範囲を拡大可能

Page 11: PowerShell DSC と Linux

DSC の構成要素(1)

Configuration (構成)

「あるべき姿」を定義したもの

Configuration キーワードによって定義が記述された PowerShell スクリプト

Configuration をコンパイルした MOF ファイルをノードへ適用

Resource (リソース)

構成(操作)対象を実際に操作するために必要なもの

Configuration に書かれた定義を、実際の操作(手続き)へ橋渡しする

PowerShell スクリプトでも実装可能

11

Page 12: PowerShell DSC と Linux

DSC の構成要素(2)

Local Configuration Manager (LCM; ローカル構成マネージャー)

DSC エンジン

MOF と Resource を使用して構成を実施

DSC Pull サーバー

Pull モデル(更新モード)の場合に使用

DSC の Configuration や Resource をホストするサーバー

各 DSC ノード(ターゲットノード)の LCM からの要求を受け付け、MOF およびリソースを応答

LCM からのレポートを受信(サポートサーバー)

12

Page 13: PowerShell DSC と Linux

DSC の構成要素13

DSC Configuration MOF

ZIPDSC Resource

dll / ps1 / etc…

DSC Pull Server

WMF / PowerShell

Internet Information Services

DSC Service

+ Report Data

DSC Target Node

Page 14: PowerShell DSC と Linux

2種類の更新モード

Push

DSC ターゲットノードへ外部(またはローカル)から構成ファイルを送信(Push)して構成を実施

ローカルに Push する場合も、PSRemoting の有効化が必要

Pull

DSC ターゲットノードの LCM が Pull サーバを定期的にポーリングし、構成ファイルを取得(Pull)して構成を実施

DSC Pull サーバー側へ状態レポートを送信(オプション)

14

Page 15: PowerShell DSC と Linux

ローカル構成マネージャー

LCM : Local Configuration Manager

ノード構成ファイル(MOF)を解釈して構成を変更する DSC のエンジン

更新モードや構成モード、Pull サーバーのアドレスなどを設定

構成モード

ApplyOnly : 新しい構成は一度のみ適用し、構成の変更を追跡しない

ApplyAndMonitor : 構成を適用後、変更を追跡する(自動修正はしない)(既定)

ApplyAndAutoCorrect : 構成を適用後変更を追跡し、ずれが生じた場合は自動修正する

15

Page 16: PowerShell DSC と Linux

PowerShell DSC

for LinuxPowerShell DSC を使用したLinux の構成

16

Page 17: PowerShell DSC と Linux

PowerShell DSC for Linux

PowerShell DSC を使用して Linux の構成を管理・実行できる

Windows と同様の仕組みで管理できる

OS 上で動作する構成管理の仕組みであるため、ファブリックにあまり依存せず動く

Azure でも、AWS でも、オンプレミスの物理でも、VM でも

PowerShell DSC for Linux のパッケージには、大きく以下の二つが含まれる

Linux 用 DSC Agent (LCM)

Linux 用 DSC Resource (nx* DSC リソース)

17

Page 18: PowerShell DSC と Linux

PowerShell DSC for Linux の要件

サポート OS

RHEL および CentOS、Oracle Linux、Debian、Ubuntu、SuSE など

詳細な対応バージョンは MSDN 参照

必要なソフトウェア

glibc, python, python-ctypes, openssl, lincurl

omiserver

(PowerShell DSC for Linux / Linux 用 DSC)

18

Page 19: PowerShell DSC と Linux

DSC for Linux のインストール

glibc, python, python-ctypes, openssl, lincurl をインストールする

ディストリビューションが提供するパッケージをインストール

Ubuntu 16.04 LTS の場合は、デフォルトでほぼインストールされている(Python が新しすぎるかも…)

OMI Server のパッケージを GitHub からダウンロードしてインストール

https://github.com/Microsoft/omi

PowerShell DSC for Linux のパッケージを GitHub からダウンロードしてインストール

https://github.com/Microsoft/PowerShell-DSC-for-Linux

Microsoft ダウンロードセンターからダウンロードできるものは古いので使用しない(2016.09.10 現在)

19

Page 20: PowerShell DSC と Linux

Linux 用 DSC リソース

Linux 用の基本的な DSC リソースは nx モジュールにまとめられている

一部、含まれないリソースがある

20

nxArchive

nxEnvironment

nxFile

nxFileLine

nxGroup

nxPackage

nxScript

nxService

nxSshAuthorizedKeys

nxUser

nxComputer nxIPAddress

nxDNSServerAddress

nxFirewall

Page 21: PowerShell DSC と Linux

Linux 用 DSC Configuration の作成

Windows 上で作成(編集およびコンパイル)する場合(おすすめ)

WMF / PowerShell 4.0 以降が必要

Linux 用 DSC リソースをインストール

PowerShellGet を使用して PowerShell Gallery から nx モジュールをインストール

個別にダウンロードして、モジュールパスに配置

Linux 上で作成する場合(現時点ではおすすめしません)

PowerShell Core v6.0.0-alpha.9 以降をインストール

PowerShell DSC for Linux version 1.1.1 以降をインストール

21

Page 22: PowerShell DSC と Linux

DemoPowerShell DSC for Linux

22

Page 23: PowerShell DSC と Linux

Azure

Automation DSCAzure Automation DSC を使用した Linux の構成

23

Page 24: PowerShell DSC と Linux

Azure Automation DSC とは

Azure Automation サービスの機能の一つ

PowerShell DSC の Pull サーバー(のようなもの)としてふるまう

DSC Pull サーバーを手元に用意しなくてもよい

Azure VM との連携が容易

OS 上で LCM を設定しなくても、ポータルからの操作のみで Pull サーバーとの連携が可能(今のところ Windows のみ)

24

Page 25: PowerShell DSC と Linux

Azure Automation DSC の構成25

DSC Configuration MOF

ZIPDSC Resource

dll / ps1 / etc…

Azure Automation

DSC Target Node

Page 26: PowerShell DSC と Linux

Azure Automation DSC を使うためには

必要なもの

Azure のサブスクリプション

DSC Configuration スクリプト

(必要なら)追加の DSC Resource

Linux を構成する場合…

ターゲットノードに PowerShell DSC for Linux version 1.1 以降が必要(2016.0910 時点での最新版)

26

Page 27: PowerShell DSC と Linux

Azure Automation DSC + Linux

構成 Step

1. Azure Automation アカウント作成

2. DSC Configuration を Azure Automation 構成へアップロード

3. 標準リソース以外を使用する場合は、Azure Automation へリソースを追加

4. アップロードした Configuration をコンパイル

5. ターゲットノード側で DSC を利用できるよう構成

6. ターゲットノードを DSC ノードとして Azure Automation DSC 上でオンボード

7. ターゲットノードと DSC ノード構成を紐づけ

27

Page 28: PowerShell DSC と Linux

Azure Automation アカウント作成

新規 → 管理 → オートメーション

名前、リソースグループ、ロケーションを指定

28

Page 29: PowerShell DSC と Linux

Azure Automation メインパネル29

DSC Resourceの追加

ノード追加ノードに構成を紐づけ

Configuration の登録コンパイル

コンパイル済構成の一覧

Page 30: PowerShell DSC と Linux

Point! : ターゲットが Linux の場合

PowerShell DSC for Linux version 1.1 以降をターゲットにインストール

Register.py を使用して、ターゲットノードを Azure Automation DSC へ登録

/opt/microsoft/dsc/Scripts/Register.py <key> <url>

<key> : Automation account registration key

<url> : Automation account registration url

<key> と <url> は Azure ポータルから入手可能

Register.py を使用せず、構成用の metaconfiguration MOF を使用する方法もある

nx リソースをギャラリーから追加

30

Page 31: PowerShell DSC と Linux

DemoAzure Automation DSC

31

Page 32: PowerShell DSC と Linux

PowerShell on

LinuxPowerShell for every system!

32

Page 33: PowerShell DSC と Linux

PowerShell on Linux

PowerShell が Linux 上で動く

Linux だけでなく、macOS でも Windows でも

PowerShell for every system!

GitHub 上で公開

https://github.com/PowerShell/PowerShell

インストール方法なども、上記 URL に記載されている

お試し程度であれば、有志が公開しているコンテナーイメージを使用する方法もある

33

Page 34: PowerShell DSC と Linux

厳密には…

PowerShell Core が動く(Core Edition)

Desktop Edition

Full .NET Framework 依存

Windows クライアントおよび Windows Server のみ(Nano Server は除く)

Core Edition

.NET Core 依存

Desktop Edition のサブセット的な位置付け

Windows(Nano 含む)、Linux、macOS で動作

Edition の判別は $PSVersionTable.PSEdition

34

Page 35: PowerShell DSC と Linux

現状

まだ alpha 版 (v6.0.0-alpha.9)

開発中のため、実装されていない機能が多数ある

PSRP(PowerShell Remoting Protocol)によるネイティブ接続は未実装

SSH 接続経由で PowerShell を Subsystem としてキックすることは可能(要設定)

そもそも、OS 依存なコマンドは実装されていない

.NET Core ベースで動作するよう再実装されている部分があり、今までの(Desktop Edition の)コマンドレットと挙動が異なる箇所がある

Nano Server (に実装されている PowerShell 5.1 Core Edition)も、従来の(Desktop Edition の)PowerShell と(出力が)異なる場合があるため要注意

35

Page 36: PowerShell DSC と Linux

DemoPowerShell on Linux

36

Page 37: PowerShell DSC と Linux

まとめ

PowerShell DSC for Linux を使用することで、Windows と同様の手法で Linux

の構成管理が可能

Azure Automation DSC を使用することで、DSC Pull サーバを手元に用意しなくてもクラウド上で一元的な管理が可能

構成管理ツールは DSC だけではないので、利用環境に適したツールを使うべき

37

Page 38: PowerShell DSC と Linux

参考資料

Windows PowerShell Desired State Configuration の概要

https://msdn.microsoft.com/ja-jp/powershell/dsc/overview

Open Management Infrastructure

https://github.com/Microsoft/omi

PowerShell Desired State Configuration for Linux

https://github.com/Microsoft/PowerShell-DSC-for-Linux

PowerShell DSC for Linux version 1.1 is Now Available! And New Linux Resources!

https://blogs.msdn.microsoft.com/powershell/2015/09/29/powershell-dsc-for-linux-version-1-1-is-now-available-and-new-linux-resources/

Azure Automation DSC の概要

https://azure.microsoft.com/ja-jp/documentation/articles/automation-dsc-overview/

38


Top Related