设为首页 收藏本站
查看: 1071|回复: 0

[经验分享] puppet 源码安装

[复制链接]

尚未签到

发表于 2015-9-16 10:44:25 | 显示全部楼层 |阅读模式
puppet 源码安装


作者: admin 分类: 自动化管理 发布时间: 2013-04-23 10:25 ė 1932次浏览 6 暂无评论

  puppet最新源码详细安装:
  在网上找了很多相关puppet的,有很多用yum安装,安装虽然成功了。但是有客户端相关过来请求,还是会有问题。最佳的还是源码安装。
  一、下载地址:
  puppet下载地址:
  http://downloads.puppetlabs.com/puppet/puppet-2.7.13.tar.gz
  facter下载地址:
  http://downloads.puppetlabs.com/facter/facter-1.6.7.tar.gz
  ruby下载地址:
  http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.gz
  二、环境准备:
  1、时间必须一致:
  crontab -e
  


  • */2  *    *    *    *   /usr/sbin/ntpdate clock.nc.fukuoka-u.ac.jp >/dev/null 2>&1
  2、首先gcc相关可用yum安装
  yum install gcc-c++
  yum install openssl*
  3、服务器及客户端名字:


  • [iyunv@server bin]# more /etc/hosts
  • # Do not remove the following line, or various programs
  • # that require network functionality will fail.
  • #127.0.0.1              localhost.localdomain localhost
  • ::1             localhost6.localdomain6 localhost6
  • 192.168.1.231      server.cbcv.net        server
  • 192.168.1.232      client.cbcv.net        client
  • [iyunv@server bin]# more /etc/sysconfig/network
  • NETWORKING=yes
  • NETWORKING_IPV6=no
  • HOSTNAME=server.cbcv.net
  <客户端也是类似一样,略……>
三、安装应用软件
1、首先安装ruby
tar -zxvf ruby-1.8.7.tar.gz
cd ruby-1.8.7
./configure –prefix=/usr/local/ruby
make
make install
操作系统PATH路径:
  vi  /etc/profile
export PATH=/usr/local/ruby/bin:$PATH
  查看ruby –version版本
  2、安装facter
