smith88 发表于 2018-8-2 12:16:38

初始Puppet—Puppet的安装和简单使用

  一、Puppet简介:
  puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。
  puppet 系统架构
  Puppet是开源的基于Ruby的系统配置管理工具,puppet是一个C/S结构, 当然,这里的C可以有很多,因此,也可以说是一个星型结构. 所有的puppet客户端同一个服务器端的puppet通讯. 每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置服务器. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息.
  二、搭建环境介绍:
  服务器:192.168.8.177master.jiu.com
  客户端:192.168.8.165 agent165.jiu.com
  192.168.8.168 agent168.jiu.com
  192.168.8.174 agent174.jiu.com
  192.168.8.176 agent176.jiu.com
  三、安装配置Puppet
  1)安装运行ruby程序所用的软件包。
  #yum install ruby ruby-libs
  # rpm -qa | grep ruby
  ruby-1.8.7.352-13.el6.x86_64
  ruby-libs-1.8.7.352-13.el6.x86_64
  2)创建puppet用户和组.
  # groupadd puppet
  # useradd -g puppet -s /bin/false -M puppet
  3)修改host文件.
  # more /etc/hosts
  127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
  ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  192.168.8.177 master.jiu.com
  192.168.8.165 agent165.jiu.com
  192.168.8.168 agent168.jiu.com
  192.168.8.174 agent174.jiu.com
  192.168.8.176 agent176.jiu.com
  4)解压并执行安装下载的文件包。
  # cd /taokey/tools/
  # tar -zxf facter-1.7.5.tar.gz
  # cd facter-1.7.5
  # ruby install.rb
  # cd ..
  # tar -zxf puppet-2.7.25.tar.gz
  # cd puppet-2.7.25
  # ruby install.rb
  5)拷贝puppet文件到/etc/puppet目录
  # mkdir -p /etc/puppet && cp conf/redhat/* /etc/puppet/
  # cp /etc/puppet/server.init /etc/init.d/puppetmasterd
  6)赋予脚本权限,设置相应的启动项。
  # chmod 755 /etc/init.d/puppetmasterd
  # ll /etc/init.d/puppetmasterd
  -rwxr-xr-x. 1 root root 3936 4月18 15:44 /etc/init.d/puppetmasterd
  # chkconfig --add puppetmasterd
  # chkconfig --level 35 puppetmasterd on
  # chkconfig --list | grep puppetmasterd
  puppetmasterd   0:关闭1:关闭2:关闭3:启用4:关闭5:启用6:关闭
  # /etc/init.d/puppetmasterd restart
  停止 puppetmaster:                                        [确定]
  启动 puppetmaster:                                        [确定]
  # netstat -anpt | grep 8140
  tcp      0      0 0.0.0.0:8140                0.0.0.0:*                   LISTEN      21341/ruby
  2.客户端设置:
  1)修改服务器的主机名。
  # more /etc/sysconfig/network
  NETWORKING=yes
  NETWORKING_IPV6=no
  HOSTNAME=agent165.jiu.com
  GATEWAY=192.168.1.1
  # hostname
  agent165.jiu.com
  2)安装运行ruby程序所用的软件包。
  # yum install -y ruby ruby-libs
  # more /etc/hosts
  # Do not remove the following line, or various programs
  # that require network functionality will fail.
  127.0.0.1               web2 localhost.localdomain localhost
  ::1             localhost6.localdomain6 localhost6
  192.168.8.177 master.jiu.com
  192.168.8.165 agent165.jiu.com
  3)解压并执行安装下载的文件包。
  # cd /taokey/tools/
  # ls
  facter-1.7.5.tar.gzpuppet-2.7.25.tar.gz
  # tar -zxf facter-1.7.5.tar.gz
  # cd facter-1.7.5
  # ruby install.rb
  # cd ..
  # tar -zxf puppet-2.7.25.tar.gz
  # cd puppet-2.7.25
  # ruby install.rb
  4)拷贝puppet文件到/etc/puppet目录
  # mkdir /etc/puppet && cp /etc/puppet/client.init /etc/init.d/puppet
  # chmod 755 /etc/init.d/puppet
  # chkconfig --add puppet
  # chkconfig --level 35 puppet on
  # chkconfig --list | grep puppet
  puppet          0:关闭1:关闭2:关闭3:启用4:关闭5:启用6:关闭
  # /etc/init.d/puppet start
  启动 puppet:                                              [确定]
  # netstat -anpt | grep 8140
  tcp      0      1 192.168.8.165:49494         202.106.199.34:8140         SYN_SENT    23799/ruby
  3.测试是否可以连接、
  # telnet master.jiu.com 8140
  Trying 192.168.8.177...
  Connected to master.jiu.com (192.168.8.177).
  Escape character is '^]'.
  quit
  Connection closed by foreign host.
  1)向服务端申请证书
  # puppetd --test --server master.jiu.com
  info: Caching certificate for ca
  info: Creating a new SSL certificate request for agent165.jiu.com
  info: Certificate Request fingerprint (md5): BC:9C:93:4C:8E:71:8A:EB:E0:1E:F0:99:DC:37:BA:E5
  Exiting; no certificate found and waitforcert is disabled
  2)在服务端查看下是否有等待审批证书
  # puppetca --list
  "agent165.jiu.com" (BC:9C:93:4C:8E:71:8A:EB:E0:1E:F0:99:DC:37:BA:E5)
  3)审批证书
  # puppetca -s agent165.jiu.com
  notice: Signed certificate request for agent165.jiu.com
  notice: Removing file Puppet::SSL::CertificateRequest agent165.jiu.com at '/var/lib/puppet/ssl/ca/requests/agent165.jiu.com.pem'
  4)批准当前证书
  # puppetd --test --server master.jiu.com
  info: Caching certificate for agent165.jiu.com
  info: Caching certificate_revocation_list for ca
  info: Caching catalog for agent165.jiu.com
  info: Applying configuration version '1398158898'
  notice: Finished catalog run in 0.04 seconds
  4.puppet同步管理功能测试。puppet文件需要在/etc/puppet/manifests/site.pp中写任务。
  # cd /etc/puppet/manifests/
  # more site.pp
  node default{
  file {"/tmp/Puppet_test.txt":
  content => "My english name is Taokey.";}
  }
  重新启动下puppet。
  # /etc/init.d/puppetmasterd restart
  停止 puppetmaster:                                        [确定]
  启动 puppetmaster:                                        [确定]
  # chmod +x /etc/puppet/manifests/site.pp
  # /etc/puppet/manifests/site.pp
  /etc/puppet/manifests/site.pp: line 1: node: command not found
  /etc/puppet/manifests/site.pp: line 2: file: command not found
  /etc/puppet/manifests/site.pp: line 3: syntax error near unexpected token `}'
  /etc/puppet/manifests/site.pp: line 3: `content => "My english name is Taokey.";}'
  在客户端同步任务,默认是半个小时同步一次。
  # puppetd --test --server master.jiu.com
  info: Caching catalog for agent165.jiu.com
  info: Applying configuration version '1398159168'
  notice: /Stage//Node/File/content:
  --- /tmp/Puppet_test.txt      2014-04-22 17:11:09.000000000 +0800
  +++ /tmp/puppet-file.28330.0    2014-04-22 17:32:33.000000000 +0800
  @@ -1 +1 @@
  - taokey are handsome
  \ No newline at end of file
  +My english name is Taokey.
  \ No newline at end of file
  info: FileBucket adding {md5}f8b6f91540f80377f00e8e73bed18992
  info: /Stage//Node/File: Filebucketed /tmp/Puppet_test.txt to puppet with sum f8b6f91540f80377f00e8e73bed18992
  notice: /Stage//Node/File/content: content changed '{md5}f8b6f91540f80377f00e8e73bed18992' to '{md5}4e616a37997cf68dd0f15702af9ceca1'
  notice: Finished catalog run in 0.14 seconds
  查看agent165这台服务器是否生成相应文件。
  # more /tmp/Puppet_test.txt
  My english name is Taokey.
  到此为止,实验结束。
页: [1]
查看完整版本: 初始Puppet—Puppet的安装和简单使用