1. **************服务端安装软件******************
  2. shell#touch /etc/puppet/manifests/site.pp
  3. shell#cat /etc/hosts
  4. 192.168.1.254 nat.test.com
  5. shell#/etc/init.d/puppetmaster start
  6. shell#puppet cert --sign test.test.com
  7. 签发证书,需要为每一个域名单独签发
  8. **************客户端配置服务******************
  9. shell#cat /etc/hosts
  10. 192.168.1.254 nat.test.com
  11. 127.0.0.1 test.test.com
  12. shell#echo  "server = nat.test.com" >>/etc/puppet/puppet.conf
  13. shell#puppet agent --no-daemonize --verbose
  14. 服务端文件
  15. vim /etc/puppet/manifests/site.pp
  16. node default{
  17. file {"/tmp/a.txt":
  18. content => "test\n",
  19. ensure  => present,
  20. backup  => ".bak",
  21. mode    => 500,
  22. owner   => root,
  23. group   => www,
  24. }
  25. }
  26. *********************客户端测试****************************
  27. puppet agent --verbose  --test
  28. *********************服务端创建模块**************************
  29. shell#mkdir /etc/puppet/modules/snmpd/{files,manifests,templates} -p
  30. shell#vim  /etc/puppet/modules/snmpd/manifests
  31. ######################################################################################################################
  32. class snmpd {
  33. service {
  34. "snmpd":
  35. enable    => "true",
  36. ensure    => "running",
  37. require   => File["snmpd.conf"],
  38. subscribe => File["snmpd.conf"],
  39. name => $operatingsystem ? {
  40. default => "snmpd",
  41. },
  42. }
  43. package {
  44. "net-snmp":
  45. ensure => present,
  46. name => $operatingsystem ? {
  47. debian => "snmpd",
  48. ubuntu => "snmpd",
  49. default => "net-snmp",
  50. },
  51. }
  52. file {
  53. "snmpd.conf":
  54. #         owner  => root,
  55. #        group  => root,
  56. #        mode   => 644,
  57. require   => Package["net-snmp"],
  58. path    => $operatingsystem ?{
  59. default => "/etc/snmp/snmpd.conf",
  60. },
  61. }
  62. }
  63. #####################################################################################################
  64. vim /etc/puppet/manifests/site.pp
  65. node default{
  66. file {"/tmp/a.txt":
  67. content => "This is a test file date\n",
  68. ensure  => present,
  69. backup  => ".back",
  70. mode    => 500,
  71. owner   => root,
  72. group   => www,
  73. }
  74. }
  75. node 'test.test.com' {
  76. file {"/tmp/b.txt":
  77. content => "This is a test file\n",
  78. ensure  => present,
  79. backup  => ".back",
  80. mode    => 500,
  81. owner   => root,
  82. group   => root,
  83. }
  84. include snmpd  #包含创建的类
  85. }
  1. http://docs.puppetlabs.com/guides/types/service.html 原文地址
  2. service管理系统运行的服务进程,不幸的是不同的系统管理服务的方式是多样的. 有些系统上面对于服务管理很简单,有些系统提供复杂的强大的服务管理功能.puppet提供最基本的服务管理,你也可以指定provider,使用一些特性.
  3. 注意,当一个服务从另一个资源收到一个事件,服务会重启,例如配置文件修改,可以要求相应的服务重启.不同的平台重启命令不同,你也可以手工指定重启服务的命令.
  4. 特性
  5. controllable provider 提供control 变量
  6. enableable provider 可以enable和disable服务
  7. refreshable provider 可以重启服务
  8. 例子service {             "ssh":             ensure => running;            "nfs":             ensure => stopped;           }
  9. 参数binary
  10. 运行服务的命令的路径, 只用于不支持init的操作系统, 如果没有指定启动脚本,就用这个命令来启动服务.
  11. enable
  12. 服务在开机的时候是否启动,可以设置的值是true和false,需要provider支持enableable
  13. ensure
  14. 是否运行服务, running表示运行服务,stopped 表示停止服务
  15. hasrestart
  16. 指出管理脚本是否支持restart参数,如果不支持,就用stop和start实现restart效果. 可以设置的值是true 或 false
  17. hasstatus
  18. 指出管理脚本是否支持status参数,puppet用status参数来判断服务是否已经在运行了,如果不支持status参数,puppet利用查找运行进程列表里面是否有服务名来判断服务是否在运行. 可以设置的值是true或false
  19. name
  20. 该资源的namevar, 服务的名字,通常就是在/etc/init.d/目录下的名字
  21. path
  22. 启动脚本的搜索路径,可以用冒号分割多个路径,或者用数组指定.
  23. pattern
  24. 设置搜索进程列表的匹配字符串,用于不支持init脚本的系统.当要停止一个服务的时候,通过查看进程运行列表来判断.
  25. provider
  26. puppet提供下面的provider(只列出常见的系统)
  27. debian debian系统的init模式的管理脚本,支持 enableable, refreshable.
  28. freebsd init模式,支持enableable, refreshable.
  29. init 标准的init模式,支持refreshable
  30. redhat redhat的init模式,支持enableable, refreshable.
  31. smf solaris新的服务管理框架,支持enableable, refreshable
  32. restart
  33. 指定重启脚本,否则就先停止该服务再启动该服务
  34. start
  35. 指定启动服务的命令,通常init模式的管理脚本都支持,不需要手工指定
  36. status
  37. 指定status命令,如果不指定,就从进程列表查询该服务
  38. stop
  39. 指定停止服务的脚本.

