自动化运维工具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,如需转载请自行联系原作者

相关文章
|
4月前
|
运维 Prometheus 监控
3 年部署经验总结:用自动化工具轻松管理 300+ 服务器开源软件
三年前接手公司IT部门时,我满怀信心,却发现部署效率低下。尽管使用了GitLab、Jenkins、Zabbix等100+开源工具,部署仍耗时费力。文档厚重如百科,却难解实际困境。一次凌晨三点的加班让我下定决心改变现状。偶然看到一篇国外博客,介绍了自动化部署的高效方式,我深受启发。
196 0
|
3月前
|
机器学习/深度学习 人工智能 测试技术
EdgeMark:嵌入式人工智能工具的自动化与基准测试系统——论文阅读
EdgeMark是一个面向嵌入式AI的自动化部署与基准测试系统,支持TensorFlow Lite Micro、Edge Impulse等主流工具,通过模块化架构实现模型生成、优化、转换与部署全流程自动化,并提供跨平台性能对比,助力开发者在资源受限设备上高效选择与部署AI模型。
353 9
EdgeMark:嵌入式人工智能工具的自动化与基准测试系统——论文阅读
|
2月前
|
人工智能 搜索推荐 UED
一个牛逼的国产AI自动化工具,开源了 !
AiPy是国产开源AI工具,结合大语言模型与Python,支持本地部署。用户只需用自然语言描述需求,即可自动生成并执行代码,轻松实现数据分析、清洗、可视化等任务,零基础也能玩转编程,被誉为程序员的智能助手。
|
3月前
|
Java 测试技术 API
自动化测试工具集成及实践
自动化测试用例的覆盖度及关键点最佳实践、自动化测试工具、集成方法、自动化脚本编写等(兼容多语言(Java、Python、Go、C++、C#等)、多框架(Spring、React、Vue等))
146 6
|
4月前
|
人工智能 数据可视化 数据挖掘
团队日报不用愁!自动化生成工具亲测:任务进度实时同步
本文深入分析了传统手动日报在数据孤岛、格式混乱和时效性差三大痛点,并探讨了自动化日报带来的效率提升、决策优化等四大核心价值。通过对板栗看板、SmartBrief、n8n 等六款主流工具的功能、适用场景及实战效果进行测评,为企业提供科学的选型建议与实施路径。
团队日报不用愁!自动化生成工具亲测:任务进度实时同步
|
2月前
|
人工智能 缓存 自然语言处理
86_自动化提示:AutoPrompt工具
在当今人工智能领域,提示工程(Prompt Engineering)已成为释放大语言模型(LLM)潜能的关键技术。随着LLM规模和能力的不断增长,如何设计高效、精确的提示词成为研究和应用的焦点。然而,传统的手工提示工程面临着巨大挑战
|
4月前
|
人工智能 供应链 数据可视化
工作流梳理工具实战教程:手把手教你绘制第一张自动化流程图
本文剖析了团队因流程混乱导致重复劳动和效率低下的问题,提出通过工作流梳理提升协作效率的解决方案。总结了流程梳理的六大核心需求,并深度测评了6款主流工具,国内有板栗看板那,国外有kiss flow结合团队规模与需求提供选型建议,助力企业高效落地流程优化。
|
3月前
|
安全 搜索推荐 机器人
风险规则引擎-RPA 作为自动化依赖业务决策流程的强大工具
机器人流程自动化(RPA)是一种通过软件“机器人”自动执行重复性任务的技术,能大幅提升工作效率。它适用于财务、电商等领域的标准化流程,如账单处理和退货管理。然而,RPA在复杂决策场景中存在局限,需结合决策模型(DMN)和业务规则管理系统(BRMS)实现流程与决策的协同自动化,从而增强灵活性与业务价值。
|
4月前
|
数据采集 运维 监控

推荐镜像

更多