puppetはLinux版構成管理ツール。Rubyで記述されていて、
独自の設定ファイルを解釈してサーバーの設定を維持管理してくれる。
便利な特徴は【設定ファイルが更新されたら、サーバーを再起動】の設定が楽になる。
設定変更→サーバー再起動といった依存関係が設定ファイルが作成でき、設定ファイルが読みやすい。
Debian/GNU Linuxの場合
sudo aptitude install puppet #puppetクライアント sudo aptitude install puppetmaster #puppetサーバー
その他のインストール
CentOS RubyGems ソースなどは本家ドキュメントを参考に
http://docs.puppetlabs.com/guides/installation.html
puppet をインストールするとpuppetmasterd / pupped のサーバ・クライアント両方が導入される。
設定ファイル
puppetmasterd/ puppedのどちらも設定とも/etc/puppet/puppet.confに記述します
/etc/puppet/puppet.conf
1 [main] # 2 logdir=/var/log/puppet # 3 vardir=/var/lib/puppet # 4 ssldir=/var/lib/puppet/ssl # puppet 5 rundir=/var/run/puppet # 共通設定 6 factpath=$vardir/lib/facter# 7 pluginsync=true # 8 9 [puppetmasterd] # 10 templatedir=/var/lib/puppet/templates #puppetmasterdの設定 11 #
puppetのはじめの一歩
クライアントとサーバーの応答が観たいので、バックグラウンドで自動起動されているpuppetを一旦終了する
sudo /etc/init.d/puppetmaster stop sudo /etc/init.d/puppet stop
puppetサーバーをフロントで起動
sudo puppetmasterd --no-daemonize --nonodes --verbose
puppetクライアントをフロントで起動
takuya@colinux:~$ sudo puppetd --server colinux --waitforcert 60 --test info: Retrieving plugins warning: Certificate validation failed; considering using the certname configuration option err: /File[/var/lib/puppet/lib]: Failed to generate additional resources during transaction: Certificates were not trusted: hostname was not match with the server certificate warning: Certificate validation failed; considering using the certname configuration option err: /File[/var/lib/puppet/lib]: Failed to retrieve current state of resource: Certificates were not trusted: hostname was not match with the server certificate Could not describe /plugins: Certificates were not trusted: hostname was not match with the server certificate warning: Certificate validation failed; considering using the certname configuration option err: Could not retrieve catalog: Certificates were not trusted: hostname was not match with the server certificate warning: Not using cache on failed catalog
なんかいっぱい証明書のエラーが出てきました。
これは --server で指定したサーバー名と受け取った証明書のサーバ名が一致しないことらしい。
認証されていないサーバー・クライアント間では通信ができません。
サーバー名にドメインを足してアクセスしてみる。
takuya@colinux:~$ sudo puppetd --server colinux.local --waitforcert 60 --test info: Retrieving plugins err: /File[/var/lib/puppet/lib]: Failed to generate additional resources during transaction: Cannot access mount[plugins] err: /File[/var/lib/puppet/lib]: Failed to retrieve current state of resource: Cannot access mount[plugins] Could not describe /plugins: Cannot access mount[plugins] info: No classes to store info: Caching catalog at /var/lib/puppet/state/localconfig.yaml notice: Starting catalog run notice: Finished catalog run in 0.04 seconds
サーバー・クライアント間に信頼関係を作る。
/etc/puppt/autosign.conf
にホスト名を書けばいいんだ。けど・・・・
うまくサインされない場合は
/etc/resolv.conf /var/lib/puppet/ssl
などを確認する。
僕の環境の場合
takuya@colinux:~$ cat /etc/resolv.conf domain local search local nameserver 192.168.0.1 nameserver 60.56.0.135 nameserver 202.234.232.6 nameserver 8.8.8.8
takuya@colinux:~$ tree /var/lib/puppet/ssl
/var/lib/puppet/ssl [error opening dir]
0 directories, 0 files
takuya@colinux:~$ sudo tree /var/lib/puppet/ssl
/var/lib/puppet/ssl
|-- ca
| |-- ca_crl.pem
| |-- ca_crt.pem
| |-- ca_key.pem
| |-- ca_pub.pem
| |-- inventory.txt
| |-- private
| | `-- ca.pass
| |-- requests
| |-- serial
| `-- signed
| `-- colinux.local.pem #クライアントの証明書
|-- certs
| |-- ca.pem
| `-- colinux.local.pem
|-- csr_colinux.local.pem
|-- private
|-- private_keys
| `-- colinux.local.pem
`-- public_keys
`-- colinux.local.pem
8 directories, 13 files
サーバー側に蓄えられた証明書を一旦消す方法
puppet などで証明書リセットしたい時、サーバーが保存している証明書を消す。
sudo rm /var/lib/puppet/ssl/ca/signed/*
証明書確認してみる。
takuya@colinux:~$ sudo puppetca --print colinux
/usr/sbin/puppetca:308: undefined method `to_text' for nil:NilClass (NoMethodError)
from /usr/sbin/puppetca:306:in `each'
from /usr/sbin/puppetca:306
takuya@colinux:~$ sudo puppetca --print colinux.local
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
Signature Algorithm: sha1WithRSAEncryption
Issuer: CN=colinux.local
Validity
Not Before: Jul 1 08:06:55 2010 GMT
Not After : Jun 30 08:06:55 2015 GMT
Subject: CN=colinux.local
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:d1:ea:64:f7:95:94:f1:fe:11:ff:9d:e0:bf:91:
(ry
b5:47:70:ec:06:81:04:bf:e3
Exponent: 65537 (0x10001)
X509v3 extensions:
Netscape Comment:
Puppet Ruby/OpenSSL Generated Certificate
X509v3 Basic Constraints: critical
CA:FALSE
X509v3 Subject Key Identifier:
BA:0E:F9:C1:C9:72:28:E8:EE:CB:A6:B8:75:D6:7C:86:D4:DA:7B:36
X509v3 Key Usage:
Digital Signature, Key Encipherment
X509v3 Extended Key Usage:
TLS Web Server Authentication, TLS Web Client Authentication, E-mail Protection
X509v3 Subject Alternative Name:
DNS:puppet, DNS:colinux.local, DNS:puppet.local
Signature Algorithm: sha1WithRSAEncryption
4d:70:cc:6a:a2:b0:bd:54:a3:13:96:cf:93:68:1f:b9:fb:ac:
(ry
dd:05:58:fc:a9:8b:d9:21:4e:74:82:c7:f2:1b:3b:cd:c7:20:
a9:6f
pupet のファイルサーバーにクライアントがアクセス出来ない
設定は更新されるけれど、ファイルサーバーからファイルが取得できない場合。
次のようなエラ
takuya@debian00:~$ sudo puppetmasterd --no-daemonize --verbose notice: Starting Puppet server version 0.25.5 (略) info: mount[files]: defaulting to no access for debian00.local err: Not authorized to call find on /file_metadata/files/etc/resolv.conf info: Expiring the node cache of debian00.local info: Not using expired node for debian00.local from cache; expired at Mon Jul 05 19:33:46 +0900 2010 info: Caching node for debian00.local notice: Compiled catalog for debian00.local in 0.00 seconds info: mount[files]: defaulting to no access for debian00.local err: Not authorized to call find on /file_metadata/files/etc/resolv.conf
クライアン側でエラー
takuya@debian00:~$ sudo puppetd --no-daemonize --onetime --verbose --server debian00.local info: Caching catalog for debian00.local info: Applying configuration version '1278326077' err: //resolv/File[/etc/resolv.conf]: Failed to retrieve current state of resource: Error 400 on SERVER: Not authorized to call find on /file_metadata/files/etc/resolv.conf Could not retrieve file metadata for puppet://debian00.local/files/etc/resolv.conf: Error 400 on SERVER: Not authorized to call find on /file_metadata/files/etc/resolv.conf at /etc/puppet/manifests/site.pp:15 notice: Finished catalog run in 0.09 seconds
fileserverのアクセス許可設定が変だった。
まちがい
/etc/puppet/fileserver.conf 8 [files] 9 path /etc/puppet/files 12 allow 192.168.5.0/24
正解
/etc/puppet/fileserver.conf 8 [files] 9 path /etc/puppet/files 12 allow 192.168.5.0/24 allow *.local ##mまたは allow 127.0.0.1
takuya@colinux:~$ sudo puppetd --server colinux.local --waitforcert 60 --test #127.0.0.1 へアクセスしている
ローカルループバックアドレスでもファイルサーバに許可を出すか、ホスト名はローカルIPを指すように変える。僕はホスト名が127.0.0.1を刺さないようにした。
puppetのエラーは
証明書やホスト名のエラーや、アクセス許可設定がエラー原因のほとんど。なれるまで結構大変。