45 puppet基础、资源详解、配置语言、puppet类与模板及模块

01 puppet基础

配置:

node1:192.168.1.131 CentOS7.2

node2:192.168.1.132 CentOS7.2

[[email protected] ~]# rpm -ivh epel-release-latest-7.noarch.rpm

[[email protected] ~]# yum list all | grep -i "puppet"

puppet.noarch                           3.6.2-3.el7                    epel     

puppet-firewalld.noarch                 0.1.3-1.el7                    epel     

puppet-server.noarch                    3.6.2-3.el7                    epel     

[[email protected] ~]# ls *rpm

facter-2.4.4-1.el7.x86_64.rpm  puppet-server-3.8.4-1.el7.noarch.rpm

puppet-3.8.4-1.el7.noarch.rpm

[[email protected] ~]# rpm -ivh epel-release-latest-7.noarch.rpm 

[[email protected] ~]# yum install facter-2.4.4-1.el7.x86_64.rpm puppet-3.8.4-1.el7.noarch.rpm 

02 puppet资源详解

#定义资源清单:

1、group、user示例

[[email protected] ~]# mkdir mainfests

[[email protected] ~]# cd mainfests/

[[email protected] mainfests]# vim test1.pp

group {‘distro‘:

gid     => 2000,

ensure  => present,

}   

user {‘centos‘:

uid     => 2000,

gid     => 2000,

shell   => ‘/bin/bash‘,

home    => ‘/home/centos‘,

ensure  => present,

}   

[[email protected] mainfests]# puppet apply -v test1.pp 

Notice: Compiled catalog for node2 in environment production in 0.61 seconds

Info: Applying configuration version ‘1480767979‘

Notice: Finished catalog run in 0.08 seconds

[[email protected] mainfests]# tail -5 /etc/group 

avahi:x:70:

slocate:x:21:

tcpdump:x:72:

puppet:x:52:

distro:x:2000:

[[email protected] mainfests]# tail -5 /etc/passwd

gnome-initial-setup:x:988:983::/run/gnome-initial-setup/:/sbin/nologin

avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin

tcpdump:x:72:72::/:/sbin/nologin

puppet:x:52:52:Puppet:/var/lib/puppet:/sbin/nologin

centos:x:2000:2000::/home/centos:/bin/bash

2、file实例

[[email protected] mainfests]# vim test2.pp

file{‘/tmp/mydir‘:

ensure     =>  directory,

}

file{‘/tmp/puppet.file‘;

content     =>  ‘puppet testing\nsecond line.‘,

ensure      =>  file,

owner       =>  ‘centos‘,

group       =>  ‘distro‘,

mode        =>  ‘0400‘,

}

file{‘/tmp/fstab.puppet‘:

source      =>  ‘/etc/fstab‘,

ensure      =>  file,

}

file{‘/tmp/puppet.link‘:

ensure      =>  link,

target      =>  ‘/tmp/puppet.file‘,

}

[[email protected] mainfests]# puppet apply -v -d test2.pp

3、exec示例

[[email protected] mainfests]# vim test3.pp

exec{‘/usr/sbin/modprobe ext4‘:

user    =>  root,

group   =>  root,

refresh =>  ‘/usr/sbin/modprobe -r ext4 && /usr/sbin/modprobe ext4‘,

timeout =>  5,

tries   =>  2,

}

exec {‘/bin/echo hello > /tmp/hello.txt‘:

user    =>  root,

group   =>  root,

creates =>  ‘/tmp/hello.txt‘,

}

exec {‘/bin/echo hello > /tmp/hello2.txt‘:

user    =>  root,

group   =>  root,

unless  =>  ‘/usr/bin/test -e /tmp/hello2.txt‘,

}

[[email protected] mainfests]# puppet apply -v test3.pp 

Notice: Compiled catalog for node2 in environment production in 0.23 seconds

Info: Applying configuration version ‘1480822653‘

