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

简介:
 
  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. **************客户端配置服务****************** 
  10. shell#cat /etc/hosts 
  11.   192.168.1.254 nat.test.com 
  12.   127.0.0.1 test.test.com 
  13. shell#echo  "server = nat.test.com" >>/etc/puppet/puppet.conf 
  14. shell#puppet agent --no-daemonize --verbose 
  15.  
  16. 服务端文件 
  17. vim /etc/puppet/manifests/site.pp  
  18. node default{ 
  19. file {"/tmp/a.txt": 
  20.      content => "test\n", 
  21.      ensure  => present, 
  22.      backup  => ".bak", 
  23.      mode    => 500, 
  24.      owner   => root, 
  25.      group   => www, 
  26.      } 
  27.  
  28.  
  29. *********************客户端测试**************************** 
  30. puppet agent --verbose  --test 
  31.  
  32. *********************服务端创建模块************************** 
  33. shell#mkdir /etc/puppet/modules/snmpd/{files,manifests,templates} -p 
  34. shell#vim  /etc/puppet/modules/snmpd/manifests 
  35. ###################################################################################################################### 
  36. class snmpd { 
  37.     service { 
  38.         "snmpd": 
  39.         enable    => "true", 
  40.         ensure    => "running", 
  41.         require   => File["snmpd.conf"], 
  42.         subscribe => File["snmpd.conf"], 
  43.         name => $operatingsystem ? { 
  44.             default => "snmpd", 
  45.             }, 
  46.     } 
  47.  
  48.     package { 
  49.         "net-snmp": 
  50.         ensure => present, 
  51.         name => $operatingsystem ? { 
  52.             debian => "snmpd", 
  53.             ubuntu => "snmpd", 
  54.             default => "net-snmp", 
  55.             }, 
  56.     } 
  57.      
  58.     file { 
  59.         "snmpd.conf": 
  60. #         owner  => root, 
  61. #        group  => root, 
  62. #        mode   => 644, 
  63.         require   => Package["net-snmp"], 
  64.         path    => $operatingsystem ?{ 
  65.                default => "/etc/snmp/snmpd.conf", 
  66.                }, 
  67.     } 
  68.  
  69. ##################################################################################################### 
  70.  
  71. vim /etc/puppet/manifests/site.pp 
  72. node default{ 
  73. file {"/tmp/a.txt": 
  74.      content => "This is a test file date\n", 
  75.      ensure  => present, 
  76.      backup  => ".back", 
  77.      mode    => 500, 
  78.      owner   => root, 
  79.      group   => www, 
  80.      } 
  81. node 'test.test.com' { 
  82. file {"/tmp/b.txt": 
  83.      content => "This is a test file\n", 
  84.      ensure  => present, 
  85.      backup  => ".back", 
  86.      mode    => 500, 
  87.      owner   => root, 
  88.      group   => root, 
  89.      } 
  90. include snmpd  #包含创建的类 

 

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

 

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

相关文章
|
1天前
|
运维 关系型数据库 MySQL
Ansible自动化运维工具主机清单配置
Ansible自动化运维工具主机清单配置
一键自动化博客发布工具,用过的人都说好(segmentfault篇)
使用一键自动化博客发布工具blog-auto-publishing-tools把博客发布到segmentfault上。
|
2天前
|
测试技术 API
探索软件测试中的自动化工具与挑战
本文探讨了软件测试领域中自动化工具的应用与挑战。通过分析目前主流的自动化测试工具,探讨了其在提高测试效率、减少人工成本、增强测试覆盖率等方面的优势。然而,自动化测试也面临着诸如脆弱性、维护成本高等挑战。最后,提出了一些应对挑战的建议,以期为软件测试领域的自动化工作提供一些启示。
9 1
|
4天前
|
Web App开发 JSON 数据格式
一键自动化博客发布工具,chrome和firfox详细配置
blog-auto-publishing-tools博客自动发布工具现在已经可以同时支持chrome和firefox了.
一键自动化博客发布工具,chrome和firfox详细配置
|
7天前
|
敏捷开发 监控 测试技术
探索自动化测试工具Selenium Grid的高效集成策略
【4月更文挑战第30天】在现代Web应用的快速迭代和持续部署中,测试自动化已成为确保产品质量的关键。Selenium Grid作为一款支持多种浏览器和操作系统的测试工具,提供了并行执行测试用例的能力,极大地提升了测试效率。本文将深入探讨如何高效地将Selenium Grid集成到现有的测试框架中,以及实施过程中的最佳实践,帮助团队最大化测试覆盖率,同时降低资源消耗。
|
8天前
|
中间件 测试技术 API
探索自动化测试工具的新边界:Selenium与Appium的集成实践
【4月更文挑战第30天】 随着移动应用和Web应用的不断融合,传统的自动化测试工具需要适应新的测试环境。本文将详细分析Selenium和Appium这两款流行的自动化测试工具的集成实践,探讨如何构建一个能够同时支持Web和移动端应用的自动化测试框架。通过对比两者的技术架构、功能特性以及在实际项目中的集成过程,我们旨在为读者提供一个清晰的指导,帮助他们在复杂的应用环境中实现高效、稳定的自动化测试流程。
|
8天前
|
弹性计算 运维 Shell
自动化网络扫描工具发现活跃主机
【4月更文挑战第30天】
8 0
|
8天前
|
Web App开发
一键自动化博客发布工具,用过的人都说好(简书篇)
给大家推荐一个一键自动化博客发布工具,完全的一键操作,让你轻松告别手动发布博客的烦恼。
|
8天前
|
机器学习/深度学习 人工智能 机器人
深入理解自动化测试:框架、工具与实践
【4月更文挑战第30天】 在现代软件开发周期中,自动化测试已成为确保产品质量和加速市场交付的关键环节。本文将探讨自动化测试的核心框架、常用工具以及实际应用的最佳实践,旨在为软件测试工程师提供深入的理解和有效的策略,以改进其自动化测试流程。我们将分析几种流行的测试自动化框架,包括Selenium、Appium和JUnit,并讨论如何根据项目需求选择适合的工具。此外,文中还将介绍持续集成(CI)环境下的自动化测试策略,以及如何通过测试结果分析和报告来优化测试过程。目标是帮助读者构建更健壮、更高效的自动化测试系统。
|
8天前
|
IDE 测试技术 持续交付
探索自动化测试工具Selenium的高效应用
【4月更文挑战第29天】 在快速迭代的软件开发过程中,高效的测试策略是确保产品质量的关键。本文将深入探讨如何利用自动化测试工具Selenium来提高软件测试的效率和准确性。通过介绍Selenium的核心功能、脚本编写技巧以及与持续集成环境的集成方法,我们旨在为读者提供一个全面的Selenium应用指南。此外,我们还将讨论常见的问题解决策略,并通过案例分析展示如何有效地运用Selenium进行复杂的Web应用测试。

热门文章

最新文章