Puppet C/S初探 site.pp文件介绍(十)

Puppet生产中常用的就是C/S架构./etc/puppet/manifests/site.pp文件是puppet站点导航文件,Agent访问Master的一切配置管理工作都有site.pp文件开始,site.pp文件作用是让Master载入并寻找Agent的配置信息.site.pp文件默认在/etc/puppet/manifests/目录中.

manifests是puppet的资源清单目录,puppet的所有资源配置文件都以*.pp文件作为扩展名.manifests和site.pp文件的路径可以在/etc/puppet.conf文件中的[master]段修改,通过修改puppet.conf中的manifestdir来修改manifest的资源文件目录,修改manifest值来改变更新puppet入口导航文件.

默认master启动会监听8140端口,agent监听8139端口.

[[email protected] manifests]# ss -antlp | grep puppet
LISTEN     0      5                         *:8139                     *:*      users:(("puppet",31325,5))
LISTEN     0      5                         *:8140                     *:*      users:(("puppet",32174,5))

puppet的日志输出路径默认为系统的syslog.

[[email protected] manifests]# tail -f /var/log/messages
Sep 13 23:38:58 puppet puppet-master[34213]: Starting Puppet master version 3.8.7
Sep 13 23:39:04 puppet puppet-agent[31325]: Caught TERM; exiting
Sep 13 23:39:04 puppet puppet-agent[34266]: Reopening log files
Sep 13 23:39:05 puppet puppet-agent[34266]: Puppet --listen / kick is deprecated. See http://links.puppetlabs.com/puppet-kick-deprecation
Sep 13 23:39:05 puppet puppet-agent[34266]: Starting Puppet client version 3.8.7
Sep 13 23:39:06 puppet puppet-master[34213]: Compiled catalog for puppet.localdomain in environment production in 0.03 seconds
Sep 13 23:39:06 puppet puppet-agent[34270]: hello world
Sep 13 23:39:06 puppet puppet-agent[34270]: (/Stage[main]/Main/Notify[hello world]/message) defined ‘message‘ as ‘hello world‘
Sep 13 23:39:06 puppet puppet-agent[34270]: Finished catalog run in 0.01 seconds
Sep 13 23:39:06 puppet puppet-master[34213]: Report processor failed: Connection refused - connect(2)

通常master也不是随便一台机器就可以连接的,一般都会配火墙规则(下面是举例,真实环境具体对待).

# iptables -A INPUT -p icmp
# iptables -A INPUT -i lo -j ACCEPT
# iptables -A INPUT -d 192.168.30.134 -p tcp -m multiport --dports 80,443,8139,8140  -j ACCEPT
# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

默认安装完puppetmaster是不存在site.pp文件,手动创建site.pp文件(安装篇已经将puppet和svn结合,所以在win客户端操作svn创建):

注意:如果使用svn托管了puppet代码,中途直接在服务器写代码会导致svn版本库冲突.

报错如下:

svn: URL ‘svn://192.168.30.134/modules/test‘ of existing directory ‘/etc/puppet/modules/apache‘ does not match expected URL ‘svn://192.168.30.134/modules/apache‘