Notice: /Stage[main]/Main/Exec[/usr/sbin/modprobe ext4]/returns: executed successfully

Notice: Finished catalog run in 0.06 seconds

4、notify示例

[[email protected] mainfests]# vim test4.pp

notify{"hello there.":}

[[email protected] mainfests]# puppet apply -v test4.pp 

Notice: Compiled catalog for node2 in environment production in 0.09 seconds

Info: Applying configuration version ‘1480823772‘

Notice: hello there.

Notice: /Stage[main]/Main/Notify[hello there.]/message: defined ‘message‘ as ‘hello there.‘

Notice: Finished catalog run in 0.06 seconds

5、cron示例

[[email protected] mainfests]# vim test5.pp

cron{"sync time":

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

minute      =>  ‘*/10‘,

ensure      =>  absent,

}   

[[email protected] mainfests]# puppet apply -v test5.pp 

Notice: Compiled catalog for node2 in environment production in 0.26 seconds

Info: Applying configuration version ‘1480824444‘

Notice: /Stage[main]/Main/Cron[sync time]/ensure: created

Notice: Finished catalog run in 0.11 seconds

 

03 puppet配置语言 

6、package示例

[[email protected] ~]# ls jdk-8u25-linux-x64.rpm 

jdk-8u25-linux-x64.rpm

[[email protected] ~]# mv jdk-8u25-linux-x64.rpm /usr/local/src/

[[email protected] ~]# cd mainfests/

[[email protected] mainfests]# vim test6.pp

package{‘zsh‘:

ensure      =>  latest,

}   

package{‘jdk‘:

ensure      =>  installed,

source      =>  ‘/usr/local/src/jdk-8u25-linux-x64.rpm‘,

provider    =>  rpm,

}   

[[email protected] mainfests]# puppet apply -v test6.pp 

Notice: Compiled catalog for node2 in environment production in 1.05 seconds

Info: Applying configuration version ‘1480827477‘

Notice: /Stage[main]/Main/Package[zsh]/ensure: created

Notice: /Stage[main]/Main/Package[jdk]/ensure: created

Notice: Finished catalog run in 424.65 seconds

7、service示例

[[email protected] mainfests]# vim test7.pp

package{‘nginx‘:

ensure      =>  latest,

}   

service{‘nginx‘:

ensure      =>  running,

enable      =>  true,

hasrestart  =>  true,

restart     =>  ‘systemctl reload nginx.service‘,

}   

[[email protected] mainfests]# puppet apply -v test7.pp 

Notice: Compiled catalog for node2 in environment production in 1.24 seconds

Info: Applying configuration version ‘1480836821‘

Notice: /Stage[main]/Main/Package[nginx]/ensure: created

Notice: /Stage[main]/Main/Service[nginx]/ensure: ensure changed ‘stopped‘ to ‘running‘

Info: /Stage[main]/Main/Service[nginx]: Unscheduling refresh on Service[nginx]

Notice: Finished catalog run in 41.21 seconds

[[email protected] mainfests]# vim test8.pp

group {‘linux‘:

gid     => 3000,

ensure  => present,

}

user {‘suse‘:

uid     => 3000,

gid     => 3000,

shell   => ‘/bin/bash‘,

home    => ‘/home/suse‘,

ensure  => present,

}

[[email protected] mainfests]# puppet apply -v test8.pp 

Notice: Compiled catalog for node2 in environment production in 0.60 seconds

Info: Applying configuration version ‘1480837614‘

Notice: /Stage[main]/Main/Group[linux]/ensure: created

Notice: /Stage[main]/Main/User[suse]/ensure: created

Notice: Finished catalog run in 0.24 seconds

8、特殊属性

[[email protected] mainfests]# mkdir -p /root/modules/nginx/flies

[[email protected] mainfests]# cp /etc/nginx/nginx.conf /root/modules/nginx/flies/

