您的位置:首页 > 移动开发

pappet运维应用(一)

2017-11-25 17:15 176 查看
puppet是一种Linux、Unix、windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件、用户、cron任务、软件包、系统服务等。puppet把这些系统实体称之为资源,puppet的设计目标是简化对这些资源的管理以及妥善处理资源间的依赖关系。

puppet采用C/S星状的结构,所有的客户端和一个或几个服务器交互。每个客户端周期的(默认半个小时)向服务器发送请求,获得其最新的配置信息,保证和该配置信息同步。每个puppet客户端每半小时(可以设置)连接一次服务器端, 下载最新的配置文件,并且严格按照配置文件来配置客户端. 配置完成以后,puppet客户端可以反馈给服务器端一个消息. 如果出错,也会给服务器端反馈一个消息.

最新安装包下载地址:http://yum.pappet.com

puppet的工作模型:

单机模型(standalone):手动应用清单;

master/agent:由agent周期性地向Master请求清单并自动应用于本地;

主服务端puppet和puppet-server都需要安装,pupper-server依赖pupper

单机模型:

程序环境:

配置文件:/etc/puppet/

puppet.conf

主程序:/usr/bin/puppet

puppet程序:

用法: puppet [options] [options]

‘puppet help ’ for help on a specific subcommand.

puppet apply:

puppet apply [-d|–debug] [-v|–verbose] [-e|–execute] [–noop]

puppet describe:

puppet describe [-h|–help] [-s|–short] [-p|–providers] [-l|–list]

-l:列出所有资源类型;

-s:显示指定类型的简要帮助信息;

-m:显示指定类型的元参数,一般与-s一同使用;

资源定义:向资源类型的属性赋值来实现,可称为资源类型实例化;

定义了资源实例的文件即清单,manifest;

定义资源的语法:

type {‘title’:

attribute1 => value1,

atrribute2 => value2,

……

}

注意:type必须使用小写字符;title是一个字符串,在同一类型中必须惟一;

资源属性中的三个特殊属性:

Namevar, 可简称为name;

ensure:资源的目标状态;

Provider:指明资源的管理接口;

资源类型:

group:

Manage groups.

属性:

name:组名;

gid:GID;

system:是否为系统组,true OR false;

ensure:目标状态,present/absent;

members:成员用户;

user:

Manage users.

属性:

name:用户名;

uid: UID;

gid:基本组ID;

groups:附加组,不能包含基本组;

comment:注释;

expiry:过期时间 ;

home:家目录;

shell:默认shell类型;

system:是否为系统用户 ;

ensure:present/absent;

password:加密后的密码串;

资源引用:

Type[‘title’]

类型的首字母必须大写;

关系元参数:before/require

A before B: B依赖于A,定义在A资源中;

{



before => Type[‘B’],



}

B require A: B依赖于A,定义在B资源中;

{



require => Type[‘A’],



}

package:

Manage packages.

属性:

ensure:installed, present, latest, absent, any version string (implies present)

name:包名;

source:程序包来源,仅对不会自动下载相关程序包的provider有用,例如rpm或dpkg;

provider:指明安装方式;

service:

Manage running services.

属性:

ensure:Whether a service should be running. Valid values are
stopped
(also called
false
),
running
(also called
true
).

enable:Whether a service should be enabled to start at boot. Valid values are
true
,
false
,
manual
.

name:

path:The search path for finding init scripts. Multiple values should be separated by colons or provided as an array. 脚本的搜索路径,默认为/etc/init.d/;

hasrestart:

hasstatus:

start:手动定义启动命令;

stop:

status:

restart:Specify a restart command manually. If left unspecified, the service will be stopped and then started. 通常用于定义reload操作;

file:

Manages files, including their content, ownership, and permissions.

ensure:Whether the file should exist, and if so what kind of file it should be. Possible values are
present
,
absent
,
file
,
directory
, and
link
.

file:类型为普通文件,其内容由content属性生成或复制由source属性指向的文件路径来创建;

link:类型为符号链接文件,必须由target属性指明其链接的目标文件;

directory:类型为目录,可通过source指向的路径复制生成,recurse属性指明是否递归复制;

path:文件路径;

source:源文件;

content:文件内容;

target:符号链接的目标文件;

owner:属主

group:属组

mode:权限;

atime/ctime/mtime:时间戳;

资源有特殊属性:

名称变量(namevar):

name可省略,此时将由title表示;

ensure:

定义资源的目标状态;

元参数:metaparameters

依赖关系:

before

require

通知关系:通知相关的其它资源进行“刷新”操作;

notify

A notify B:B依赖于A,且A发生改变后会通知B;

{



notify => Type[‘B’],



}

subscribe

B subscribe A:B依赖于A,且B监控A资源的变化产生的事件;

{



subscribe => Type[‘A’],



}

示例1:

file{‘test.txt’:

path => ‘/tmp/test.txt’,

ensure => file,

source => ‘/etc/fstab’,

}

file{‘test.symlink’:

path => ‘/tmp/test.symlink’,

ensure => link,

target => ‘/tmp/test.txt’,

require => File[‘test.txt’],

}

file{‘test.dir’:

path => ‘/tmp/test.dir’,

ensure => directory,

source => ‘/etc/yum.repos.d/’,

recurse => true, #如果这里recurse => limit 则是限制目录层级到多少层

}

源为文件或多个文件,目标为目录,则复制过去也是文件,

示例2:

service{‘h
afea
ttpd’:

ensure => running,

enable => true,

restart => ‘systemctl restart httpd.service’,

# subscribe => File[‘httpd.conf’],

}

package{‘httpd’:

ensure => installed,

}

file{‘httpd.conf’:

path => ‘/etc/httpd/conf/httpd.conf’,

source => ‘/root/manifests/httpd.conf’,

ensure => file,

notify => Service[‘httpd’],

}

Package[‘httpd’] -> File[‘httpd.conf’] -> Service[‘httpd’]

exec:

Executes external commands. Any command in an
exec
resource must be able to run multiple times without causing harm — that is, it must be idempotent.

command (namevar):要运行的命令;

cwd:The directory from which to run the command.

creates:文件路径,仅此路径表示的文件不存在时,command方才执行;

user/group:运行命令的用户身份;

path:The search path used for command execution. Commands must be fully qualified if no path is specified.

onlyif:此属性指定一个命令,此命令正常(退出码为0)运行时,当前command才会运行;

unless:此属性指定一个命令,此命令非正常(退出码为非0)运行时,当前command才会运行;

refresh:重新执行当前command的替代命令;

refreshonly:仅接收到订阅的资源的通知时方才运行;

cron:

Installs and manages cron jobs. Every cron resource created by Puppet requires a command and at least one periodic attribute (hour, minute, month, monthday, weekday, or special).

command:要执行的任务;

ensure:present/absent;

hour:

minute:

monthday:

month:

weekday:

user:以哪个用户的身份运行命令

target:添加为哪个用户的任务

name:cron job的名称;

示例:

cron{‘timesync’:

command => ‘/usr/sbin/ntpdate 172.16.0.1 &> /dev/null’,

ensure => present,

minute => ‘*/3’,

user => ‘root’,

}

notify:

Sends an arbitrary message to the agent run-time log.

属性:

message:信息内容

name:信息名称;

核心类型:

group: 组

user:用户

packge:程序包

service:服务

file:文件

exec:执行自定义命令,要求幂等

cron:周期性任务计划

notify:通知

https://docs.puppet.com/puppet/5.2/cheatsheet_core_types.html#notify
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unix 运维 配置管理