puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描写叙述语言,可管理配置
文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标
是简化对这些资源的管理以及妥善处理资源间的依赖关系。
puppet採用C/S星状的结构,全部的client和一个或几个server交互。每一个client周期的(默认半个小时)
向server发送请求,获得其最新的配置信息,保证和该配置信息同步。每一个puppetclient每半小时(能够设
置)连接一次server端, 下载最新的配置文件,而且严格依照配置文件来配置server. 配置完毕以后,puppet客
户端能够反馈给server端一个消息. 假设出错,也会给server端反馈一个消息.
puppet通信过程中,client向服务端请求时port是8140,若是server推送到client时通信port是8139,
所以安装和通信过程要注意防火墙的配置!!!能够先关闭.
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 server install ==>> 主机名 : puppet_server IP : 1.1.1.1
yum -y install ruby ruby-lib ruby-rdoc
yum -y install puppet-server
chkconfig puppet on
service puppetmaster start
/etc/init.d/iptables stop > /dev/null 2>&1
# puppet client install ==>> 主机名 : puppet_client IP : 1.1.1.2
echo "1.1.1.1 puppet_server" >> /etc/hosts (服务端主机名)
yum -y install ruby ruby-lib ruby-rdoc
yum -y install puppet
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" : ==>>推送到client的路径文件
source=>"puppet:///opencdn/test1/helloworld.txt", ==>> 依据/etc/puppet/fileserver.conf里面配置的opecnd域
#终于路径就是 /etc/puppet/test1/helloworld.txt
recurse=>"true", ==>>能够传送文件夹
owner=>"root",
group=>"root",
mode=>777,
}
}
# mkdir /etc/puppet/test1/
# cat /etc/puppet/test1/helloworld.txt
到这里为止puppet的服务端已经设置好了
puppetclient
# puppet agent --test --server=puppet_server(服务端主机名)
# cat /tmp/helloworld.txt 就OK了
# vim /etc/puppet/manifests/site.pp
node default {
exec { "/bin/ls > 1.txt": ==>> 这里对于""里面的字符要求非常高,/bin/ls之前都不能有空格,否则就会提示错误
cwd => "/tmp", ==>> client运行命令的路径
path=> "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin", ==>> 对于命令的系统路径
}
}
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,
}
}