[[email protected] mainfests]# vim /root/modules/nginx/flies/nginx.conf 

修改

worker_processes auto;

worker_processes 2;

修改

listen       80

listen       8080

[[email protected] mainfests]# vim test9.pp 

package{‘nginx‘:

ensure      =>  latest,

}

file{‘/etc/nginx/nginx.conf‘:

ensure      =>  file,

source      =>  ‘/root/modules/nginx/flies/nginx.conf‘,

require     =>  Package[‘nginx‘],

notify      =>  Service[‘nginx‘],

}

service{‘nginx‘:

ensure      =>  running,

enable      =>  true,

hasrestart  =>  true,

#restart        =>  ‘systemctl reload nginx.service‘,

require     =>  [ Package[‘nginx‘], File[‘/etc/nginx/nginx.conf‘] ],

}

[[email protected] mainfests]# puppet apply -v test9.pp 

Notice: Compiled catalog for node2 in environment production in 1.43 seconds

Info: Applying configuration version ‘1480854538‘

Notice: Finished catalog run in 4.68 seconds

[[email protected] mainfests]# service nginx stop

Redirecting to /bin/systemctl stop  nginx.service

[[email protected] mainfests]# vim /etc/nginx/nginx.conf

修改

worker_processes 2;

worker_processes auto;

[[email protected] mainfests]# puppet apply -v test9.pp 

Notice: Compiled catalog for node2 in environment production in 1.45 seconds

Info: Applying configuration version ‘1480855179‘

Info: Computing checksum on file /etc/nginx/nginx.conf

Info: FileBucket got a duplicate file {md5}93bc8e01bfd45e7e18b23acc178ae25b

Info: /Stage[main]/Main/File[/etc/nginx/nginx.conf]: Filebucketed /etc/nginx/nginx.conf to puppet with sum 93bc8e01bfd45e7e18b23acc178ae25b

Notice: /Stage[main]/Main/File[/etc/nginx/nginx.conf]/content: content changed ‘{md5}93bc8e01bfd45e7e18b23acc178ae25b‘ to ‘{md5}456ddb9d4209543dab23207931473c91‘

Notice: /Stage[main]/Main/Service[nginx]/ensure: ensure changed ‘stopped‘ to ‘running‘

Info: /Stage[main]/Main/Service[nginx]: Unscheduling refresh on Service[nginx]

Notice: Finished catalog run in 5.29 seconds

[[email protected] mainfests]# vim /root/modules/nginx/flies/nginx.conf 

修改

worker_processes 2;

worker_processes 3;

修改

listen       80 default_server;

listen       808 default_server;

[[email protected] mainfests]# puppet apply -v test9.pp 

Notice: Compiled catalog for node2 in environment production in 1.41 seconds

Info: Applying configuration version ‘1480857702‘

Info: Computing checksum on file /etc/nginx/nginx.conf

Info: /Stage[main]/Main/File[/etc/nginx/nginx.conf]: Filebucketed /etc/nginx/nginx.conf to puppet with sum 456ddb9d4209543dab23207931473c91

Notice: /Stage[main]/Main/File[/etc/nginx/nginx.conf]/content: content changed ‘{md5}456ddb9d4209543dab23207931473c91‘ to ‘{md5}5aeb19c0057030b2990920a929d8aed3‘

Info: /Stage[main]/Main/File[/etc/nginx/nginx.conf]: Scheduling refresh of Service[nginx]

Notice: /Stage[main]/Main/Service[nginx]: Triggered ‘refresh‘ from 1 events

Notice: Finished catalog run in 4.98 seconds

9、变量

[[email protected] mainfests]# vim test10.pp 

$webserver=nginx

package{$webserver:

ensure      =>  latest,

}

file{‘/etc/nginx/nginx.conf‘:

ensure      =>  file,

source      =>  ‘/root/modules/nginx/flies/nginx.conf‘,

require     =>  Package[‘nginx‘],

notify      =>  Service[‘nginx‘],

}

