13. 第1日 講義資料 No.2
puppetコマンドの使用例
■
RHEL6.4の環境でPuppetを利用して、Webサーバを自動構築する例です。
- PuppetはEPELリポジトリで提供されており、次の手順でインストールします。
# yum install http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# yum install puppet
- 「簡単なマニフェストの例」のapache.ppをカレントディレクトリに用意します。
- --noopオプションで実行すると、マニフェストの文法チェックのみを行います。
# puppet apply apache.pp --noop
warning: Could not retrieve fact fqdn
notice: /Stage[main]//Package[httpd]/ensure: current_value absent, should be latest (noop)
notice: /File[/var/www/html/index.html]/ensure: current_value absent, should be file (noop)
notice: /Stage[main]//Service[httpd]/ensure: current_value stopped, should be running (noop)
notice: /Stage[main]//Exec[fw-http]/returns: current_value notrun, should be 0 (noop)
notice: Finished catalog run in 0.67 seconds
- 次は実際に設定を適用する例です。
# puppet apply apache.pp
warning: Could not retrieve fact fqdn
notice: /Stage[main]//Package[httpd]/ensure: created
notice: /File[/var/www/html/index.html]/ensure: defined content as
'{md5}1661d7d216a61e36241de00fffb3dfcc'
notice: /Stage[main]//Service[httpd]/ensure: ensure changed 'stopped' to 'running'
notice: /Stage[main]//Exec[fw-http]/returns: executed successfully
notice: Finished catalog run in 4.96 seconds
●
「--debug」オプションを指定すると、実行中の詳細情報が表示されます。
13
Copyright (C) 2014 National Institute of Informatics, All rights reserved.
14. 第1日 講義資料 No.2
Puppetマニフェストのその他の設定
■
「Class」によるモジュール化
- ひとまとまりの設定を「Class」にまとめて定義した後、必要に応じて「include」することで、
設定のモジュール化ができます。(マニフェストを複数ファイルに分割することも可能で
す。)
- 依存関係を設定する際は、Class単位での依存関係の指定も可能です。
- 「第12回 仮想マシン構築自動化演習」の例(PostgreSQLサーバ導入・設定用マニフェスト
「pgsql.pp」)を参考にしてください。
■
「通知関係」の設定
- 依存関係を指定する際は、単純な順序関係の他に、「通知関係」を指定することができます。
(下図の例を参照)
- 通知関係を設定すると、順序関係も同時に設定されます。両方を設定する必要はありません。
# httpdパッケージ導入後にhttpdサービスを有効化
Package['httpd'] -> Service['httpd']
# httpdパッケージが更新されるとhttpdサービスを再起動
Package['httpd'] ~> Service['httpd']
通知関係の設定例
(参考資料)
http://tatsu-zine.com/books/puppet
14
Copyright (C) 2014 National Institute of Informatics, All rights reserved.
15. 第1日 講義資料 No.2
Puppetを利用したインストールツールの例 (1)
■
RDOに標準で付属するインストーラ「Packstack」は、Puppetを利用してOpenStackの
各種コンポーネントをリモートインストールします。
- Nova/Glance/Cinder/Neutron/Keystone/Horizonなどのコンポーネント別にPuppetマニフェス
トが用意されています。
- 下図は、Packstackがマニフェストを配布して、順番に適用している所です。
15
Copyright (C) 2014 National Institute of Informatics, All rights reserved.
16. 第1日 講義資料 No.2
Puppetを利用したインストールツールの例 (2)
■
PackstackはSSHでマニフェストを配布・適用するため、複数ノードを並列にインス
トールすることができます。
# packstack --gen-answer-file=answer.txt
# grep NOVA answer.txt
CONFIG_NOVA_INSTALL=y
CONFIG_NOVA_API_HOST=10.64.200.99
CONFIG_NOVA_CERT_HOST=10.64.200.99
CONFIG_NOVA_VNCPROXY_HOST=10.64.200.99
CONFIG_NOVA_COMPUTE_HOSTS=10.64.200.99
CONFIG_NOVA_CONDUCTOR_HOST=10.64.200.99
CONFIG_NOVA_DB_PW=5ccf01bb5cdc4c9f
CONFIG_NOVA_KS_PW=2a18ec2a72cf455c
CONFIG_NOVA_SCHED_HOST=10.64.200.99
CONFIG_NOVA_SCHED_CPU_ALLOC_RATIO=16.0
CONFIG_NOVA_SCHED_RAM_ALLOC_RATIO=1.5
CONFIG_NOVA_COMPUTE_PRIVIF=eth1
・・・
# packstack --answer-file=answer.txt
answerファイルのテンプレートを作成
例としてNova関連オプションを確認
Nova Computeノードを複数指定可能
answerファイルに基づいてインストール
16
Copyright (C) 2014 National Institute of Informatics, All rights reserved.