SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
puppet 入门
2
puppet简介                      5
   puppet是什么                  5
   Hello world                6

puppet安装                      7
   debian 系发行版安装puppet        7
   redhat 系发行版安装puppet        7
   源代码安装puppet                8
   配置c/s模式的puppet试验环境         8

puppet语法                     11
   资源                        11
   类和函数                      13
   节点                        14
   变量和数组                     15
   模块                        16

几个常用的资源                      17
   file资源                    17
   package资源                 18
   service资源                 18
   exec资源                    19

puppet高级内容                   21




                         3
第0章   4

     前言




              4
第1章        puppet简介




                                     1




    puppet是什么
     2




           Figure 1.1: puppet structure
1
2



                        5
第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
第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
第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
第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
第2章 puppet安装   10




               10
第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
第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
第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
第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
第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
第3章 puppet语法   16


模块




                    16
第4章              几个常用的资源




        file资源




source =  puppet : / / $ { f i l e s e r v e r } / l v s /$ { corp } . $ { idc } . keepalived
    . conf 




                                              17
第4章 几个常用的资源   18


file {
              / etc / squid / squid . conf  :
             mode = 0644 ,
             content = template (  squid / squid . conf . erb  ) ;
}


                                                              1


cache_mem %= Integer ( vmx_memsize . t o _ i * 0 . 4 5 ) −% MB
                                                            
visible_hostname %= fqdn %




            package资源




package {
        [ vim  ,  iproute  ,  x−window−system  ] :
        ensure = i n s t a l l e d ;
        [ pppoe , pppoe−conf  ] :
        ensure = absent ;
        }




            service资源


service {
              ssh  :
             ensure = running ;
              nfs  :
             ensure = stoped ;
    1



                                                                         18
第4章 几个常用的资源   19


}




     exec资源



exec {
          delete ␣ config  :
         path =  / bin : / usr / bin  ,
         command = rm␣ / etc / ssh / ssh_config  ;
}




                                                               19
第4章 几个常用的资源   20




              20
第5章   puppet高级内容




        21
第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

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (10)

Perou
PerouPerou
Perou
 
Bengvarna 5 september 2010
Bengvarna 5 september 2010Bengvarna 5 september 2010
Bengvarna 5 september 2010
 
Tormentas
TormentasTormentas
Tormentas
 
Molecular Biology - Leishmaniasis
Molecular Biology - LeishmaniasisMolecular Biology - Leishmaniasis
Molecular Biology - Leishmaniasis
 
12 preguntas
12 preguntas12 preguntas
12 preguntas
 
Grupo de trabajo Headhunters. Alberto Herranz, Gerente ANCOPORC
Grupo de trabajo Headhunters.  Alberto Herranz, Gerente ANCOPORCGrupo de trabajo Headhunters.  Alberto Herranz, Gerente ANCOPORC
Grupo de trabajo Headhunters. Alberto Herranz, Gerente ANCOPORC
 
Modelo de Formación en línea Comunidad de Madrid
Modelo de Formación en línea Comunidad de MadridModelo de Formación en línea Comunidad de Madrid
Modelo de Formación en línea Comunidad de Madrid
 
Anboto 348
Anboto 348Anboto 348
Anboto 348
 
Unidad 3 Parte 1
Unidad 3 Parte 1Unidad 3 Parte 1
Unidad 3 Parte 1
 
Aan dipecho5 ward 5 trijuga
Aan dipecho5 ward 5 trijugaAan dipecho5 ward 5 trijuga
Aan dipecho5 ward 5 trijuga
 

Puppet入门

  • 2. 2
  • 3. puppet简介 5 puppet是什么 5 Hello world 6 puppet安装 7 debian 系发行版安装puppet 7 redhat 系发行版安装puppet 7 源代码安装puppet 8 配置c/s模式的puppet试验环境 8 puppet语法 11 资源 11 类和函数 13 节点 14 变量和数组 15 模块 16 几个常用的资源 17 file资源 17 package资源 18 service资源 18 exec资源 19 puppet高级内容 21 3
  • 4. 第0章 4 前言 4
  • 5. 第1章 puppet简介 1 puppet是什么 2 Figure 1.1: puppet structure 1 2 5
  • 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
  • 16. 第3章 puppet语法 16 模块 16
  • 17. 第4章 几个常用的资源 file资源 source = puppet : / / $ { f i l e s e r v e r } / l v s /$ { corp } . $ { idc } . keepalived . conf 17
  • 18. 第4章 几个常用的资源 18 file { / etc / squid / squid . conf : mode = 0644 , content = template ( squid / squid . conf . erb ) ; } 1 cache_mem %= Integer ( vmx_memsize . t o _ i * 0 . 4 5 ) −% MB visible_hostname %= fqdn % package资源 package { [ vim , iproute , x−window−system ] : ensure = i n s t a l l e d ; [ pppoe , pppoe−conf ] : ensure = absent ; } service资源 service { ssh : ensure = running ; nfs : ensure = stoped ; 1 18
  • 19. 第4章 几个常用的资源 19 } exec资源 exec { delete ␣ config : path = / bin : / usr / bin , command = rm␣ / etc / ssh / ssh_config ; } 19
  • 21. 第5章 puppet高级内容 21
  • 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