6. 第1章 puppet简介 6
Hello world
file {
/tmp/ t e s t :
content= h e l l o n ,
mode = 0644;
}
package {
[ gcc , make ] :
ensure = i n s t a l l e d ;
}
再次提醒:不同的资源有不同的属性,但是又有一些属性是所
有资源都共有的,例如tag,这种属性叫做元属性。
6
7. 第2章 puppet安装
1
debian 系发行版安装puppet
2
apt−get i n s t a l l puppet puppetmaster
redhat 系发行版安装puppet
rpm −Uvh http : / / download . fedora . redhat . com/pub/ epel /5/ i386 / epel
−release −5−3.noarch . rpm
yum i n s t a l l puppet
1
2
7
8. 第2章 puppet安装 8
源代码安装puppet
base64
cgi
digest /md5
etc
fileutils
ipaddr
openssl
strscan
syslog
uri
webrick
webrick / https
xmlrpc
t a r z x f f a c t e r − 1 . 5 . 7 . t a r . gz
cd f a c t e r −1.5.7
ruby i n s t a l l . rb
t a r z x f puppet − 0 . 2 5 . 4 . t a r . gz
cd puppet −0.25.4
ruby i n s t a l l . rb
配置c/s模式的puppet试验环境
8
9. 第2章 puppet安装 9
apt−get i n s t a l l puppet
apt−get i n s t a l l puppetmaster
echo 192.168.0.10 ␣ s e r v e r . puppet . com /etc / hosts
注意:要在安装软件以前先设置主机名,因为生成证书的时候
要把主机名写入证书,如果证书生成好了再改主机名,就连不上,这是很多初学者遇到
的问题。
puppetd −−t e s t −−s e r v e r s e r v e r . puppet . com
pupetca −− l i s t
pupetca −s −a
node d e f a u l t {
f i l e { /tmp/temp1 . t x t :
content = h e l l o ; }
}
pupetd −−t e s t −−s e r v e r s e r v e r . puppet . com
9
11. 第3章 puppet语法
资源
file {
/ etc /passwd :
name = / etc / passd ,
owner = root ,
group = root ,
mode = 644;
}
file {
sshdconfig :
name = $operatingsystem ? {
s o l a r i s = / usr / l o c a l / etc / ssh / sshd_config ,
d e f a u l t = / etc / ssh / sshd_config ,
},
owner = root ,
11
12. 第3章 puppet语法 12
group = root ,
mode = 644 ,
}
s e r v i c e { sshd :
subscribe = F i l e [ sshdconfig ] ,
}
file {
[ / etc /passwd , / etc / hosts ] :
owner = root ,
group = root ,
mode = 644;
}
F i l e { owner = root , mode = 644 ; }
file {
/ etc / apache2 / port . conf :
content = 80 ,
require = Package [ apache2 ] ;
}
package {
apache2 :
12
13. 第3章 puppet语法 13
ensure = i n s t a l l e d ;
}
类和函数
c l a s s ssh {
file {
/ etc / ssh / sshd_config :
source = puppet : / / $ f i l e s e r v e r / ssh / sshd_config
. cfg ;
}
package {
ssh :
ensure = i n s t a l l e d ;
}
service {
ssh :
ensure = running ;
}
}
13
14. 第3章 puppet语法 14
define svn_repo ( $path ) {
exec {
/ usr / bin / svnadmin␣ create ␣$path / $ t i t l e :
unless = / bin / t e s t ␣−d␣$path ,
}
}
svn_repo {
puppet_repo :
path = / var / svn_puppet }
svn_repo {
other_repo :
path = / var / svn_other }
1
2
节点
3
node ' host1 . example . com ' {
include ssh
}
node ' host2 . example . com ' {
include apache , mysql , php
}
1
2
3
14
15. 第3章 puppet语法 15
node ' host4 . example . com ' {
$networktype= t e l e
$nagioscheckport= 80 ,22 ,3306
include ssh , apache , mysql
}
变量和数组
$ t e s t= hello , guys
file {
/tmp/ t e s t :
content = $ t e s t ;
}
[ apache2 , httpd , ssh ]
define php : : pear ( ) {
package { `php−$ {name} : ensure = i n s t a l l e d }
}
php : : pear { [ ' ldap ' , ' mysql ' , ' ps ' , 'snmp ' , ' s q l i t e ' , ' t i d y ' , '
xmlrpc ' ] : }
15
22. 第5章 puppet高级内容 22
后记
huangmingyou
houqp
frostynova
aaniao999
kuuyee
edison7500
min xu
270175100
douzl
Daniel Ho
unline
wtoppp
xw2014
chifeng
dywer
L i u Nan
22