Chinaunix首页 | 论坛 | 博客
  • 博客访问: 32293
  • 博文数量: 9
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-27 11:03
文章分类

全部博文(9)

文章存档

2015年(9)

我的朋友

分类: LINUX

2015-10-27 11:34:21

 什么是Puppet

  1. 一种集中管理配置和服务的工具;
  2. 语法简单,易学易用,基于Ruby开发,但Ruby不是必备技能
  3. C/S模式         
        Puppet工作原理  
        puppet工作细节分以下几个步骤:
  1. Node节点将Facts和本机信息发送给Master
  2. Master告诉Node节点应该如何配置,将这些信息写入Catalog后传给Node
  3. Node节点在本机进行代码解析验证并执行,将结果反馈给Master
  4. Master将Node的执行结果写入日志



        Puppet安装和配置

安装
  1. wget http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm
  2. yum localinstall puppetlabs-release-6-7.noarch.rpm
  3. yum update
  4. rpm -qa |grep puppet
  5. puppetlabs-release-6-11.noarch
  6. yum search puppet
  7. yum install puppet-server.noarch puppet.noarch
  8. vi puppet.conf
  9. service puppetmaster start
  10.     Starting puppetmaster: [ OK ]        
puppet目录结构

点击(此处)折叠或打开

  1. tree
  2. .
  3. ├── auth.conf #ACL权限控制文件
  4. ├── environments    #
  5. │   └── example_env
  6. │   ├── manifests
  7. │   ├── modules
  8. │   └── README.environment
  9. ├── fileserver.conf    #文件服务配置文件
  10. ├── manifests        #节点存储目录
  11. │   ├── bashrc.pp
  12. │   └── nginx.pp
  13. ├── modules        #模块配置目录
  14. └── puppet.conf    #puppet主配置文件
puppet核心配置文件详解

点击(此处)折叠或打开

  1. cat /etc/puppet/puppet.conf
  2. [main]
  3. vardir = /var/lib/puppet
  4. confdir = /etc/puppet
  5. logdir = /var/log/puppet
  6. rundir = /var/run/puppet
  7. modulepath = $confdir/modules:/etc/puppet/modules
  8. autoflush = true
  9. ssldir      = $vardir/ssl
  10. report = true
  11. configtimeout = 360
  12. pluginsync = true       #插件同步配置对facter自定义有效
  13. [master]
  14. manifestdir = /etc/puppet/manifests
  15. manifest = /etc/puppet/manifests/site.pp
  16. user = puppet
  17. reports = log, store   #报告的方式与类型
  18. reportdir = /etc/puppet/report #报告文件生产目录

  19. [agent]
  20. classfile = $vardir/classes.txt
  21. localconfig = $vardir/localconfig
  22. authconfig = $confdir/namespaceauth.conf
  23. user = root
  24. runinterval = 1800        #客户端默认探测时间
  25. listen      = true        #是否监听,执行puppet kick时需要配置
  26. server      = master.test.com

点击(此处)折叠或打开

  1. cat /etc/puppet/auth.conf

  2. path /facts
  3. auth yes
  4. method find, search
  5. allow agent01.test.com

  6. #允许主机名为”agent01.test.com”的客户端在facts目录进行find和search操作
   
     Puppet命令

点击(此处)折叠或打开

  1. puppet resource file /root/.bashrc
  2. file { '/root/.bashrc':
  3.   ensure => 'file',
  4.   content => '{md5}c36f10fd0ff59c3b222228d7a7a6c410',
  5.   ctime => 'Tue Mar 05 16:58:33 +0800 2013',
  6.   group => '0',
  7.   mode => '644',
  8.   mtime => 'Thu Sep 23 11:59:52 +0800 2004',
  9.   owner => '0',
  10.   type => 'file',
  11. }

  12. vi bashrc.pp
  13. file { '/tmp/bashrc':
  14.   ensure => 'file',
  15.   content => "123\n",
  16.   group => '0',
  17.   mode => '644',
  18.   owner => '0',
  19. }

  20. puppet apply bashrc.pp

  21. puppet resource package ntp
  22. package { 'ntp':
  23.   ensure => '4.2.6p5-1.el6',
  24. }



  25. puppet resource service sshd
  26. service { 'sshd':
  27.   ensure => 'running',
  28.   enable => 'true',
  29. }

        创建第一个Puppet配置

点击(此处)折叠或打开

  1. rpm -qa |grep nginx

  2. ps -ef |grep nginx
  3. root 6554 4188 0 15:43 pts/0 00:00:00 grep nginx

  4. vi nginx.pp
  5. package { 'nginx':
  6.   ensure => 'present',
  7. }

  8. service { 'nginx':
  9.   ensure => 'running',
  10.   enable => 'true',
  11. }

  12. puppet apply nginx.pp
  13. Notice: Compiled catalog for master.test.com in environment production in 0.31 seconds
  14. Notice: /Stage[main]/Main/Package[nginx]/ensure: created
  15. Notice: /Stage[main]/Main/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
  16. Notice: Finished catalog run in 14.87 seconds

  17. ps -ef |grep nginx
  18. root 6789 1 0 15:45 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
  19. nginx 6790 6789 0 15:45 ? 00:00:00 nginx: worker process
  20. root 6795 4188 0 15:45 pts/0 00:00:00 grep nginx





阅读(930) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:MongoDB入门一

给主人留下些什么吧!~~