service{‘nginx‘:

ensure      =>  running,

enable      =>  true,

hasrestart  =>  true,

#restart        =>  ‘systemctl reload nginx.service‘,

require     =>  [ Package[‘nginx‘], File[‘/etc/nginx/nginx.conf‘] ],

}

[[email protected] mainfests]# puppet apply -v test10.pp 

Notice: Compiled catalog for node2 in environment production in 1.42 seconds

Info: Applying configuration version ‘1480938332‘

Notice: Finished catalog run in 18.48 seconds

[[email protected] mainfests]# systemctl stop nginx.service 

[[email protected] mainfests]# yum -y remove nginx

[[email protected] mainfests]# rm -rf /etc/nginx/

[[email protected] mainfests]# puppet apply -v test10.pp 

Notice: Compiled catalog for node2 in environment production in 1.44 seconds

Info: Applying configuration version ‘1480938505‘

Notice: /Stage[main]/Main/Package[nginx]/ensure: created

Info: Computing checksum on file /etc/nginx/nginx.conf

Info: FileBucket got a duplicate file {md5}93bc8e01bfd45e7e18b23acc178ae25b

Info: /Stage[main]/Main/File[/etc/nginx/nginx.conf]: Filebucketed /etc/nginx/nginx.conf to puppet with sum 93bc8e01bfd45e7e18b23acc178ae25b

Notice: /Stage[main]/Main/File[/etc/nginx/nginx.conf]/content: content changed ‘{md5}93bc8e01bfd45e7e18b23acc178ae25b‘ to ‘{md5}5aeb19c0057030b2990920a929d8aed3‘

Info: /Stage[main]/Main/File[/etc/nginx/nginx.conf]: Scheduling refresh of Service[nginx]

Notice: /Stage[main]/Main/Service[nginx]/ensure: ensure changed ‘stopped‘ to ‘running‘

Info: /Stage[main]/Main/Service[nginx]: Unscheduling refresh on Service[nginx]

Notice: Finished catalog run in 12.16 seconds

10、if语句

[[email protected] mainfests]# vim test11.pp

if $processorcount>1 {

notice("SMP Host.")

} else {

notice("Poor Guy.")

}   

[[email protected] mainfests]# puppet apply -v test11.pp 

Notice: Scope(Class[main]): SMP Host.

Notice: Compiled catalog for node2 in environment production in 0.10 seconds

Info: Applying configuration version ‘1480939461‘

Notice: Finished catalog run in 0.02 seconds

[[email protected] mainfests]# vim test12.pp

if $operatingsystem =~ /^(?i-mx:(centos|redhat|fedora|ubuntu))/ {

notice("Welcome to $1 distribute linux.")

}   

[[email protected] mainfests]# puppet apply -v test12.pp 

Notice: Scope(Class[main]): Welcome to CentOS distribute linux.

Notice: Compiled catalog for node2 in environment production in 0.10 seconds

Info: Applying configuration version ‘1480940033‘

Notice: Finished catalog run in 0.05 seconds

04 puppet类、模板及模块

1、类声明方式1

[[email protected] mainfests]# vim test13.pp

class nginx {

$webserver=nginx

package{$webserver:

ensure      =>  latest,

}

file{‘/etc/nginx/nginx.conf‘:

ensure      =>  file,

source      =>  ‘/root/modules/nginx/flies/nginx.conf‘,

require     =>  Package[‘nginx‘],

notify      =>  Service[‘nginx‘],

}

service{‘nginx‘:

ensure      =>  running,

enable      =>  true,

hasrestart  =>  true,

#restart        =>  ‘systemctl reload nginx.service‘,

require     =>  [ Package[‘nginx‘], File[‘/etc/nginx/nginx.conf‘] ],

}

}

include nginx

