手机版
你好,游客 登录 注册
背景:
阅读新闻

Puppet 3.0资源介绍

[日期:2013-08-05] 来源:Linux社区  作者:bingodeng [字体:大 中 小]

一,Puppet资源:

Puppet将软件安装,文件配置,服务管理,用户添加,定时计划配置等抽象成资源。

Puppet 的详细介绍:请点这里
Puppet 的下载地址:请点这里

有关Puppet agent端三种备份恢复方案探讨研究 http://www.linuxidc.com/Linux/2013-07/87885.htm

选择更安全的方式注册你的Puppet节点 http://www.linuxidc.com/Linux/2013-07/87884.htm

通过配置SSH深刻理解Puppet的语法及工作机制 http://www.linuxidc.com/Linux/2013-07/87882.htm

Puppet利用Nginx多端口实现负载均衡 http://www.linuxidc.com/Linux/2013-02/79794.htm

CentOS(5和6)下Puppet的C/S模式实例 http://www.linuxidc.com/Linux/2011-12/50502.htm

二,资源类型:

1,file管理文件,通过一定的配置也可以管理目录

2,package管理软件包,会将软件自动安装

3,service 管理服务,设置服务运行还是停止

4,cron 设置定时任务

5,user添加用户

6,group添加组

7,exec如果资源不能满足任务时,可以通过与shell 命令交互来完成

8,notify资源之间通信

三,资源语法格式:

Type { “title”:

Attribute =>a,

Attribute =>b,

}

Type 就是上面的资源类型file……,“title”为了标识这个资源,attribute属性,如果权限,用户之类。

四,资源使用

1,应用于class中,完成某一个具体的应用

2,应用于site.pp中,作为全局配置

五,资源详解

1,file

对文件:有用户,用户组,权限,链接文件,内容

对目录:用户,用户组,权限,清理目录及子目录。

2,file资源属性

File { “absolute path”:

Ensure => present/absent/file/directory/link ,

#定义absolute path是否存在及它应该有哪些角色

#ensure定义资源处于什么状态,present表示如果client不存在则自动创建,absent表示如果client端存在这个文件,则删除,file表示文件,directory表示目录,link表示链接

User =>”username”,

Group => “groupname”,

Mode => 0777,

#四位八进制

Path=>”absolute path”,

#如果在title指定绝对路径了,在这可以省略,提高处理效率。

Soure => “puppet:///url”,

#指定到master上文件的路径或者client上本地文件路径

Content=>”content”,

#指定文件内容的字符串,也可以是模板或者输出内容的函数,模版常用

Target =>

#用于链接文件,创建链接文件时的目标文件

Recurse =>

#对应目录,递归

Purge =>

#对于没有定义的目录或文件,不让其存在这目录文件中。清理作用

}


}

其他的属性

Backup,checksum,force,igore,links,provider,recurselimit,replace,selrange,selrole,seltype,seltype,seluser,sourceselect,type

3,flie资源的应用

/etc/puppet下manifests是client的入口,当client来请求资源来,从manifests请求。在manifests下的site.pp是必须存在的。所有的客户端需要的资源都在这里定义。如果服务器过多,肯定会造成这个文件庞大无比,解决办法是给客户端单独新建一个文件,将资源属性定义到这,然后在site.pp 用import将其文件包括进来就行了。如果一台服务器有许多服务时,可以为这台服务器在manifests下新建一个目录,然后通过import node/*将node目录的文件都包含进来

[root@master manifests]# touch site.pp 需要手工创建

[root@master manifests]# ls

Site.pp

[root@master manifests]# touch node.pp

[root@master manifests]# echo "import ‘node.pp’" >> site.pp

4,实例

1)文件

[root@master manifests]# vim node.pp

file { "/etc/ssh/sshd_config":

ensure=> present,

owner => root,

group => root,

mode => 0600,

}

[root@client ~]# mv /etc/ssh/sshd_config /root

[root@client puppet]# puppet agent --verbose --no-daemonize 下面表示成功

Notice: Starting Puppet client version 3.2.3

Info: Retrieving plugin

Info: Caching catalog for client

Info: Applying configuration version '1375107271'

Notice: /Stage[main]//File[/etc/ssh/sshd_config]/ensure: created

Notice: Finished catalog run in 0.04 seconds

2)目录

[root@master manifests]# vim node.pp

file { "/etc/ssh/sshd_config":

ensure=> directory,

owner => root,

group => root,

mode => 0600,

recurse =>true,

purge => true,

#如果在/test下目录不在资源管理的范围,则会将其删除,必须加下面的force才有效,删除目录需要配合force,删除文件则不需要

force =>true,

igore => test.txt #表示test.txt将忽略,不会被删除。

}

[root@master manifests]# vim node.pp 对/etc/puppet/puppet.conf创建链接文件,链接名为/test/test。

file { "/test":

ensure=> directory,

owner => root,

group => root,

mode => 0600,

recurse => true,

purge => true,

force => true,

}

file { "/test/test":

ensure => link,

target => "/etc/puppet/puppet.conf",

}

~

[root@client puppet]# puppet agent --verbose --no-daemonize 查看有没有创建

[root@master manifests]# vim site.pp 定义不同节点的资源,也可以这样写

node "client1" {

file { "/test_client1":

ensure => present,

}

node "client2" {

file { "/test_client2":

ensure => present,

}

[root@client puppet]# puppet agent --test也可以实现上面--verbose

linux
相关资讯       Puppet  Puppet 3.0 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款