解决:登陆puppet master服务器,rm -rf /etc/puppet/*,重新从svn check即可.

操作如下:

[[email protected] puppet]# rm -rf *
[[email protected] puppet]# ls
[[email protected] puppet]# svn checkout svn://192.168.30.134 /etc/puppet/
Restored ‘/etc/puppet/puppet.conf‘
Restored ‘/etc/puppet/namespaceauth.conf‘
Restored ‘/etc/puppet/auth.conf‘
Restored ‘/etc/puppet/fileserver.conf‘
Restored ‘/etc/puppet/autosign.conf‘
A    /etc/puppet/modules
A    /etc/puppet/modules/test
A    /etc/puppet/modules/apache
A    /etc/puppet/modules/apache/files
A    /etc/puppet/modules/apache/lib
A    /etc/puppet/modules/apache/manifests
A    /etc/puppet/modules/apache/manifests/init.pp
A    /etc/puppet/modules/apache/templates
A    /etc/puppet/manifests
A    /etc/puppet/manifests/site.pp
A    /etc/puppet/manifests/nodes.pp
Checked out revision 64.

测试puppet代码:

puppet notify指令和shell中的echo指令相似,之前的文章介绍过,很多puppet功能测试都会选择notify指令.

测试节点sh-proxy2更新:

[[email protected] ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-proxy2.localdomain
Info: Applying configuration version ‘1505315382‘
Notice: hello world
Notice: /Stage[main]/Main/Notify[hello world]/message: defined ‘message‘ as ‘hello world‘
Notice: Finished catalog run in 0.02 seconds

测试节点sh-web1更新:

[[email protected] ~]# puppet agent -t
Notice: Ignoring --listen on onetime run
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-web1.localdomain
Info: Applying configuration version ‘1505315382‘
Notice: hello world
Notice: /Stage[main]/Main/Notify[hello world]/message: defined ‘message‘ as ‘hello world‘
Notice: Finished catalog run in 0.02 seconds

举例:(多节点匹配操作)

新建模块apache

cd /etc/puppet/modules
# mkdir apache/{templates,files,lib,manifests}

模块清单文件说明:

uppet模块,模块名称只能使用小写字母开头,可以包含小写字母、数字、下划线,但不能使用"main"或"settings"。

modules/apache/

files    文件存储目录

httpd.conf      puppet:///modules/Module_name/module_file

templates:    模板目录,访问路径template("modulename/Tomplatename")

*.erp

manifests:    清单目录

init.pp 必须包含且只能包含一个与模块同名的类

httpd.pp 每个清单文件通常只包含一个类,类名不可以与模块重名,除模块名外可以随意命名

lib :ruby插件存储目录,用于实现一些自定义的功能

示例:

安装apache软件httpd的init.pp文件.

class apache ($sta = "present") {
  package {"httpd":
    ensure=> $sta,
  }
}

文件路径即代码如图:

文件说明:

site.pp文件和nodes.pp文件.

site.pp文件为agent访问master的导航入口文件(site.pp文件直接可以定义资源,class等,批量操作建议引入其他文件).

manifest 可以有多个,manifest之间可以相互调用使用import.

import :导入所有

如下:

import "nodes"

nodes.pp文件作用匹配主机,主机管理文件.

模糊匹配:node /^sh-(web|proxy)\d+/

精确匹配:node "sh-proxy2"

如下:

agent端更新操作测试:

[[email protected] puppet]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for sh-proxy2.localdomain
Info: Applying configuration version ‘1505376917‘
Notice: /Stage[main]/Apache/Package[httpd]/ensure: created
Notice: Finished catalog run in 7.14 seconds
时间: 2024-07-31 03:10:16

Puppet C/S初探 site.pp文件介绍(十)的相关文章

46 puppet master-agent模型、运维工具介绍及pxe环境的实现、cobbler简单实现、CentOS7 cobbler

01 puppet master-agent模型 配置环境 node1 192.168.1.131 CentOS7.2 node2 192.168.1.132 CentOS7.2 node3 192.168.1.133 CentOS7.2 node4 192.168.1.134 CentOS7.2 1.agent节点扩展为master节点 [[email protected] ~]# yum -y install puppet-server-3.8.4-1.el7.noarch.rpm [[em

Puppet函数介绍(十八)

puppet函数 puppet函数主要用途是完成一个功能的集合,puppet的函数很多,只例举常用的几个. define函数 define函数主要用于创建自定义函数,define支持参数但不支持继承.通常可以通过define函数将多个资源整合为一个资源. define函数示例(crontab计划任务模块): 新建cron模块,依次建{templates,manifests,lib,files}文件夹,模块资源清单文件manifests下必须有init.pp文件,定义此模块的类且类名唯一. ini

linux设备驱动程序该添加哪些头文件以及驱动常用头文件介绍(转)

原文链接:http://blog.chinaunix.net/uid-22609852-id-3506475.html 驱动常用头文件介绍 #include <linux/***.h> 是在linux-2.6.29/include/linux下面寻找源文件.#include <asm/***.h> 是在linux-2.6.29/arch/arm/include/asm下面寻找源文件.#include <mach/***.h> 是在linux-2.6.29/arch/ar

Android的学习之路(二)项目中原生文件的使用场景和文件介绍

1.src文件:java源代码存放目录 2.gen 文件:自动生成所有由android开发工具自动生成的文件,目录中最重要的就是R.java文件,这个文件由android开 发工具自动产生的.android开发工具会自动根据你存放res目录的资源,同步更新修稿R.java文件,正因为 R.java文件是由开发工具自动生成的,所以我们应避免手工修改R.java.R.java文件在应用中起到了字典的作 用,它包含了各种资源的ID,通过R.java,应用可以很方便的找到对应资源, 2.1R.java 

APK扩展文件介绍、功能及用法

APK扩展文件介绍 Android Market (Google Play Store)中每一个APK文件的最大限制是50MB.假设您的程序中包括大量的数据文件,曾经您仅仅能把这些数据文件放到自己的server上,当用户启动程序的时候让用户去下载. 如今这些数据文件能够直接上传到Android Market了.在新的Market控制台上传App的时候.能够加入扩展文件了. 怎样使用扩展文件: 每一个APK能够有2个扩展文件,每一个文件最大限制是2GB. 为了降低用户的带宽消耗,最好使用压缩格式文

内存问题排查手段及相关文件介绍

5.内存问题排查手段及相关文件介绍[重点] 对于内存问题排查,或者OOM问题排查,一般会涉及到如下文件,下面将如下文件的分析和设置介绍一下,这也是本文档的重点,后面排查内存信息还是要根据这些文件信息来排查.其实未必是有内存泄露,也可能是一些策略有问题,比如线程数目的增加,buffer的申请.释放时间交集等. 5.1 /proc/sys/vm/min_free_kbytes min_free_kbytes用来确定系统开始回收内存的阀值,控制系统的空闲内存.值越高,内核越早开始回收内存,空闲内存越高

APK扩展文件介绍、功能及使用方法

APK扩展文件介绍 Android Market (Google Play Store)中每个APK文件的最大限制是50MB.如果您的程序中包含大量的数据文件,以前您只能把这些数据文件放到自己的服务器上,当用户启动程序的时候让用户去下载.现在这些数据文件可以直接上传到Android Market了.在新的Market控制台上传App的时候,可以添加扩展文件了. 如何使用扩展文件: 每个APK可以有2个扩展文件,每个文件最大限制是2GB.为了减少用户的带宽消耗,最好使用压缩格式文件吧. 这两扩展文

Linux core 文件介绍

Linux core 文件介绍 http://www.cnblogs.com/dongzhiquan/archive/2012/01/20/2328355.html 1. core文件的简单介绍在一个程序崩溃时,它一般会在指定目录下生成一个core文件.core文件仅仅是一个内存映象(同时加上调试信息),主要是用来调试的. 2. 开启或关闭core文件的生成用以下命令来阻止系统生成core文件:ulimit -c 0下面的命令可以检查生成core文件的选项是否打开:ulimit -a该命令将显示

第二章 DuiEngine资源文件介绍

一.初识DuiEngine的Skin Files 传统MFC界面主要是在一个.rc文件里进行窗口的布局,然后在resource.h中维系一个控件ID通过此控件ID在程序中通过此控件ID就可以访问到该控件,从而对指定控件做出各种操作:DuiEngine与之不同,但是思想仍然类似.以上章我们利用DuiEngineWizard生成的第一个工程为例: DuiEngine将与界面相关的东西都扔到了一个叫Skin Files的文件夹里,其中: 1.image文件中主要用于存放工程中要使用到的相关图像,这个不