[[email protected] mainfests]# systemctl stop nginx.service 

[[email protected] mainfests]# yum -y remove nginx

[[email protected] mainfests]# rm -rf /etc/nginx/

[[email protected] mainfests]# puppet apply -v test13.pp    

Notice: Compiled catalog for node2 in environment production in 1.41 seconds

Info: Applying configuration version ‘1481026945‘

Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created

Info: Computing checksum on file /etc/nginx/nginx.conf

Info: FileBucket got a duplicate file {md5}93bc8e01bfd45e7e18b23acc178ae25b

Info: /Stage[main]/Nginx/File[/etc/nginx/nginx.conf]: Filebucketed /etc/nginx/nginx.conf to puppet with sum 93bc8e01bfd45e7e18b23acc178ae25b

Notice: /Stage[main]/Nginx/File[/etc/nginx/nginx.conf]/content: content changed ‘{md5}93bc8e01bfd45e7e18b23acc178ae25b‘ to ‘{md5}5aeb19c0057030b2990920a929d8aed3‘

Info: /Stage[main]/Nginx/File[/etc/nginx/nginx.conf]: Scheduling refresh of Service[nginx]

Notice: /Stage[main]/Nginx/Service[nginx]/ensure: ensure changed ‘stopped‘ to ‘running‘

Info: /Stage[main]/Nginx/Service[nginx]: Unscheduling refresh on Service[nginx]

Notice: Finished catalog run in 917.40 seconds

2、类声明方式2

[[email protected] mainfests]# vim test14.pp 

class nginx($webserver=‘nginx‘) {

package{$webserver:

ensure      =>  latest,

}

file{‘/etc/nginx/nginx.conf‘:

ensure      =>  file,

source      =>  ‘/root/modules/nginx/flies/nginx.conf‘,

require     =>  Package[‘nginx‘],

notify      =>  Service[‘nginx‘],

}

service{‘nginx‘:

ensure      =>  running,

enable      =>  true,

hasrestart  =>  true,

#restart        =>  ‘systemctl reload nginx.service‘,

require     =>  [ Package[‘nginx‘], File[‘/etc/nginx/nginx.conf‘] ],

}

}

class {‘nginx‘:

webserver => ‘tengine‘,

}

3、子类调用父类

[[email protected] mainfests]# vim test15.pp

class nginx {

package {‘nginx‘:

ensure  =>  latest,

} ->

service{‘nginx‘:

enable      =>  true,

ensure      =>  running,

hasrestart  =>  true,

restart     =>  ‘service nginx reload‘,

}   

}

class nginx::webserver inherits nginx {

file{‘/etc/nginx/nginx.conf‘:

source  => /root/modules/nginx/files/nginx_web.conf,

ensure  =>  file,

notify  =>  Service[‘nginx‘],

}   

}

class nginx::proxy inherits nginx {

file{‘/etc/nginx/nginx.conf‘:

source  => /root/modules/nginx/files/nginx_proxy.conf,

ensure  =>  file,

notify  =>  Service[‘nginx‘],

}   

}

include nginx::webserverclass nginx {

package {‘nginx‘:

ensure  =>  latest,

} ->

service{‘nginx‘:

enable      =>  true,

ensure      =>  running,

hasrestart  =>  true,

restart     =>  ‘service nginx reload‘,

}   

}

class nginx::webserver inherits nginx {

file{‘/etc/nginx/nginx.conf‘:

source  => ‘/root/modules/nginx/files/nginx_web.conf‘,

ensure  =>  file,

notify  =>  Service[‘nginx‘],

}   

}

class nginx::proxy inherits nginx {

file{‘/etc/nginx/nginx.conf‘:

source  => ‘/root/modules/nginx/files/nginx_proxy.conf‘,

ensure  =>  file,

notify  =>  Service[‘nginx‘],

}   

}

include nginx::webserver

[[email protected] mainfests]# cd /root/modules/nginx/flies/

