puppet

运维工具
puppet rubby开放 支持多平台 c/s构架 可管理配置文件,cron任务 图形化配置
saltstack  python开发
ansible实现批量操做系统配置,程序部署,命令执行 python开发node



puppet的安装和配置
修改主机名 把ip+主机名添加到hosts文件中
写计划任务:crontab -e :*/10 * * * * ntpdate time.windows.com
安装puppet源rpm -ivh “http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm”
rpm -ivh puppetlabs-release-6-7.noarch.rpm --force --nodeps
服务端:chkconfig puppetmaster on     yum -y install puppet-server
客服端:listen = true,server =服务器名,runinterval=30(服务器与客服端更新时间)   chkconfig puppet on   yum -y install puppetpython



配置认证  让二者之间信任
客服端:puppet agent --test --server 信任服务端名    客服端生成ssl证书
puppet agent --verbose --no-daemonize 测试是否同步与更新linux


服务端:查看已认证客服端列表 puppet cert list --all      puppet cert sign 客服端名 服务端指定客服端证书
puppet cert clean 客服端删除指定客服端证书     puppet cert clean --all 删除全部证书
puppet agent --test --server 信任服务端名    客服端生成ssl证书
删除认证客服端后必须删除/var/lib/puppet/ssl/*下的全部证书 重启后才能生成新的证书apache



puppet配置自动签发证书
1 删除全部的之前配置   
2 在服务端配置文件中加入 autosign=true
3.vi /etc/puppet/autosign.conf    ======= *.*   容许全部的用户名
4 重启服务   查看认证。windows



puppet证书测试。
vi /etc/puppet/manifests/site.pp
node default {        定义全部的类
file { "/tmp/1.txt":   文件目录
  content =>"test,test";}}    文件内容
 重启服务数组


puppet安装和配置---定义模块管理  模块--<<类--<<资源
1,在./etc/puppet/modules 下建立名为testm的模块  mkdir /etc/puppet/modules/testm
2. 在testm目录下建立三个目录:files 存放文件目录 manifests模块的主配置文件 templates 模板与配置文件
3.  vi /etc/puppet/modules/manifests/init.pp   编译一个初始模块
class testm{     定义类名testm 随意定义
file {"/tmp/cisco.txt":定义在客服端建立的文件名
owner => "root", 属主
group =>"root",属组
mode =>0400, 权限
source=>"puppet://$puppetserver/modules/testm/cisco.txt" 获取资源的目录
}}服务器


这是新建目录的方式:也能够在上一目录下
class test{  定义类 能够自定义。随意。
file {"/usr/apache":
owner => "root", 属主
group =>"root",属组
mode =>0400, 权限
source=>"puppet://$puppetserver/modules/test/apache",
recurse =>true,递归查询
purge => true 文件同步
}
}
说明:类名字也叫作testm, 类下面定义了一个资源file,文件名字叫作/tmp/cisco.txt ,owner,group,mode定义文件的属主、数组以及权限,source定义这个文件从哪里获取。 $puppetserver一会也要定义一下,这里指的是puppet server服务器上/etc/puppet/modules/testm/files/1.txtless


vi /etc/puppet/manifests/site.pp
$puppetserver='主服务器名‘
node 客服端名 {
include testm   定义客服端须要加载的模块名
include test
}
说明:$puppetserver 定义服务端的主机名,node后面为客户端的主机名,这里面定义该客户端要加载的模块
 配置完成后,在客户端执行命令:puppet agent --test  --server=master.aming.com   //若是客户端上启动了puppet服务,不用执行这命令,它也会自动同步的上面的模块其实只是同步了一个文件而已,运维


那么要想同步一个目录如何作?咱们能够经过实现同步一个目录来作一个包发布系统。 好比在一台机器上编译安装好了apache,那么就能够经过这样的模块把这个apache目录整个分发到其余机器上。ide



远程执行命令
exec {"aaa" 执行命令的名字
unless => "test -f /tmp/1.txt", 判断是否有这文件
onlyif => "test -f /tmp/1.txt",   只有文件存在时或是一个文件才去建立
path => ["/usr","/sbin","/usr/bin"], 定义一个环境变量
command => "touch /tmp/1.txt"  如判断无文件 就建立文件
}
说明:unless后面的命令做为一个条件,当条件成立时,不会执行下面的命令,若是想要条件成立时,执行下面的命令,用 onlyif。要注意的是,咱们必定要给执行的这条命令加个条件,使用unless就能够,必须知足这个条件才能执行命令,不然这个命令会一直执行,不太稳当。



puppet的任务计划
cron {"linux":
command =>"/sbin/ntpdate time.windows.com",
user => "root",
minute => "*/5",
monthday =>"1-10",
#ensure => "sbsent"
}


puppet的几种模块下的类:module目录下创建一个模块:puppet模块下的文件files(用于下载文件)manifests(用于存放puppet的配置)包含的配置文件(init.pp管理模块全部pp文件配置,config.pp.server.pp,site.pp,install.pp,params.pp)templates(用于存放模块,方便pp调用))在

相关文章
相关标签/搜索