初始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.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

三、安装配置Puppet

1)安装运行ruby程序所用的软件包。

[root@master ~]#yum install ruby ruby-libs

[root@master ~]# 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用户和组.

[root@master ~]# groupadd puppet

[root@master ~]# useradd -g puppet -s /bin/false -M puppet

3)修改host文件.

[root@master ~]# 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)解压并执行安装下载的文件包。

[root@master ~]# cd /taokey/tools/

[root@master tools]# tar -zxf facter-1.7.5.tar.gz

[root@master tools]# cd facter-1.7.5

[root@master facter-1.7.5]# ruby install.rb

[root@master facter-1.7.5]# cd ..

[root@master tools]# tar -zxf puppet-2.7.25.tar.gz

[root@master tools]# cd puppet-2.7.25

[root@master puppet-2.7.25]# ruby install.rb

5)拷贝puppet文件到/etc/puppet目录

[root@master puppet-2.7.25]# mkdir -p /etc/puppet && cp conf/redhat/* /etc/puppet/

[root@master puppet-2.7.25]# cp /etc/puppet/server.init /etc/init.d/puppetmasterd

6)赋予脚本权限,设置相应的启动项。

[root@master ~]# chmod 755 /etc/init.d/puppetmasterd

[root@master ~]# ll /etc/init.d/puppetmasterd

-rwxr-xr-x. 1 root root 3936 4月  18 15:44 /etc/init.d/puppetmasterd

[root@master ~]# chkconfig --add puppetmasterd

[root@master ~]# chkconfig --level 35 puppetmasterd on

[root@master ~]# chkconfig --list | grep puppetmasterd

puppetmasterd   0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:启用  6:关闭

[root@master ~]# /etc/init.d/puppetmasterd restart

停止 puppetmaster:                                        [确定]

启动 puppetmaster:                                        [确定]

[root@master ~]# netstat -anpt | grep 8140

tcp        0      0 0.0.0.0:8140                0.0.0.0:*                   LISTEN      21341/ruby    

2.客户端设置:

1)修改服务器的主机名。

[root@agent165 ~]# more /etc/sysconfig/network

NETWORKING=yes

NETWORKING_IPV6=no

HOSTNAME=agent165.jiu.com

GATEWAY=192.168.1.1

[root@agent165 ~]# hostname

agent165.jiu.com

2)安装运行ruby程序所用的软件包。

[root@agent165 ~]# yum install -y ruby ruby-libs

[root@agent165 ~]# 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)解压并执行安装下载的文件包。

[root@agent165 ~]# cd /taokey/tools/

[root@agent165 tools]# ls

facter-1.7.5.tar.gz  puppet-2.7.25.tar.gz

[root@agent165 tools]# tar -zxf facter-1.7.5.tar.gz

[root@agent165 tools]# cd facter-1.7.5

[root@agent165 facter-1.7.5]# ruby install.rb

[root@agent165 facter-1.7.5]# cd ..

[root@agent165 tools]# tar -zxf puppet-2.7.25.tar.gz

[root@agent165 tools]# cd puppet-2.7.25

[root@agent165 puppet-2.7.25]# ruby install.rb

4)拷贝puppet文件到/etc/puppet目录

[root@agent165 puppet-2.7.25]# mkdir /etc/puppet && cp /etc/puppet/client.init /etc/init.d/puppet

[root@agent165 ~]# chmod 755 /etc/init.d/puppet

[root@agent165 ~]# chkconfig --add puppet

[root@agent165 ~]# chkconfig --level 35 puppet on

[root@agent165 ~]# chkconfig --list | grep puppet

puppet          0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:启用  6:关闭

[root@agent165 ~]# /etc/init.d/puppet start

启动 puppet:                                              [确定]

[root@agent165 ~]# netstat -anpt | grep 8140

tcp        0      1 192.168.8.165:49494         202.106.199.34:8140         SYN_SENT    23799/ruby  

3.测试是否可以连接、

[root@agent165 ~]# 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)向服务端申请证书

[root@agent165 ~]# 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)在服务端查看下是否有等待审批证书

[root@master ~]# puppetca --list

 "agent165.jiu.com" (BC:9C:93:4C:8E:71:8A:EB:E0:1E:F0:99:DC:37:BA:E5)

3)审批证书

[root@master ~]# 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)批准当前证书

[root@agent165 ~]# 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中写任务。

[root@master ~]# cd /etc/puppet/manifests/

[root@master manifests]# more site.pp

node default{

file {"/tmp/Puppet_test.txt":

content => "My english name is Taokey.";}

}

重新启动下puppet。

[root@master ~]# /etc/init.d/puppetmasterd restart

停止 puppetmaster:                                        [确定]

启动 puppetmaster:                                        [确定]

[root@master ~]# chmod +x /etc/puppet/manifests/site.pp

[root@master ~]# /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.";}'

在客户端同步任务,默认是半个小时同步一次。

[root@agent165 ~]# puppetd --test --server master.jiu.com

info: Caching catalog for agent165.jiu.com

info: Applying configuration version '1398159168'

notice: /Stage[main]//Node[default]/File[/tmp/Puppet_test.txt]/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[main]//Node[default]/File[/tmp/Puppet_test.txt]: Filebucketed /tmp/Puppet_test.txt to puppet with sum f8b6f91540f80377f00e8e73bed18992

notice: /Stage[main]//Node[default]/File[/tmp/Puppet_test.txt]/content: content changed '{md5}f8b6f91540f80377f00e8e73bed18992' to '{md5}4e616a37997cf68dd0f15702af9ceca1'

notice: Finished catalog run in 0.14 seconds

查看agent165这台服务器是否生成相应文件。

[root@agent168 ~]# more /tmp/Puppet_test.txt

My english name is Taokey.

到此为止,实验结束。


你可能感兴趣的:(windows,服务器,配置文件,管理工具,管理系统)