[[email protected] flies]# cp nginx.conf nginx_web.conf 

[[email protected] flies]# cp nginx.conf nginx_proxy.conf

[[email protected] flies]# vim nginx_proxy.conf 

修改

location / { 

}   

location / { 

proxy_pass http://192.168.1.131/;

}   

[[email protected] mainfests]# puppet apply -v test15.pp 

Notice: Compiled catalog for node2 in environment production in 1.49 seconds

Info: Applying configuration version ‘1481031545‘

4、在子类中覆盖父类中已经定义的资源的属性值

[[email protected] mainfests]# vim test16.pp 

class nginx {

package {‘nginx‘:

ensure  =>  latest,

name    =>  nginx,

} ->

service{‘nginx‘:

enable      =>  true,

ensure      =>  running,

hasrestart  =>  true,

restart     =>  ‘service nginx reload‘,

}   

}

class nginx::webserver inherits nginx {

Package[‘nginx‘]{

name    =>  tengine,

}   

file{‘/etc/nginx/nginx.conf‘:

source  => ‘/root/modules/nginx/files/nginx_web.conf‘,

ensure  =>  file,

notify  =>  Service[‘nginx‘],

}   

}

class nginx::proxy inherits nginx {

file{‘/etc/nginx/nginx.conf‘:

source  => ‘/root/modules/nginx/files/nginx_proxy.conf‘,

ensure  =>  file,

notify  =>  Service[‘nginx‘],

}   

}

include nginx::webserver

[[email protected] mainfests]# puppet apply -v test16.pp 

Notice: Compiled catalog for node2 in environment production in 1.40 seconds

Info: Applying configuration version ‘1481112014‘

Error: /Stage[main]/Nginx::Webserver/File[/etc/nginx/nginx.conf]: Could not evaluate: Could not retrieve information from environment production source(s) file:/root/modules/nginx/files/nginx_web.conf

Error: Could not update: Execution of ‘/usr/bin/yum -d 0 -e 0 -y list tengine‘ returned 1: Error: No matching Packages to list

Error: /Stage[main]/Nginx/Package[nginx]/ensure: change from absent to latest failed: Could not update: Execution of ‘/usr/bin/yum -d 0 -e 0 -y list tengine‘ returned 1: Error: No matching Packages to list

Notice: /Stage[main]/Nginx/Service[nginx]: Dependency Package[nginx] has failures: true

Notice: /Stage[main]/Nginx/Service[nginx]: Dependency File[/etc/nginx/nginx.conf] has failures: true

Warning: /Stage[main]/Nginx/Service[nginx]: Skipping because of failed dependencies

Notice: Finished catalog run in 5.41 seconds

5、模板

[[email protected] mainfests]# cd /root/modules/nginx/files/

[[email protected] flies]# vim nginx_proxy.conf

修改

worker_processes 3;

worker_processes <%= @processorcount %>;

[[email protected] flies]# cd -

/root/mainfests

[[email protected] mainfests]# vim test16.pp 

修改

source  => ‘/root/modules/nginx/files/nginx_proxy.conf‘,

content => template(‘/root/modules/nginx/files/nginx_proxy.conf‘),

修改

include nginx::webserver

include nginx::proxy

[[email protected] mainfests]# puppet apply -v test16.pp 

Notice: Compiled catalog for node2 in environment production in 1.35 seconds

Info: Applying configuration version ‘1481113843‘

Info: Computing checksum on file /etc/nginx/nginx.conf

Info: /Stage[main]/Nginx::Proxy/File[/etc/nginx/nginx.conf]: Filebucketed /etc/nginx/nginx.conf to puppet with sum 5aeb19c0057030b2990920a929d8aed3

Notice: /Stage[main]/Nginx::Proxy/File[/etc/nginx/nginx.conf]/content: content changed ‘{md5}5aeb19c0057030b2990920a929d8aed3‘ to ‘{md5}a7a50e95d479630c400907a161a348b8‘