http://nocap.blog.163.com/blog/static/19052507420121030113615705/

  1. 官方文档
  2. http://docs.puppetlabs.com/puppetdocs-latest.tar.gz
  3. http://www.puppetlabs.com/downloads/docs/puppet_labs_docs_pdfs.zip
  4. puppet  cert    sign    mytestagent.example.com
  5. puppet  cert    sign    --all
  6. puppet  master  --no-daemonize  --verbose
  7. puppet  --genconfig
  8. puppet  agent   --server    myserver.example.com    --waitforcert   60  --test
  9. puppet  master  --configprint   modulepath
  10. puppet  config  print   modulepath  --mode  master
  11. auth.conf
  12. autosign.conf
  13. ==========================================
  14. rebuilt.example.com
  15. *.scratch.example.com
  16. *.local
  17. ==========================================
  18. device.conf
  19. ==========================================
  20. [device certname]
  21. type    <type>
  22. url <url>
  23. [router6.example.com]
  24. type    cisco
  25. url ssh://admin:password@ef03c87a.local
  26. fileserver.conf
  27. ===========================================
  28. #   Files   in  the /path/to/files  directory   will    be  served
  29. #   at  puppet:///mount_point/.
  30. [mount_point]
  31. path    /path/to/files
  32. allow   *.example.com
  33. deny    *.wireless.example.com
  34. ===========================================
  35. tagmail.conf
  36. require
  37. Set  report=true  on your agent nodes
  38. Set  reports=tagmail
  39. Set  the  reportfrom  email address and either  the  smtpserver  or  sendmail  setting on  the puppet master
  40. Create a  tagmail.conf  file at  the  location specified  in  the   tagmap  setting
  41. ocated at   /etc/puppet/tagmail.conf  by default
  42. A comma-separated  list of  tags and  !negated  tags;  valid  tags  include:
  43. Explicit  tags
  44. Class names
  45. Puppet Documentation ? Configuring Puppet 40/411
  46. “ all ”
  47. Any valid Puppet  log  level  ( debug ,   info ,   notice ,   warning ,   err ,   alert ,   emerg ,   crit ,  or
  48. verbose )
  49. A colon
  50. A comma-separated  list of email addresses
  51. The  list of  tags on a  line builds  the set of  resources whose messages will be  included  in  the mailing;
  52. each additional  tag adds  to  the set,  and each  !negated  tag subtracts  from  the set.
  53. So,   for example:
  54. ==============================================================================================
  55. all:    log-archive@example.com
  56. webserver,  !mailserver:    httpadmins@example.com
  57. emerg,  crit:   james@example.com,  zach@example.com,   ben@example.com
  58. ==============================================================================================
  59. service {   'sshd':
  60. subscribe   =>  File['sshdconfig'],
  61. }
  62. define  svn_repo($path) {
  63. exec    {   "/usr/bin/svnadmin  create  ${path}/${title}":
  64. unless  =>  "/bin/test  -d  ${path}",
  65. }
  66. }
  67. svn_repo    {   'puppet_repo':  path    =>  '/var/svn_puppet'   }
  68. svn_repo    {   'other_repo':       path    =>  '/var/svn_other'    }
  69. define  svn_repo($path) {
  70. exec   {   "create_repo_${name}":
  71. command    =>  "/usr/bin/svnadmin  create  ${path}/${title}",
  72. unless     =>  "/bin/test  -d  ${path}",
  73. }
  74. if $require    {
  75. Exec["create_repo_${name}"]    {
  76. require    +>  $require,
  77. }
  78. }
  79. }
  80. svn_repo    {   'puppet':
  81. path               =>  '/var/svn',
  82. Puppet Documentation ? Language Guide 50/411
  83. require    =>  Package['subversion'],
  84. }
  85. 变量赋值
  86. $value  =   "${one}${two}"
  87. 数组
  88. $foo    =[ 'one', 'two', 'three' ]
  89. notice  $foo[1]
  90. 将返回 two
  91. host { 'one.example.com':
  92. ensure =>  present,
  93. alias  =>  [ 'satu','dua', 'tiga'  ],
  94. ip =>  '192.168.100.1',
  95. }
  96. 哈希
  97. $myhash ={ key1 => 'myval', key2 => $b  }
  98. 访问hash元素
  99. $myhash ={ key  => { subkey => 'b' }}
  100. notice($myhash[key][subkey])
  101. 节点赋不同的值
  102. =========================================================
  103. node    a   {
  104. $setting    =   'this'
  105. include class_using_setting
  106. }
  107. node    b   {
  108. $setting    =   'that'
  109. include class_using_setting
  110. }
  111. =========================================================
  112. calss的设置
  113. =========================================================================================
  114. $test   =   'top'
  115. class   myclass {
  116. exec    {   "/bin/echo  ${test}":   logoutput   =>  true    }
  117. }
  118. class   other   {
  119. $test   =   'other'
  120. include myclass
  121. }
  122. include other
  123. ===========================================================================================
  124. 访问class里面的值
  125. ========================================================
  126. class   myclass {
  127. $test   =   'content'
  128. }
  129. class   anotherclass    {
  130. $other  =   $myclass::test
  131. }
  132. ========================================================
  133. 给变量中的数组增加元素
  134. ==========================================================================
  135. $ssh_users  =   [   'myself',   'someone'   ]
  136. class   test    {
  137. $ssh_users  +=  ['someone_else']
  138. }
  139. ===========================================================================
  140. 这里的+=是给数组增加值
  141. 变量选择相关
  142. file{ '/etc/config':
  143. owner     =>    $operatingsystem ? {
  144. 'sunos'   =>    'adm',
  145. 'redhat'  =>    'bin',
  146. default   =>    undef,
  147. },
  148. }
  149. 默认值为undef,
  150. $owner=$operatingsystem ? {
  151. /(redhat|debian)/=>'bin',
  152. default          =>undef,
  153. }
  154. $system=$operatingsystem ? {
  155. /(redhat|debian)/ => "our system  is $1",
  156. default           => "our system  is unknown",
  157. }
  158. 这里的$1将会返回redhat或者debian
  159. $0将会返回整行
  160. case
  161. =====================================================================================================
  162. case    $operatingsystem {
  163. 'sunos':    {   include solaris }   #   apply   the solaris class
  164. 'redhat':   {   include redhat  }   #   apply   the redhat  class
  165. default:    {   include generic }   #   apply   the generic class
  166. }
  167. ====================================================================================================
  168. =======================================================================================================
  169. case    $hostname {
  170. 'jack','jill':       {  include hill    }   #   apply   the hill    class
  171. 'humpty','dumpty':   {  include wall    }   #   apply   the wall    class
  172. default:         {  include generic }   #   apply   the generic class
  173. }
  174. ========================================================================================================
  175. 如果v$hostname fact里面含有jack或者jill,那么将会include  hill
  176. ========================================================================================================
  177. case    $hostname   {
  178. /^j(ack|ill)$/: {  include  hill   }    #   apply   the hill    class
  179. /^[hd]umpty$/:  {  include  wall   }    #   apply   the wall    class
  180. default:        {  include generic }    #   apply   the generic class
  181. }
  182. ===========================================================================================================
  183. case    $hostname  {
  184. /^j(ack|ill)$/: { notice("Welcome $1!") }
  185. default:    { notice("Welcome stranger")    }
  186. }
  187. ===========================================================================================================
  188. if $variable {
  189. file { '/some/file':   ensure  => present }
  190. }  else {
  191. file { '/some/other/file': ensure  => present }
  192. }
  193. ============================================================================================================
  194. if  $server == 'mongrel'    {
  195. include mongrel
  196. } elsif $server ==  'nginx' {
  197. include nginx
  198. }   else    {
  199. include thin
  200. }
  201. if  $ram    >   1024    {
  202. $maxclient = 500
  203. }
  204. =============================================================================================================
  205. if ( $processor_count > 2 ) and ((  $ram >= 16 * $gigabyte  ) or ( $disksize > 1000 )) {
  206. include for_big_irons
  207. } else {
  208. include  for_small_box
  209. }
  210. ================================================================================================================
  211. unless  $memorysize >   1024    {
  212. $maxclient  =   500
  213. }
  214. ================================================================================================================
  215. 虚拟资源
  216. @user   {   'luke': ensure  =>  present }
  217. User    <|  title   ==  luke    |>
  218. realize User['luke']
  219. #将虚拟资源实例化
  220. class   ssh {
  221. @@sshkey    {   $hostname:  type    =>  dsa,    key =>  $sshdsakey  }
  222. Sshkey  <<| |>>
  223. }
  224. 正则表达式
  225. 安装module
  226. puppet  module  install puppetlabs-apache   --version   0.0.2
  227. puppet  module  list
  228. puppet  module  search  apache
  229. puppet  module  uninstall   puppetlabs-apache
  230. puppet  module  upgrade puppetlabs-apache   --version   0.0.3
  231. https://forge.puppetlabs.com
  232. 当一个文件改变的时候如何运行一个命令
  233. ===============================================================================================
  234. file    {   "/etc/bind":    source  =>  "/dist/apps/bind"   }
  235. exec    {   "/usr/bin/ndc   reload":
  236. subscribe   =>  File["/etc/bind"],
  237. refreshonly =>  true
  238. }
  239. ==============================================================================================
  240. 如何确保创建一个用户之前另一个组已经存在
  241. group   {   "fearme":
  242. ensure  =>  present,
  243. gid =>  1000
  244. }
  245. user    {   "tim":
  246. ensure  =>  present,
  247. gid =>  "fearme",
  248. groups  =>  ["adm", "staff",    "root"],
  249. membership  =>  minimum,
  250. shell   =>  "/bin/bash",
  251. require =>  Group["fearme"]
  252. }
  253. class   base_class  {
  254. define  testvar_file($myvar="bob")  {
  255. file    {   $name:
  256. content =>  template("john.erb"),
  257. }
  258. }
  259. testvar_file    {   "/tmp/testvar": }
  260. }
  261. class   child_class inherits    base_class  {
  262. Base_class::Testvar_file["/tmp/testvar"]    {   myvar   =>  fred    }
  263. }
  264. gem install rack
  265. gem install passenger
  266. passenger-install-apache2-module