tar -zxvf facter-1.6.7.tar.gz
cd facter-1.6.7
ruby install.rb
  3、安装puppet


  • tar -zxvf puppet-2.7.9.tar.gz


  • cd puppet-2.7.9/
  • ruby install.rb
  • [iyunv@server puppet-2.7.2rc2]# cp conf/redhat/fileserver.conf /etc/puppet/
  • [iyunv@server puppet-2.7.9]# cp conf/auth.conf /etc/puppet/
  • [iyunv@server puppet-2.7.9]# cp conf/namespaceauth.conf /etc/puppet/
  • [iyunv@server puppet-2.7.9]# cp conf/redhat/puppet.conf /etc/puppet/
  • [iyunv@server puppet-2.7.9]# cp conf/redhat/server.init /etc/init.d/puppetmaster
  • [iyunv@server puppet-2.7.9]# chmod +x /etc/init.d/puppetmaster
  • [iyunv@server puppet-2.7.9]# /etc/init.d/puppetmaster start
  • Starting puppetmaster: /bin/bash: /usr/sbin/puppetmasterd: No such file or directory
  •                                                            [FAILED]


  • [iyunv@server puppet-2.7.9]# cp sbin/puppetmasterd /usr/sbin/
  • [iyunv@server puppet-2.7.9]# chmod -R 777 /usr/sbin/puppetmasterd
  • [iyunv@server puppet-2.7.9]# cp sbin/puppetmasterd /bin/puppetmasterd
  • [iyunv@server puppet-2.7.9]# chmod -R 777 /bin/puppetmasterd
  • [iyunv@server puppet-2.7.9]# /etc/init.d/puppetmaster start
  • Starting puppetmaster: /usr/bin/env: ruby: No such file or directory
  •                                                            [FAILED]
  • [iyunv@server puppet-2.7.9]# ln -s /usr/local/ruby/bin/
  • erb         filebucket  pi          puppetdoc   rdoc        ruby
  • facter      irb         puppet      ralsh       ri          testrb
  • [iyunv@server puppet-2.7.9]# ln -s /usr/local/ruby/bin/ruby /usr/bin/
  • [iyunv@server puppet-2.7.9]# /etc/init.d/puppetmaster start
  • Starting puppetmaster: Could not prepare for execution: Got 6 failure(s) while initializing: change from absent to directory failed: Could not set ‘directory on ensure: Could not find group puppet; change from absent to directory failed: Could not set ‘directory on ensure: Could not find group puppet; change from absent to directory failed: Could not set ‘directory on ensure: Could not find group puppet; change from absent to directory failed: Could not set ‘directory on ensure: Could not find group puppet; change from absent to directory failed: Could not set ‘directory on ensure: Could not find group puppet; change from absent to directory failed: Could not set ‘directory on ensure: Could not find group puppet
  •                                                            [FAILED]
  • [iyunv@server puppet-2.7.9]# useradd puppet
  • [iyunv@server puppet-2.7.9]# /etc/init.d/puppetmaster start
  • Starting puppetmaster:                                     [  OK  ]


  • [iyunv@server sbin]# pwd
  • /usr/local/src/puppet-2.7.9/sbin
  • cp -r * /usr/sbin/




  • [iyunv@server manifests]# chkconfig –add puppetmaster
  • [iyunv@server manifests]# chkconfig puppetmaster on
  客户端其它安装和服务器安装相同,除了用cp conf/redhat/client.init /etc/init.d/puppet


  • tar -zxvf puppet-2.7.9.tar.gz


  • cd puppet-2.7.9/
  • ruby install.rb


  • [iyunv@localhost puppet-2.7.9]# cp conf/auth.conf /etc/puppet/
  • [iyunv@localhost puppet-2.7.9]# cp conf/namespaceauth.conf /etc/puppet/
  • [iyunv@localhost puppet-2.7.9]# cp conf/redhat/puppet.conf /etc/puppet/
  • [iyunv@localhost puppet-2.7.9]# cp conf/redhat/client.init /etc/init.d/puppet
  • [iyunv@localhost puppet-2.7.9]# chmod +x /etc/init.d/puppet
  • [iyunv@localhost puppet-2.7.9]# service puppet start
  • Starting puppet: /bin/bash: /usr/sbin/puppetd: No such file or directory
  •                                                            [FAILED]
  • [iyunv@localhost puppet-2.7.9]# cp sbin/puppetd /usr/sbin/puppetd
  • [iyunv@localhost puppet-2.7.9]# service puppet start
  • Starting puppet: /usr/bin/env: ruby: No such file or directory
  •                                                            [FAILED]
  • [iyunv@localhost puppet-2.7.9]# chmod +x /usr/sbin/puppetd
  • [iyunv@localhost puppet-2.7.9]# service puppet start
  • Starting puppet: /usr/bin/env: ruby: No such file or directory
  •                                                            [FAILED]
  • [iyunv@localhost puppet-2.7.9]# ln -s /usr/local/ruby/bin/ruby /usr/bin/
  • [iyunv@localhost puppet-2.7.9]# /etc/init.d/puppet start
  • Starting puppet:                                           [  OK  ]
  安装完毕后进行测试:
  在服务器端执行:
puppetca –list
应该是无
在客户端执行 puppetd –server server.cbcv.net  –test
再到服务器端执行:
puppetca –s client.cbcv.net
clinet.cbcv.net (BF:5D:58:D0:F2:06:8C:FB:5C:AA:08:80:87:DC:92:20)
  如果看到了客户端的证书请求,
针对客户端请求为
puppetca –s client.cbcv.net
用下面的命令对所有证书请求签名:
puppetca -s –a
  在主服务器上/etc/puppet/manifests
  vi /etc/puppet/manifests/site.pp
node default{
file { “/tmp/test.txt”:
content=> “hello, Test”;
}
}
  再重启一下服务器service puppetmaster restart 和客户端service puppet restart
再执行puppetd –server server.cbcv.net  –test
看/tmp下面是不是有test.txt文件了
增加多个site.pp
  可以先在site.pp中增加
  import “test.pp”
  然后再在里面执行需要操作的内容。
  可用puppetd –server server.cbcv.net  –test进行测试。
  如果有报错:notice: Ignoring –listen on onetime run