Info: /Stage[main]/Nginx::Proxy/File[/etc/nginx/nginx.conf]: Scheduling refresh of Service[nginx]

Notice: /Stage[main]/Nginx/Service[nginx]: Triggered ‘refresh‘ from 1 events

Notice: Finished catalog run in 22.55 seconds

6、模块

#列出可用模块

[[email protected] ~]# puppet module list

/etc/puppet/modules (no modules installed)

/usr/share/puppet/modules (no modules installed)

#查找模块

[[email protected] ~]# puppet module search nginx

#安装模块

[[email protected] ~]# puppet module install nginx

#创建模块

[[email protected] ~]# mkdir -p /etc/puppet/modules/nginx/{mainfets,files,templates,tests,lib,spec}

[[email protected] ~]# puppet module list                                                          

/etc/puppet/modules

└── nginx (???)

/usr/share/puppet/modules (no modules installed)

[[email protected] ~]# cd mainfests/

[[email protected] mainfests]# cp test16.pp /etc/puppet/modules/nginx/mainfets/init.pp

[[email protected] mainfests]# cp /root/modules/nginx/files/nginx_web.conf /etc/puppet/modules/nginx/files/

[[email protected] mainfests]# cp /root/modules/nginx/files/nginx_proxy.conf /etc/puppet/modules/nginx/templates/nginx_proxy.conf.erb

[[email protected] mainfests]# cd /etc/puppet/modules/nginx/

[[email protected] nginx]# ls

files  lib  mainfets  spec  templates  tests

[[email protected] nginx]# cd mainfets/

[[email protected] mainfets]# ls

init.pp

[[email protected] mainfets]# vim init.pp 

class nginx {

package {‘nginx‘:

ensure  =>  latest,

name    =>  nginx,

} ->

service{‘nginx‘:

enable      =>  true,

ensure      =>  running,

hasrestart  =>  true,

restart     =>  ‘service nginx reload‘,

}   

}

class nginx::webserver inherits nginx {

Package[‘nginx‘]{

name    =>  tengine,

}   

file{‘/etc/nginx/nginx.conf‘:

source  => ‘puppet:///modules/nginx/nginx_web.conf‘,

ensure  =>  file,

notify  =>  Service[‘nginx‘],

}   

}

class nginx::proxy inherits nginx {

file{‘/etc/nginx/nginx.conf‘:

content => template(‘nginx/nginx_proxy.conf.erb‘),

ensure  =>  file,

notify  =>  Service[‘nginx‘],

}   

}

[[email protected] mainfets]# systemctl stop nginx.service 

[[email protected] mainfets]# yum -y remove nginx

[[email protected] mainfets]# rm -rf /etc/nginx/

[[email protected] mainfets]# puppet apply --noop -v -e ‘include nginx::proxy‘

时间: 2024-10-17 17:36:38

45 puppet基础、资源详解、配置语言、puppet类与模板及模块的相关文章

puppet package资源详解

yum源配置 1. wget http://ftp.kaist.ac.kr/fedora//epel/6/i386/epel-release-6-8.noarch.rpm 2. yum list | grep puppet` //测试yum源配置有没有问题 NTP时间服务器配置 vi /etc/ntp.conf ----------------------- driftfile /var/lib/ntp/drift Broadcastdelay 0.008 logfile /var/log/nt

puppet file资源详解

yum源配置 1. wget http://ftp.kaist.ac.kr/fedora//epel/6/i386/epel-release-6-8.noarch.rpm 2. yum list | grep puppet` //测试yum源配置有没有问题 NTP时间服务器配置 vi /etc/ntp.conf ----------------------- driftfile /var/lib/ntp/drift Broadcastdelay 0.008 logfile /var/log/nt

Python基础知识详解 从入门到精通(七)类与对象