本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1134203,如需转载请自行联系原作者

自动化运维工具puppet学习笔记之基础篇相关推荐

  1. 自动化运维工具Puppet(管理资源)

    接上文<自动化运维工具Puppet>http://kaliarch.blog.51cto.com/8966921/1973736 利用模块与模版管理agent端资源 一.模块管理 环境安装 ...

  2. 自动化运维工具——puppet详解(二)

    自动化运维工具--puppet详解(二) 目录 一.class 类 1)什么是类? 2)带有参数的类 3)类的继承 1.新增属性 2.新增原有值 3.修改原有值 4.整体调用父类,并重写部分值 二.模 ...

  3. 项目10.2-企业级自动化运维工具---puppet详解

    1.认识puppet 1.1 引入 puppet是什么,咱们先不用专业的名词解释它,咱们先描述一些工作场景,看明白这些工作场景,自然会知道puppet是什么. (1)场景一: 管理员想要在100台服务 ...

  4. 自动化运维工具ansible学习+使用ansible批量推送公钥到远程主机

    原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 .作者信息和本声明.否则将追究法律责任. 目录: 一.ansible简介 1.1.ansible是什么 1.2.ansible如何工作 ...

  5. 自动化运维工具ansible学习+使用ansible批量推送公钥到远程主机[学习马哥]

    目录: 一.ansible简介 1.1.ansible是什么 1.2.ansible如何工作 1.3.ansible优缺点 1.4.ansible安装方式 1.5.ansible文件简单介绍 1.6. ...

  6. 自动化运维工具——puppet详解(一)

    一.puppet 介绍 1.puppet是什么 puppet是一个IT基础设施自动化管理工具,它能够帮助系统管理员管理基础设施的整个生命周期: 供应(provisioning).配置(configur ...

  7. 自动化运维工具—puppet详解

    文章目录 一.puppet 介绍 1.puppet是什么 2.puppet的工作机制 1)工作模型 2)工作流程 3)使用模型 3.puppet 名词解释 二.puppet 资源详解 1.程序安装及环 ...

  8. 自动化运维工具puppet(四)

    一.节点管理 1.什么是节点 我们将Puppet的每个客户端都称为节点( node) . 每个节点件定义主机名时可以是个. 组 ( 正则或继承) . 所有的节点都需要在站点件( site.pp) 中进 ...

  9. 自动化运维工具puppet(1)

    puppet模块管理 模块是puppet的最大单元,模块里面有类,类下面有资源. puppet管理的文件.用户.服务.任务计划等全部由这些单元组成. 下面我们来定义一个模块: 在服务端上做如下操作: ...

  10. 52.puppet自动化运维工具

    puppet自动化运维工具 Puppet是一款运维自动化工具,在一些大型的互联网企业,它可以针对多台服务器进行统一操作,如统一部署软件,进行统一上线维护等,意思就是说在一台linux服务器上所部署的操 ...