notice: Skipping run of Puppet configuration client; administratively disabled; use ‘puppet Puppet configuration client –enable’ to re-enable.
  那么需要在客户端执行puppet agent –enable即可。
  puppet agent –disable为关闭。
  

记得重启puppetmaster和puppet
以下为参考内容,感觉非常不错:
默认时间vim /etc/puppet/puppet.con
runinterval =1800 ###默认是30分钟,可以修改此处的值,单位为秒
有的时间修改了这个没有用,是什么原因呢:
我也曾修改过多次,没效果,后在客户端的配置文件再加了一句server = server.cbcv.net
然后重启
在客户端修改即可!最好重启一下server puppet restart
puppet 如何全客户端自动签名
a.vim /etc/puppet/puppet.conf
[puppetmaster]
autosign=true      #增加这两行
autosing=/etc/puppet/autosign.conf  
#增加这两行添加
* 表示所有,或者添加域名,IP或者网段。举例:
b.再编辑 /etc/puppet/autosign.conf**.test.com192.168.0.1/24
错误总结<此错误是因为用了yum去安装。看到别人写的OK......>:
第一次认证的时候报下边的错误:
[iyunv@client ~]# puppetd --server server.cbcv.net  --test
err: Could not retrieve catalog from remote server: certificate verify failed
我做测试发现的原因有三种:
第一:是hostname没有设置好,在安装前一定要把hostname设置好,设置好之后尽量重启机器。实在不行就删了重新安装。
第二:时间不同步,时间不同步也会报认证失败的错误,可以用date设置时间,只要不是差得太多就没事。
第三:是ssl的问题,在你用的这个客户端puppet已经做过其他的机器的客户端的情况下,因为已经生成的有证书,可能会和现在的冲突,把/var/lib/puppet/ssl这个文件夹删掉之后就行了。
1.3配置c/s模式的puppet的实验环境
Puppet的的客户端和服务端是靠ssl链接的,在服务端有一个自签名的根证书,在安装软件的时候自动生成。每个客户端的证书要经过根证书签名才能和服务器连接。所以首先要在客户端执行下面的命令来请求服务器签名证书。
puppetd --server server.cbcv.net --test
  
  
  下面是一个完整的例子
  





NOTE:puppet的客户端和服务器通过ssl连接,在服务器端上一个自签名的根证书,在安装软件的时候自动生成.因此在安装软件以前须设置好主机名,生成证书的时候要把主机名写入证书,如果证书生成后再改主机名,会导致无法通信.每个客户端的证书要经过根证书的签名才能和服务器连接.所以要执行以上命令,请求证书=>签发证书
   NOTE:自动签名:创建/etc/puppet/autosign.conf文件,添加*.puppet.com一行。根据实际情况,修改客户机对应的域名.puppet会检查证书请求是否匹配该配置文件的任何一行,客户端端主机如匹配*.puppet.com,puppetmaster都会自动签名。(因只要主机名匹配,master都会信任,此为潜在的安全问题,不建议使用)
  Puppet目录结构(/etc/puppet):



  • |-auth.conf                     #认证配置文件
  • |-puppet.conf                   #主配置文件
  • |-fileserver.conf            #文件服务器配置文件
  • |-autosign.conf              #自动验证配置文件
  • |‘-manifests                    #puppet代码文件存储目录
  •     |‘-nodes                    #节点配置目录
  •          |-node1.pp           #节点1配置文件
  •     |-site.pp                   #入口文件,定义变量,默认配置等
  •     |-modules.pp                #加载模块
  • |‘-modules                      #模块配置目录,其下一个目录相当于一个模块,如mysql
  •     |‘-mysql                    #mysql模块,一般有files,manifests,templates三个子目录
  •          |‘-files             #文件存储目录,如my.cnf
  •               |-my.cnf
  •          |‘-manifests         #模块配置代码所在目录,其下必须有init.pp文件
  •               |-init.pp
  •          |‘-templates         #针对此模块模板目录
  • |‘-templates                    #模板目录
  Puppet的几个常见资源:



(1)文件:管理系统文件

  • file {
  •     “/etc/mysql/my.cnf”:
  •     source => “puppet:///mysql-server/my.cnf”,
  •     owner => root,
  •     group => root,
  •     mode => 0644;
  • }

   NOTE:上面的代码是让/etc/mysql/my.cnf这个文件权限保持644,并且属于root用户root组,第二行为资源的title,默认和文件的名字相同,source是指定文件复制到客户端并覆盖已有的文件,上面代码定义的source代码也可这样写source=>"puppet://$fileserver/mysql-server/my.cnf",此处的mysql-server指的是定义在fileserver.conf中的一个模块所对应的全路径.这里需要知道fileserver.conf的配置:

  • $ vim fileserver.conf    #添加如下行:
  • [mysql-server]
  •   path /etc/puppet/modules/mysql-server/files #指定文件所在的目录
  •   allow *            #可配置allow,deny做限制,支持使用主机名,IP,
  • 及通配符,此处为方便,允许所有主机

   通过fileserver.conf的定义,代码source =>"puppet:///mysql-server/my.cnf"所指定的路径可以解析为/etc/puppet/modules/mysql-server/files/my.cnf,代码source => "puppet:///mysql-server/my.cnf"中的mysql-server可简单理解为等价于/etc/puppet/modules/mysql-server/files
(2)软件包:管理软件包的安装升级和删除。

  • package {
  •       ["nginx","mysql-server"]:
  •       ensure => installed;
  •       ["vim"]:
  •       ensure => absent;
  • }

   NOTE:该资源的主要是ensure,表示该软件包应该在什么状态。installed 表示要安装该软件,也可以写成present; absent表示卸载该软件
(3)服务:管理系统服务(启用,禁用,重启等)

  • service {
  •     “mysql”:
  •     enable => true,
  •     ensure => running;
  •     “nginx”:
  •     ensure => stopped;
  • }

   NOTE:enable表示服务在开机的时候是否启动,可以设置的值是true和false;
        ensure表示是否运行服务, running表示运行服务,stopped 表示停止服务
(4)Exec:执行外部命令

  • exec {
  •     “set mysql root password”:
  •     path => “/usr/bin”,
  •     unless => “mysql -uroot -p$root_mysql_password”,
  •     command => “mysqladmin -u root password $root_mysql_password”;
  • }

   NOTE:path:命令执行的搜索路径。如果path没有被定义,命令需要使用绝对路径。路径可以以数组或以冒号分隔的形式来定义。
        unless:如果unless所设定的命令返回0,此定义的资源将不被执行
        command:将会被执行的命令,必须为被执行命令的绝对路径,或者得提供该命令的搜索路径更多资源介绍请访问puppet官网或者puppet中文维基:http://puppet.wikidot.com/
  
  Puppet资源间的关系:

(1)puppet 资源之间简单依赖关系:
   before:在某个资源之前执行
   after:在某个资源之后执行
   require:某个资源必须存在或者正确执行后,才执行相应的资源。
(2)puppet 资源之间触发更新:
   notify:用来通知某个资源进行更新
   subscribe:该资源有更新时,通知另一个资源执行相应的动作
  
  Puppet类:

作用:把一组资源收集到一个盒子里面,一起使用,其他地方要用到直接包含此个类就可以,便于维护。例:

  • class ssh {
  •         package {
  •                 [ "openssh-server" ]:
  •                 ensure => installed;
  •         }


  •         file {
  •                 “/etc/ssh/sshd_config”:
  •                 mode => 0644,
  •                 owner => root,
  •                 group => root,
  •                 source => “puppet://$fileserver/ssh/sshd_config”,
  •                 require => Package["openssh-server"];  #在指定的Packgae资源执行成功后再执行此File资源
  •         }


  •         service {
  •                 “ssh”:
  •                 ensure => running,
  •                 require => Package["openssh-server"],
  •                 subscribe => File["/etc/ssh/sshd_config"]; #sshd_config文件有变动,重启ssh服务,使其生效
  •         }
  • }
  
  Puppet节点:

puppet用来区分不同的客户端,并且给不同的服务器端分配manifest.例:

  • node ‘host1.puppet.com’ {
  •            include ssh  #此处的ssh指的是定义的ssh类
  • }
  • node ‘host2.puppet.com’ {
  •          include apache,mysql,ssh
  • }
  
  Puppet模块:

  (1):一个模块包含/etc/puppet/modules目录下的一个目录和它的子目录,通常一个模块目录下面含三个目录files,manifests,templates.
  (2):在puppet的主文件site.pp里面可以用import modulename可以插入模块。新版本的puppet可自动插入modules目录下的模板。引入模块,可以结构化代码,便于分享,保存,及管理
  (3):manifests里面必须包含一个init.pp的文件,为此模块的初始文件.
  (4):files目录是该模块的文件发布目录,
  (5):templates包含erb模型文件。
  一个完整示例:

(1)修改主机名,hosts文件,同步时间
(2)服务器端安装好puppet,puppetmaster;客户端安装好puppet
(3)客户端请求签名,服务器端签名
(4)/etc/puppet下代码的配置

  • $ cd /etc/puppet


  • #modules目录配置:
  • $ sudo mkdir -pv modules/mysql-server/{files,manifests,templates} #创建模块目录及其子目录
  • files
  • $ sudo vim my.cnf #此文件配置好,放在files目录下即可


  • $ cd /etc/puppet/modules/mysql-server/manifests/
  • $ sudo vim init.pp  #模块的主配置文件,添加如下行:
  • #mysql-server install and set psaaword
  • #
  • class mysql-server {
  •         package {
  •                 [ "mysql-server","mysql-client" ]:
  •                 ensure => installed;
  •         }
  •         file {
  •                 “/etc/mysql/my.cnf”:
  •                 source => “puppet://$fileserver/mysql-server/my.cnf”,
  •                 owner => root,
  •                 group => root,
  •                 mode => 0644,
  •                 require => Package[ "mysql-server","mysql-client" ];
  •         }
  •         service {
  •                 “mysql”:
  •                 ensure => running,
  •                 require => File[ "/etc/mysql/my.cnf" ],
  •                 subscribe => File[ "/etc/mysql/my.cnf" ];
  •         }
  •         exec {
  •                 “set mysql root password”:
  •                 path => “/usr/bin”,
  •                 unless => “mysql -uroot -p$root_mysql_password”,
  •                 command => “mysqladmin -u root password $root_mysql_password”,
  •                 require => Service['mysql'];
  •         }
  • }


  • #manifests目录下配置:
  • $ cd /etc/puppet/manifests
  • $ sudo vim site.pp  #puppet入口文件配置,添加如下行:
  • $fileserver = “server.puppet.com”  #puppet变量定义,注意$
  • $root_mysql_password = “123456&Prime;
  • node default {
  •         file {
  •                 “/tmp/test1.txt”:
  •                 content => “hello”;
  •         }
  • }
  • import “modules.pp”
  • import “node*.pp”


  • $ sudo vim modules.pp   #导入模块配置,添加如下行:
  • import “mysql-server”


  • $ sudo vim node1.pp  #节点配置文件,添加如下行:
  • node ‘client.puppet.com’ {
  •         include mysql-server
  • }


  • #文件服务器配置:
  • $ cd /etc/puppet
  • $ sudo vim fileserver.conf  #文件服务器配置文件,添加如下:
  • [mysql-server]
  •     path /etc/puppet/modules/mysql-server/files
  •     allow *
  (5)在客户端执行如下命令:mysql就会在客户端下安装(如想让puppet以守护进程运行,去掉–test参数即可,puppetd命令的详细参数请参照:puppetd –help)


  • $ sudo puppetd –test –server server.puppet.com
  至此puppet已配置完毕,此篇内容,主要针对入门级简单应用,更多的puppet的语法,如puppet函数(puppet称之为define),数组,以及puppet的更高级的内容,如和nginx结合puppet做集群等等,本文并未涉及,有兴趣的同学可参考puppet官方文档。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-114366-1-1.html 上篇帖子: puppet使用 apache passsenger 作为前端 (centos) 下篇帖子: Learning Puppet — Resources and the RAL
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表