在Linux下,Puppet是集中配置管理系統,擁有自己的描述語言,如果想要開發Puppet,就需要用到Puppet工具,下面小編以CentOS 5.5為例,給大家介紹下CentOS 5.5安裝配置Puppet的方法。
一:Puppet是一個自動化配置管理工具,最常用在C/S架構中。
puppet的語法允許你創建一個單獨腳本,用來在目標主機上建立一個用戶,所有目標主機會依次使用適合本地系統的語法來解釋和執行這個模塊。如果是在RedHat中執行,則使用的是useradd命令;若在FreeBSD中,則使用adduser命令。再者puppet有很好的靈活性。
二:安裝准備:
兩台CentOS 5.5 32位機器
主機IP及主機名
172.16.100.10 server.tech10.com
172.16.100.11 slave.tech11.com
facter:http://puppetlabs.com/downloads/facter/facter-1.5.9.tar.g
puppet: http://puppetlabs.com/downloads/puppet/puppet-2.6.3.tar.gz
三:安裝步驟
1:rpm -Uvh http://dl.Fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum install mysql mysql-devel mysql-server ruby ruby-devel ruby-irb ruby-mysql ruby-rdoc ruby-ri
查看下ruby的版本,版本是1.8.5
安裝facter及puppet
tar zxvf facter-1.5.9
cd facter-1.5.9
ruby install.rb
tar zxvf puppet-2.6.3.tar.gz
cd puppet-2.6.3
ruby install.rb
以上步驟均在兩台機器上執行
2:server端配置
a.拷貝源文件
mkdir /etc/puppet
cp conf/auth.conf /etc/puppet
cp conf/redhat/fileserver.conf /etc/puppet
cp conf/redhat/puppet.conf /etc/puppet
cp conf/redhat/server.init /etc/init.d/puppetmaster
chmod +x /etc/init.d/puppetmaster
chkconfig puppetmaster on
mkdir -p /etc/puppet/manifests
b.創建puppet帳號
groupadd puppet
useradd -g puppet puppet
puppetmasterd --mkusers
c.建立相應的目錄
mkdir /var/lib/puppet /rrd
chown puppet.puppet /var/lib/puppet/rrd
d.啟動服務
/etc/init.d/puppetmaster restart
第一次啟動時會創建所需文件,包括證書文件等
3:slave端配置
a.復制文件
mkdir /etc/puppet
cp conf/auth.conf /etc/puppet
cp conf/namespaceauth.conf /etc/puppet
cp conf/redhat/puppet.conf /etc/puppet
cp conf/redhat/client.init /etc/init.d/puppet
chmod +x /etc/init.d/puppet
chkconfig --add puppet
chkconfig puppet on
b.創建puppet帳號
groupadd puppet
useradd -g puppet puppet
puppetd --mkusers
c.建立puppet目錄
mkdir -p /var/lib/puppet/rrd
chown puppet.puppet /var/lib/puppet/rrd
d.啟動服務
/etc/init.d/puppet restart
e.向server端發送請求命令
puppetd --test --server server.tech10.com
到這一步時,總是提示err: Could not retrieve catalog from remote server: certificate verify failed,後來在谷歌上找到解決方法。刪除客戶端/var/lib/puppet/ssl目錄下的文件,再次執行正常
f.server端用如下命令接受請求
puppetca -s -a
g.slave端再次發認證請求
puppetd -test -server server.tech10.com
四.puppet的簡單應用
在服務器端的/etc/puppet/manifests下建立site.pp文件,在文件/tmp/andrew.txt內容及權限推送過去
node default {
file {“/tmp/andrew.txt”:
content =》 “hello,My Name is Jone!\n”,
ensure =》 present,
mode =》 644,
owner =》 root,
group =》 root,
}
}
present,意思是會檢查該文件是否存在,如果不存在,就新建該文件
客戶及執行如下
puppetd --test --server server.tech10.com
info: Caching catalog for tech1
info: Applying configuration version ‘1348711982’
--- /tmp/andrew.txt 2012-09-27 10:11:18.000000000 +0800
+++ /tmp/puppet-file.10084.0 2012-09-27 10:13:03.000000000 +0800
@@ -1 +1,2 @@
-hello,My Name is Jone!\n
\ No newline at end of file
+hello,My Name is Jone!
+hello
\ No newline at end of file
info: FileBucket adding /tmp/andrew.txt as {md5}0578dc72120af9d1ff2ccc6261516d6e
info: /Stage[main]//Node[default]/File[/tmp/andrew.txt]: Filebucketed /tmp/andrew.txt to puppet with sum 0578dc72120af9d1ff2ccc6261516d6e
notice: /Stage[main]//Node[default]/File[/tmp/andrew.txt]/content: content changed ‘{md5}0578dc72120af9d1ff2ccc6261516d6e’ to ‘{md5}23d258c42f96b5af34aae4c959995798’
notice: Finished catalog run in 0.09 seconds
這是已存在的,在原有基礎上發生了改動。
修改完site.pp文件,要執行/etc/init.d/puppetmaster重啟服務。
上面就是CentOS 5.5安裝配置Puppet的方法介紹了,本文詳細介紹了Puppet的配置,Puppet在安裝完後記得進行相關配置,避免不需要的麻煩。