本篇主要是介绍python,内容可先看目录其他基础知识详解,欢迎查看本人的其他文章Python基础知识详解 从入门到精通(一)介绍Python基础知识详解 从入门到精通(二)基础Python基础知识详解 从入门到精通(三)语法与函数Python基础知识详解 从入门到精通(四)列表.元组.字典.集合Python基础知识详解 从入门到精通(五)模块管理Python基础知识详解 从入门到精通(六)文件操作PS:很多人在学习Python的过程中,往往因为遇问题解决不了或者没好的教程从而导致自己放弃,为此

Linux上命令的使用格式和基础命令详解

一.Linux上命令的使用格式 命令行提示符详解: 用户通过终端的命令行接口来控制操作系统,登陆后如下: [[email protected] ~]# root: 当前登录的用户 @:分隔符 localhost: 当前主机的主机名,非完整格式:此处的完整格式为:localhost.localdomain [[email protected] ~]# hostname localhost.localdomain ~:用户当前所在的目录(current directory),也称为工作目录(work

高性能Web服务之tomcat基础应用详解(一)

Tomcat概述: Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache.Sun 和其他一些公司及个人共同开发而成.由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat 中得到体现,Tomcat 5支持最新的Servlet 2.4 和JSP 2.0 规范.因为Tomcat 技术先进.性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目

varnish基础概念详解

varnish基础概念详解 比起squid更加轻量级,大致有以下几个特点: ·可以基于内存缓存,也可以在磁盘上缓存,但是就算存放在磁盘上,也不能实现持久缓存 只要进程崩溃,此前缓存统统失效,无论是在内存还是在磁盘,但是现在已经具备持久缓存功能,但是仍然在实验阶段,经常容易崩溃,而且最大大小不能超过1G 如果期望内存大小超过几十个G,比如图片服务器,纯粹使用内存,性能未必好,这时候可以使用磁盘进行缓存,或SSD X 2 做RAID 避免磁盘损坏,在实现随机访问上 ssd硬盘要比机械硬盘要好的多,如

Servlet基础知识详解

Servlet基础知识详解 Servlet基础知识详解 Servlet程序执行全过程 Servlet映射路径 Servlet映射练习 Servlet生命周期 为什么要学习Servlet生命周期 Servlet重要的生命周期方法 模拟通过反射构造Servlet对象 Servlet单实例多线程 Servlet留给开发者的init方法 Servlet中核心对象学习 HttpServletRequest对象 HttpServletResponse对象 ServletConfig对象 ServletCon

RabbitMQ,Apache的ActiveMQ,阿里RocketMQ,Kafka,ZeroMQ,MetaMQ,Redis也可实现消息队列,RabbitMQ的应用场景以及基本原理介绍,RabbitMQ基础知识详解,RabbitMQ布曙

消息队列及常见消息队列介绍 2017-10-10 09:35操作系统/客户端/人脸识别 一.消息队列(MQ)概述 消息队列(Message Queue),是分布式系统中重要的组件,其通用的使用场景可以简单地描述为: 当不需要立即获得结果,但是并发量又需要进行控制的时候,差不多就是需要使用消息队列的时候. 消息队列主要解决了应用耦合.异步处理.流量削锋等问题. 当前使用较多的消息队列有RabbitMQ.RocketMQ.ActiveMQ.Kafka.ZeroMQ.MetaMq等,而部分数据库如Re

Docker基础命令详解——镜像及容器操作

Docker基础命令详解--镜像及容器操作 前言 ? 上篇文章介绍了有关Docker的基础与Linux下docker的安装,本文主要讲解安装docker后的基础使用方法以及命令的介绍,主要是docker镜像操作及容器操作命令. ? 当然,docker的相关命令非常多,可以使用docker help命令查看对应目录以及相关提示命令. Docker镜像操作命令 [[email protected] ~]# which docker /usr/bin/docker 1.镜像搜索:docker sear