290112011 发表于 2018-8-2 06:26:35

puppet ENC 配置说明

  节点分类(node>

  生成catalog的第一步是必须找到agent节点的配置里使用了哪些class和resource。这个过程称为节点分类(node>  默认的方式使用site.pp中的静态配置,其默认路径是/etc/puppet/manifests/. 如果environment被设置了,请查看enviornment相关设置来确定site.pp位置
node 'web01' , 'web02' , 'web03' {   #节点名称,可以是一个或者多个名字,也可以是表达式,比如 node /^www\d+$/ { ... }  include apache                           #节点中声明的class
  }
  另一种方式是使用ENC(External Node>PuppetDashBoard, The Foreman and PuppetEnterprise。同时,它会提供一个程序。master可以调用这个程序并输入节点FQDN名作为参数,然后这个程序会返回一个YAML格式的文件,其中包含节点需要使用的class和resource。这个程序可以是由任何语言编写。
  使用这个功能,需要在master的puppet.conf里进行配置
  node_terminus = exec                                        #使用ENC
  external_nodes = /etc/puppet/node.rb               #外部程序路径。
  Puppet master接收到一个node的请求的时候,如果 node_terminus 配置为exec,将输出node的fqdn给external_nodes
  Puppet 有两种将节点信息存储在外部的方法:
  1.使用外部节点分类器 (ENC)
  2.使用LDAP服务器分类
  主要学习使用ENC(外部节点分类器)。ENC是一种提供Puppet 查询节点数据的基于脚本(SHELL、RUBY、PERL等)集成系统,这个脚本返回类、继承、变量和环境设置,Puppet可用来定义一个节点和配置主机。
  LDAP:是允许你查询LDAP(轻型目录访问协议)的目录来获取节点的信息。这种集成方式用得没有ENC那么多。列如你的资产管理数据库或者一个LDAP的DNS后端来提供节点数据
  使用外部节点,无论是通过ENC还是LDAP,都是在大规模主机中扩展Puppet实现的推荐方式。
  使用ENC的根本原因之一是在于我们的nodes全部定义在/etc/puppet/manifests/site.pp文件中,如果我们有太多的nodes的话,会使site.pp文件变得很大!
  一般的操作都是在/etc/puppet/manifests/ 目录下根据每个node的定义不同,建立多个nodes文件,之后在site.pp中import所有的nodes定义文件
  Import ‘nodes*.pp’
  这样就包含了所有的node,但是随着你node的增多,你需要手工管理太多的文件
  要使用ENC,首先需要更改master的配置文件:
  cd /etc/puppet/
  # vi puppet.conf
  ######文件最后面追加##
  
  node_terminus = exec
  external_nodes = /etc/puppet/puppet_node_classifer.pl
  需要重启puppetmaster 服务
  # service puppetmaster restart
  停止 puppetmaster:                                        [确定]
  启动 puppetmaster:                                        [确定]
  修改这个配置设置,就是说:
  1. Puppet master接收到一个node的请求的时候,如果 node_terminus 配置为exec,将输出node的fqdn给external_nodes
  2.external_nodes接收到agent的主机名,并将主机名传递给/etc/puppet/puppet_node_classifer.pl
  脚本的配置:
  # cat puppet_node_classifer.pl
  #!/usr/bin/perl -w
  use strict;
  use YAML qw(Dump);
  my $hostname = shift || die "NO hostname passed";
  $hostname =~ /^([\w-]+)\_vm(\d?)/i or die "Invalid hostname :$hostname";
  my @classes = ('rsync','rsync_svn_up');
  my %parameters = (
  puppetserver => "MOBIM-KVM"
  );
  print Dump({
  classes => \@classes,
  parameters => \%parameters,
  });
  # perl puppet_node_classifer.plmobim_vm1
  ---
  classes:
  - rsync
  - rsync_svn_up
  parameters:
  puppetserver: MOBIM-KVM
  这个是一个YAML的格式,相当于
  Node   mobim_vm1 {
  Include rsync
  Include rsync_svn_up
  }
  Rsync rsync_svn_up 是定义的类
  以上的配置文件的修改和脚本都是在master上进行的,在client上请求master进行数据同步
  # puppet agent --server=MOBIM-KVM --test -v
  info: Caching catalog for mobim_vm1
  info: Applying configuration version '1394015854'
  notice: /Stage/Rsync_svn_up/File/ensure: defined content as '{md5}4221d002ceb5d3c9e9137e495ceaa647'
  info: /Stage/Rsync_svn_up/File: Scheduling refresh of Exec
  notice: /Stage/Rsync_svn_up/Exec: Triggered 'refresh' from 1 events
  notice: Finished catalog run in 0.60 second
  OK,一切正常的,这个是简单的ENC的应用实例,
  ERROR

  err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find>  warning: Not using cache on failed catalog
  err: Could not retrieve catalog; skipping run
  配置好ENC时,有遇到上面的ERROR信息,提示我在master上找不到node SSL证书
  解决办法:
  给脚本附加可执行的权限
  Chmod -R 775 /etc/puppet/puppet_node_classifer.pl
  参考:
  http://www.178linux.com/17052
  http://caibird.blog.51cto.com/1403570/1368153
页: [1]
查看完整版本: puppet ENC 配置说明