puppet安装和使用

来源:互联网 发布:淘宝新店铺怎么推广 编辑:程序博客网 时间:2024/04/28 19:56

puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置

文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标

是简化对这些资源的管理以及妥善处理资源间的依赖关系。

puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)

向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设

置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置服务器. 配置完成以后,puppet客

户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息.

puppet通信过程中,客户端向服务端请求时端口是8140,若是服务器推送到客户端时通信端口是8139,

所以安装和通信过程要注意防火墙的配置!!!可以先关闭.

更新puppet源

rpm -ivh "http://yum.puppetlabs.com/el/5/products/i386/puppetlabs-release-5-1.noarch.rpm"
rpm -ivh "http://yum.puppetlabs.com/el/5/products/x86_64/puppetlabs-release-5-1.noarch.rpm"
rpm -ivh "http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-1.noarch.rpm"
rpm -ivh "http://yum.puppetlabs.com/el/5/products/x86_64/puppetlabs-release-5-1.noarch.rpm"

puppet服务端安装

# puppet server install ==>> 主机名 : puppet_server IP : 1.1.1.1yum -y install ruby ruby-lib ruby-rdocyum -y install puppet-serverchkconfig puppet onservice puppetmaster start/etc/init.d/iptables stop > /dev/null 2>&1


puppet客户端安装

# puppet client install  ==>> 主机名 : puppet_client IP : 1.1.1.2echo "1.1.1.1 puppet_server" >> /etc/hosts  (服务端主机名)yum -y install ruby ruby-lib ruby-rdocyum -y install puppet


puppet客户端发送证书

#客户端第一次启动向服务端发送证书,要求签好之后才能通信
puppet agent --no-daemonize --onetime --verbose --debug --server=puppet_server(服务端主机名)

puppet服务端签证书

puppet cert list --all #查看所有客户端的请求(有+号的代表已经签好证书可以通信,没有加号的代表尚未签好证书)
puppet cert --sign puppet_client(客户端主机名) #这条命令加客户端主机名就能签字,自此可以通信


1.下面是一个文件同步的例子

puppet服务端
# vim /etc/puppet/fileserver.conf

# This file consists of arbitrarily named sections/modules# defining where files are served from and to whom# Define a section 'files'# Adapt the allow/deny settings to your needs. Order# for allow/deny does not matter, allow always takes precedence# over deny# [files]#  path /var/lib/puppet/files#  allow *.example.com#  deny *.evil.example.com#  allow 192.168.0.0/24# 在下面加一个配置域,名字叫做opencdn,路径是 /etc/puppet [opencdn]  path /etc/puppet  allow *

# vim /etc/puppet/manifests/site.pp

node default {        file {                "/tmp/helloworld.txt" :==>>推送到客户端的路径文件                source=>"puppet:///opencdn/test1/helloworld.txt", ==>> 根据/etc/puppet/fileserver.conf里面配置的opecnd域               #最终路径就是 /etc/puppet/test1/helloworld.txtrecurse=>"true",==>>可以传送目录                owner=>"root",                group=>"root",                mode=>777,        }}

# mkdir /etc/puppet/test1/
# cat /etc/puppet/test1/helloworld.txt
到这里为止puppet的服务端已经设置好了

puppet客户端

# puppet agent --test --server=puppet_server(服务端主机名)
# cat /tmp/helloworld.txt 就OK了

2.puppet从服务端推送系统命令到客户端执行

# vim /etc/puppet/manifests/site.pp

node default {exec { "/bin/ls > 1.txt": ==>> 这里对于""里面的字符要求很高,/bin/ls之前都不能有空格,否则就会提示错误cwd => "/tmp",==>> 客户端执行命令的路径path=> "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin", ==>> 对于命令的系统路径}}

3.一次推送多个指令

node default {        exec { "service opencdn restart":                cwd => "/tmp",                path=> "/usr/bin:/usr/sbin:/bin:/sbin",        }        exec { "ls > 1.txt":                cwd => "/tmp",                path=> "/usr/bin:/usr/sbin:/bin:/sbin",        }file {"/tmp/helloworld.txt" :source=>"puppet:///opencdn/test1/helloworld.txt",owner=>"root",group=>"root",mode=>777,}}


原创粉丝点击