最新文章

  1. vue Element-ui 表格自带筛选框自定义高度
  2. 【组队学习】【23期】Datawhale深度推荐模型
  3. php 效率最高的递归,PHP 递归效率分析_PHP教程 - microtime
  4. 皮猜按下谷歌招聘暂停键,疫情之下,「紧日子」来了
  5. 死磕Java并发:J.U.C之并发工具类:CyclicBarrier
  6. python 转短链接_使用Python生成url短链接的方法
  7. 大型网站技术架构文摘
  8. 【差分隐私组合定理,直方图,列联表代码实现】差分隐私代码实现系列(五)
  9. Java并发编程实战笔记—— 并发编程1
  10. 2362:数字游戏(小k和小p的传奇)
  11. 乐博Android客户端(新浪微博)1.01发布,欢迎各位童鞋试用
  12. 如何发布自己的npm包(超详细步骤,博主都在用)
  13. 避坑14_此浏览器或应用可能不安全。了解详情请尝试使用其他浏览器。
  14. Mysql Where条件执行顺序是从左到右
  15. c语言字符串的题库,C考试系统题库含答案程序题
  16. 模拟登陆广西科技大学正方教务系统
  17. 加班两年只赚2千块:低姿态的人,挣不了大钱
  18. u盘无法linux,Linux 3.18U盘无法正确使用
  19. Cris 的Python日记(三):循环语句
  20. SAP寄售采购的原料可以发给加工商做外协加工吗?

热门文章

  1. oracle获取本月天数,Oracle查询日期所属月份的天数
  2. 【转载】社会网络中心性度量
  3. ZCMU-1345: 国际象棋
  4. cpu性能测试软件 国际象棋,国际象棋测试
  5. C语言火车订票系统开发
  6. 使用SPSS对数据异常值进行探索分析
  7. 为什么没写Feedsky话题广告
  8. matlab 图像处理之边缘提取
  9. PHP获取每月第一天与最后一天
  10. 2010年1月高等教育国际金融全国统一命题考试