A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。

puppet 系统架构

Puppet是开源的基于Ruby的系统配置管理工具,puppet是一个C/S结构, 当然,这里的C可以有很多,因此,也可以说是一个星型结构. 所有的puppet客户端同一个服务器端的puppet通讯. 每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置服务器. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息。

工作步骤
Puppet工作流程
1. 客户端Puppetd向Master发起认证请求,或使用带签名的证书。
2. Master告诉Client你是合法的。
3. 客户端Puppetd调用Facter,Facter探测出主机的一些变量,例如主机名、内存大小、IP地址等。Puppetd将这些信息通过SSL连接发送到服务器端。
4. 服务器端的Puppet Master检测客户端的主机名,然后找到manifest对应的node配置,并对该部分内容进行解析。Facter送过来的信息可以作为变量处 理,node牵涉到的代码才解析,其他没牵涉的代码不解析。解析分为几个阶段,首先是语法检查,如果语法错误就报错;如果语法没错,就继续解析,解析的结 果生成一个中间的“伪代码”(catelog),然后把伪代码发给客户端。
5. 客户端接收到“伪代码”,并且执行。
6. 客户端在执行时判断有没有File文件,如果有,则向fileserver发起请求。
7. 客户端判断有没有配置Report,如果已配置,则把执行结果发送给服务器。
8. 服务器端把客户端的执行结果写入日志,并发送给报告系统。
部署规划
服务器 192.168.137.10 Hehe
客户端 192.168.137.101 localhost.localdomain
安装
因为是基于ruby的,所以需要安装ruby need的环境(客户端/服务器端均需要安装)
libselinux-utils
ruby-libs
ruby
libselinux-ruby
augeas-libs
ruby-shadow
ruby-augeas
yum install dmidecode//注释:centOS6需要装
yum install pciutils//注释:centOS6需要装
facter,用来采集本机数据的
上述软件直接采用yum安装就好
安装完必备环境后,就可以安装puppet了。
可以源码安装,也可以rpm安装,客户端只需安装puppet,服务器端还需要安装Puppet-server。
配置
配置主机名(服务器端,客户端同样处理)
vi /etc/sysconfig/network
hostname设置成自己想要的,一般情况不动就可以
可以运行hostname查看。
vi /etc/hosts,把服务器客户端的ip以及对应的主机名都加进去。
呵呵。。。这样就配完了。。我一开始还错了。
接下来就是启动和链接了。
服务器端启动
/etc/init.d/puppetmasterd start
检查
netstat -anpt | grep 8140
客户端启动
/etc/init.d/puppet start
检查
netstat -an | grep 8139
客户端向服务端申请证书
puppetd --test --server Hehe
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
服务端审批证书
puppetca -s localhost.localdomain
这样就好了。
下面测试
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.
到此为止,实验结束。

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马