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

[经验分享] Suse 11 sp1下puppet安装配置文档

[复制链接]

尚未签到

发表于 2018-8-3 06:20:07 | 显示全部楼层 |阅读模式
  Suse 11 sp1下puppet安装配置文档
  目录
  Suse 11 sp1下puppet安装配置文档 ...................................................................... 1
  puppet简介............................................................................................................. 1
  1、运行环境和软件 ............................................................................................ 3
  2、Puppet安装 .................................................................................................. 3
  3、Puppet相关配置 ........................................................................................... 4
  4、puppet通信 .................................................................................................. 6
  5、puppet测试 .................................................................................................. 7
  file资源 ............................................................................................................. 7
  exec资源 ......................................................................................................... 10
  Service资源...................................................................................................... 11
  Package资源 .................................................................................................... 12
  puppet简介
  puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。
  puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置服务器. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息.
  puppet是一个为实现数据中心自动化管理而设计的配置管理软件。基于c/s架构。puppet的服务器端保存着所有的对客户端服务器的配置代码,在puppet里面叫做manifest. 客户端下载manifest之后,可以根据manifest对服务器进行配置,例如软件包管理,用户管理和文件管理等等
  puppet的工作流程如下:
  1. 客户端puppetd调用facter,facter探测出主机的一些变量,例如主机名,内存大小,ip地址等。pupppetd 把这些信息通过ssl连接发送到服务器端;
  2. 服务器端的puppetmaster 检测客户端的主机名,然后找到manifest里面对应的node配置,并对该部分内容进行解析,facter送过来的信息可以作为变量处理,node牵涉到的代码才解析,其他没牵涉的代码不解析。解析分为几个阶段,语法检查,如果语法错误就报错。如果语法没错,就继续解析,解析的结果生成一个中间的“伪代码”,然后把伪代码发给客户端;
  3. 客户端接收到“伪代码”,并且执行,客户端把执行结果发送给服务器;
  4. 服务器端把客户端的执行结果写入日志。
  puppet工作过程中有两点值得注意,第一,为了保证安全,client和master之间是基于ssl和证书的,只有经master证书认证的 client可以与master通信;第二,puppet会让系统保持在你所期望的某种状态并一直维持下去,如检测某个文件并保证其一直存在,保证ssh 服务始终开启,如果文件被删除了或者ssh服务被关闭了,puppet下次执行时(默认30分钟),会重新创建该文件或者启动ssh服务。
  Puppet是Puppet Labs 基于ruby语言开发的自动化系统配置工具,可以以C/S 模式或独立模式运行,支持对所有 UNIX 及类 UNIX 系统的配置管理,最新版本也开始支持对 Windows 操作系统有限的一些管理。Puppet 适用于服务器管理的整个过程,比如初始安装、配置、更新以及系统下线。
  典型的 Puppet 架构为星型结构,Clients默认每30分钟请求一次Server 端,确认是否有新的变更操作指令,puppet 支持以节点的方式管理若干的服务器群组.常见的架构图如下
  1、运行环境和软件
  运行环境:SLES-11-SP2 -x86_64
  server软件:puppet-2.7.12.tar.gz
  facter-1.6.6.tar.gz
  以下安装采用两台服务器,一台是 server.puppet.com 用来安装 puppet-server 服务;一台是 agent1.pupet.com 用来安装 puppet 客户端。
  Puppet 要求所有机器有完整的域名(FQDN),修改双方的/etc/hosts文件,添加各自的IP地址对应的主机名,生产环境做内部DNS比较好,不用修改每台服务器的hosts文件。
  Server 主机名修改
  server:~ # echo "server.puppet.com" >>/etc/HOSTNAME
  dns服务器添加A记录  server.puppet.com  172.16.0.1
  Client1 主机名修改
  agent1:/tmp # echo "agent1.puppet.com">>/etc/HOSTNAME
  在dns服务器添加A记录  agent1.puppet.com  172.16.0.2
  2、Puppet安装
  Server安装
  首先在client做ssh密钥认证打通通道(必须步骤)
  agent1:~ # ssh-keygen -t dsa -N ''(生成密钥)
  agent1:~ # cat ~/.ssh/id_dsa.pub | ssh root@172.16.0.1 "cat - >> ~/.ssh/authorized_keys2"(上传密钥)
  安装依赖 puppet是基于ruby高级语言编写
  #zyyper se ruby (查看ruby是否已经安装)
  #zypper install ruby (安装ruby包)
  安装 puppet-2.7.9.tar.gz
  server:/opt/huawei/xen #zyyper
  server:/opt/huawei/xen # tar zxvf puppet-2.7.9.tar.gz
  server:/opt/huawei/xen # cd puppet-2.7.9
  server:/opt/huawei/xen/puppet-2.7.9 # ./install.rb
  安装facter-1.6.4.tar.gz
  # tar xf facter-1.6.6.tar.gz
  # cd facter-1.6.6
  # ruby install.rb
  3、Puppet相关配置
  a、Server端
  从解开的tar包中拷取相应的配置文件: [root@server puppet-2.7.12]# cp conf/suse/fileserver.conf /etc/puppet/
  [root@server puppet-2.7.12]# cp conf/suse/puppet.conf /etc/puppet/
  [root@server puppet-2.7.12]# cp conf/suse/server.init /etc/init.d/puppetmaster
  [root@server puppet-2.7.12]# chmod 755 /etc/init.d/puppetmaster
  [root@server puppet-2.7.12]# chkconfig --add puppetmaster
  [root@server puppet-2.7.12]# chkconfig puppetmaster on
  [root@server puppet-2.7.12]# mkdir /etc/puppet/manifests
  生成puppet账户
  [root@server puppet-2.7.12]# puppetmasterd --mkusers
  启动: # /etc/init.d/puppetmaster start
  b、Client端
  从解开的源码包拷取相关配置文件: [root@client puppet-2.7.12]# cp conf/namespaceauth.conf /etc/puppet/
  [root@client puppet-2.7.12]# cp conf/suse/puppet.conf /etc/puppet/
  [root@client puppet-2.7.12]# cp conf/suse/client.init /etc/init.d/puppet
  [root@client puppet-2.7.12]# chmod +x /etc/init.d/puppet
  修改相关配置文件: [root@client puppet-2.7.12]# vi /etc/puppet/puppet.conf
  #修改内容如下
  [agent]
  listen = true
  server = server //服务器端主机名
  [root@client puppet-2.7.12]# vi /etc/puppet/namespaceauth.conf
  #修改内容如下
  [fileserver]
  allow *
  [puppetmaster]
  allow *
  [puppetrunner]
  allow *
  [puppetbucket]
  allow *
  [puppetreports]
  allow *
  [resource]
  allow *
  [root@client puppet-2.7.12]#
  生成puppet账户:
  [root@client puppet-2.7.12]# puppetmasterd --mkusers
  [root@client puppet]# rm -rf /var/lib/puppet/ssl/*
  //删除客户端/var/lib/puppet/ssl目录下的文件,否则可能会报错
  4、puppet通信
  Client [root@client puppet-2.7.12]# puppetd --test --server server .puppet.com//客户端向server端发送请求
  //Puppet 客户端使用 HTTPS 和服务端(master)通信,为了和服务器端通信必须有合法的 SSL认证,第一次运行puppet 客户端的时候会生成一个SSL 证书并指定发给 Puppet 服务端。
  info: Creating a new SSL key for client.puppet.com
  warning: peer certificate won't be verified in this SSL session
  warning: peer certificate won't be verified in this SSL session
  info: Creating a new SSL certificate request for client.puppet.com
  info: Certificate Request fingerprint (md5): 62:CD:A6:63:A7:8C:89:54:68:AF:95:12:59:16:D7:08
  warning: peer certificate won't be verified in this SSL session
  warning: peer certificate won't be verified in this SSL session
  warning: peer certificate won't be verified in this SSL session
  Exiting; no certificate found and waitforcert is disabled
  [root@client puppet-2.7.12]#
  Server [root@server ~]# puppetca –list //Server端查看请求的主机
  agent1.server.com (05:BF:3C:9E:D8:72:13:24:1D:3F:4C:15:00:E7:FC:25)
  [root@server ~]# puppetca -s –a //发送接受请求
  // puppet 服务端接受到客户端的证书后必须签字(sign)才能允许客户端接入
  //puppetca –s –a //对所有客户端全部签名
  //puppetca –s client.puppet.com //只签名某个客户端
  notice: Signed certificate request for client.puppet.com
  notice: Removing file Puppet::SSL::CertificateRequest client.puppet.com at '/var/lib/puppet/ssl/ca/requests/client.puppet.com.pem'
  [root@server ~]# puppet cert list --all
  //使用puppet cert list --all 命令可以查看客户端已经加入
  + agent1.puppet.com (E5:3B:BC:F5:DD:47:F2:07:75:52:FA:85:67:F5:38:EE)
  client再次发送请求
  puppetd --test --server server.puppet.com
  [root@client puppet]# puppetd --test --server server.puppet.com
  notice: Ignoring --listen on onetime run
  info: Caching catalog for client.puppet.com
  info: Applying configuration version '1332988321'
  info: Creating state file /var/lib/puppet/state/state.yaml
  notice: Finished catalog run in 0.25 seconds
  完成以上之后server和client就可以正常通信了
  常见错误和解决方法:
  1、
  notice: Ignoring --listen on onetime run
  notice: Run of Puppet configuration client already in progress; skipping
  解决方法:a.可以通过ps –e|grep puppet是否有puppet进程在运行。如果有,则停掉puppet,再运行,即可。
  b、没有进程,那有可能puppetdlock存在,则删除之,使用rm -rf /var/puppet/state/puppetdlock
  2、
  warning: peer certificate won't be verified in this SSL session
  warning: peer certificate won't be verified in this SSL session
  warning: peer certificate won't be verified in this SSL session
  Exiting; no certificate found and waitforcert is disabled
  解决方法:mv /var/lib/puppet/ /tmp/
  3、
  err: Could not retrieve catalog from remote server: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed. This is often because the time is out of sync on the server or client
  warning: Not using cache on failed catalog
  err: Could not retrieve catalog; skipping run
  err: Could not send report: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed. This is often because the time is out of sync on the server or client
  解决方法: 务必保持两台主机时间同步
  5、puppet测试
  file资源
  file资源在puppet里面用的挺多,属性包括大家已经属性的owner,group,mode,content等等。file还有两个重要的命令,source和template。通常,一个文件的内容可以由content属性来包含固定的内容,但是也可以用source命令来从其他url复制文件内容。目前puppet只支持puppet这个url,表示从puppet的fileserver去下载文件内容
  Hello World测试
  这个例子作用很简单,用来在客户端的 /tmp 目录下新建一个helloworld.txt 文件 [root@server ~]# vi /etc/puppet/manifests/site.pp
  [root@server ~]# cat /etc/puppet/manifests/site.pp
  在node里面添加如下内容
  node default {
  # This is where you can declare classes for all nodes.
  # Example:
  #   class { 'my_class': }
  file {
  "/tmp/helloworld.txt":
  content => "hello, world\n";
  }
  }
  file {
  "/tmp/agent1.txt":
  content => "agent1.puppet.com\n";
  }
  puppet如何区分不同的客户端,并且给不同的服务端分配manifest呢?puppet使用叫做node的语法来做这个事情,node后面跟客户端的主机名,这里使用的是默认值。file是指定资源的类型是"file"类型,"/tmp/helloworld.txt "是资源的title,title的作用是让puppet能唯唯一标识这个资源。
  在客户端上执行puppet,运行成功后会在/tmp看到新生成的helloworld.txt
  [root@client puppet]# puppetd --test --server  server.puppet.com
  notice: Ignoring --listen on onetime run
  info: Caching catalog for agent1.puppet.com
  info: Applying configuration version '1332991088'
  notice: /Stage[main]//Node[default]/File[/tmp/helloworld.txt]/ensure: defined content as '{md5}e4d7f1b4ed2e42d15898f4b27b019da4'
  notice: Finished catalog run in 0.35 seconds
  [root@client puppet]# cat /tmp/helloworld.txt
  hello, world
  文件分发测试
  Server [root@server ~]# grep -v '^#' /etc/puppet/fileserver.conf
  [files]
  path /tmp/
  allow *.puppet.com
  [root@server ~]# touch /tmp/hello
  [root@server ~]# cat /etc/puppet/manifests/site.pp
  file {
  "/tmp/hello":
  source => "puppet://server.puppet.com/files/hello ";
  }
  Client [root@client ~]# rm -rf /tmp/hello*
  agent1:/tmp # puppetd --test --server server.puppet.com
  notice: Ignoring --listen on onetime run
  info: Caching catalog for agent1.puppet.com
  info: Applying configuration version '1368599836'
  notice: /Stage[main]//File[/tmp/hello]/ensure: defined content as '{md5}d41d8cd98f00b204e980
  notice: Finished catalog run in 0.08 seconds
  agent1:/tmp # ls hello
  hello
  修改文件权限
  Server [root@server ~]# cat /etc/puppet/manifests/site.pp
  file {
  "/tmp/hello":
  source => "puppet://server.puppet.com/files/hello ",
  group => puppet,
  owner => puppet,
  mode => 600
  }
  Client
  agent1:/tmp # rm -rf /tmp/hello*
  agent1:/tmp # puppetd --test --server server.puppet.com
  notice: Ignoring --listen on onetime run
  info: Caching catalog for agent1.puppet.com
  info: Applying configuration version '1368599836'
  notice: /Stage[main]//File[/tmp/hello]/ensure: defined content as '{md5}d41d8cd98f00b204e980
  notice: Finished catalog run in 0.08 seconds
  agent1:/tmp # ll hello
  -rw------- 1 puppet puppet 0 05-15 14:37 hello
  exec资源
  执行shell命令或者shell脚本
  exec资源就是在执行puppet的时候,调用shell执行一条shell语句,或者执行一个脚本
  执行shell脚本
  Server [root@server ~]# vi /tmp/test.sh
  [root@server ~]# cat /tmp/test.sh
  #!/bin/bash
  touch /root/puppet
  [root@server ~]# cat /etc/puppet/manifests/site.pp
  node "client.puppet.com" {
  file { "/tmp/test.sh":
  source => "puppet://server.puppet.com/files/test.sh",
  notify => Exec["exec-touch"];
  }
  exec { "exec-touch":
  cwd => "/tmp/",
  command => "sh /tmp/test.sh",
  user => "root",
  path => "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin";
  }
  }

运维网声明 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-545542-1-1.html 上篇帖子: puppet学习(二:简单模块配置和应用) 下篇帖子: Puppet 3.0资源介绍
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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