您好,登錄后才能下訂單哦!
Centos 6.2 puppet 安裝
Puppet 要求所有機(jī)器有完整的域名(FQDN),如果沒有 DNS 服務(wù)器提供域名的話,可以在兩臺(tái)機(jī)器上設(shè)置主機(jī)名(注意要先設(shè)置主機(jī)名再安裝 Puppet,因?yàn)榘惭b Puppet 時(shí)會(huì)把主機(jī)名寫入證書,客戶端和服務(wù)端通信需要這個(gè)證書):
# vi /etc/hosts
192.168.2.10 master master.test.net
192.168.2.11 client client.test.net
Puppet 要求所有機(jī)器上的時(shí)鐘保持同步,所以需要安裝和啟用 ntp 服務(wù)(如果采用 CentOS-6.2-x86_64-minimal.iso 最小化安裝,需要額外安裝這個(gè)軟件包)。
# yum install ntp
# chkconfig ntpd on
# ntpdate pool.ntp.org
29 Feb 15:22:47 ntpdate[15867]: step time server 196.25.1.1 offset 98.750417 sec
# service ntpd start
Starting ntpd: [ OK ]
安裝 puppet 服務(wù)
Puppet 需要 Ruby 的支持,如果要查看命令行幫助的話需要額外 ruby-rdoc 這個(gè)軟件包:
# yum install ruby ruby-libs ruby-rdoc
Puppet 不在 CentOS 的基本源中,需要加入 PuppetLabs 提供的官方源:
# yum -y install wget
# wget http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-1.noarch.rpm
# yum install puppetlabs-release-6-1.noarch.rpm
# yum update
在 master 上安裝和啟用 puppet 服務(wù):
# yum install puppet-server
# chkconfig puppet on
# service puppetmaster start
Starting puppetmaster: [ OK ]
關(guān)閉 iptables:
# /etc/init.d/iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
安裝 puppet 客戶端
在 client 上安裝 puppet 客戶端:
# yum install puppet
Puppet 客戶端使用 HTTPS 和服務(wù)端(master)通信,為了和服務(wù)器端通信必須有合法的 SSL 認(rèn)證,第一次運(yùn)行 puppet 客戶端的時(shí)候會(huì)生成一個(gè) SSL 證書并指定發(fā)給 Puppet 服務(wù)端。
# puppet agent --no-daemonize --onetime --verbose --debug --server=master.test.net
Puppet 服務(wù)端接受到客戶端的證書后必須簽字(sign)才能允許客戶端接入,sign 后用 puppet cert list –all 查看會(huì)發(fā)現(xiàn) client.test.net 前面多了一個(gè) + 后,表示 “加入” 成功:
# puppet cert list --all
client.test.net (65:3C:20:82:AE:F6:23:A8:0A:0B:09:EF:05:64:1D:BB)
+ master.test.net (AF:A0:32:78:D4:EB:D3:EE:02:1C:62:1C:83:3C:46:EC) (alt names: DNS:master, DNS:master.test.net)
# puppet cert --sign client.test.net
notice: Signed certificate request for client.test.net
notice: Removing file Puppet::SSL::CertificateRequest client.test.net at '/var/lib/puppet/ssl/ca/requests/client.test.net.pem'
# puppet cert list --all
+ client.test.net (65:3C:20:82:AE:F6:23:A8:0A:0B:09:EF:05:64:1D:BB)
+ master.test.net (AF:A0:32:78:D4:EB:D3:EE:02:1C:62:1C:83:3C:46:EC) (alt names: DNS:master, DNS:master.test.net)
這樣,客戶端和服務(wù)端就配置好了,雙方可以通信了。
Hello, world
現(xiàn)在可以在服務(wù)端寫個(gè)小例子來測(cè)試一下。這個(gè)例子作用很簡(jiǎn)單,用來在客戶端的 /tmp 目錄下新建一個(gè) helloworld.txt 文件,內(nèi)容為 hello, world. 在服務(wù)端編寫代碼:
# vi /etc/puppet/manifests/site.pp
node default {
file {
"/tmp/helloworld.txt": content => "hello, world";
}
}
在客戶端上執(zhí)行 puppet,運(yùn)行成功后會(huì)在 /tmp 看到新生成的 helloworld.txt:
$ puppet agent --test --server=master.test.net
warning: peer certificate won't be verified in this SSL session
info: Caching certificate for client.test.net
info: Caching certificate_revocation_list for ca
info: Caching catalog for client.test.net
info: Applying configuration version '1330668451'
notice: /Stage[main]//Node[default]/File[/tmp/helloworld.txt]/ensure: defined content as '{md5}e4d7f1b4ed2e42d15898f4b27b019da4'
info: Creating state file /home/vpsee/.puppet/var/state/state.yaml
notice: Finished catalog run in 0.03 seconds
$ cat /tmp/helloworld.txt
hello, world
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。