Puppet基础篇9-Puppetmaster多环境配置

零基础学习Puppet自动化配置管理系列文档

扩充现有架构环境是对一个企业成长的见证

将基础环境模块部署到puppetmaster端之后就可以初始化所有节点了,接下来就是部署应用代码了。众所周知,一个企业中应用代码的编写并不是运维一个人完成的,而且代码的上线也不是一次性完成的。标准的架构应该由开发、测试、生产三个组成,对应到puppetmaster里面应该有3套代码才对。而且每套代码都应该对应到自己的环境中,而代码的变更更应该通过版本控制工具进行管理,比如svn、git等。 接下来我们为puppetmaster创造3个环境,它们分别是开发环境(kissdev)、测试环境(kissqa)、生产环境(kissprd).

1、配置puppet.conf

在标签[master]中添加environments环境,其次创建对应的环境标签及配置

[root@puppetmaster ~]# vim /etc/puppet/puppet.conf
[main]logdir = /var/log/puppetrundir = /var/run/puppetssldir = $vardir/ssl
[agent]classfile = $vardir/classes.txtlocalconfig = $vardir/localconfigserver = puppetmaster.kisspuppet.comcertname = puppetmaster_cert.kisspuppet.com
[master]certname = puppetmaster.kisspuppet.comenvironments = kissdev,kisstmq,kissprd  #添加三个环境的标签名称
[kissdev]
modulepath = $confdir/environments/kissdev/environment/modules:$confdir/environments/kissdev/application/modules  #设置环境的搜索路径
manifest = $confdir/environments/kissdev/manifests/site.pp  #设置环境的site.pp文件位置
fileserverconfig = /etc/puppet/fileserver.conf.kissdev  #设置环境的fileserver
[kissmq]
modulepath = $confdir/environments/kissmq/environment/modules:$confdir/environments/kisstest/application/modules
manifest = $confdir/environments/kisstest/manifests/site.pp
fileserverconfig = /etc/puppet/fileserver.conf.kisstest
[kissprd]
modulepath = $confdir/environments/kissprd/environment/modules:$confdir/environments/kissprd/application/modules
manifest = $confdir/environments/kissprd/manifests/site.pp
fileserverconfig = /etc/puppet/fileserver.conf.kissprd

顺便解释一下:为什么在每个环境下会有environment和application两个目录,其中environment目录是存放基础环境模块的,比如puppet、yum等;而application目录是存在应用环境模块的,比如apache、mysql等。当然也可以放在同一个目录下,如果应用多的话还可以将application进行拆分,一切都是为了方便管理而考虑。

2、创建多环境目录结构

[root@puppetmaster environments]# mkdir kissdev
[root@puppetmaster environments]# mkdir kissdev/{application/modules,environment/modules} -p
[root@puppetmaster environments]# tree .
.
└── kissdev├── application│   └── modules   #存放应用的模块└── environment└── modules  #存放基础环境模块
5 directories, 0 files
[root@puppetmaster environments]# cp kissdev kissmq -rp
[root@puppetmaster environments]# cp kissdev kissprd -rp
[root@puppetmaster environments]# tree .
.
├── kissdev
│   ├── application
│   │   └── modules
│   └── environment
│       └── modules
├── kissmq
│   ├── application
│   │   └── modules
│   └── environment
│       └── modules
└── kissprd├── application│   └── modules└── environment└── modules
15 directories, 0 files

3、移动默认环境modules中的配置到kissprd对应的环境中

其中puppet和yum模块属于基础环境模块,motd属于应用环境模块

[root@puppetmaster environments]# mv /etc/puppet/modules/puppet kissprd/environment/modules/
[root@puppetmaster environments]# mv /etc/puppet/modules/yum  kissprd/environment/modules/
[root@puppetmaster environments]# mv /etc/puppet/modules/motd kissprd/application/modules/

4、复制manifests文件至kissprd环境中

[root@puppetmaster environments]# cp /etc/puppet/manifests kissprd/ -r

复制完成后整个环境如下

[root@puppetmaster environments]# tree kissprd/
kissprd/
├── application
│   └── modules
│       └── motd
│           ├── files
│           │   └── etc
│           │       └── motd
│           ├── manifests
│           │   └── init.pp
│           └── templates
├── environment
│   └── modules
│       ├── puppet
│       │   ├── files
│       │   ├── manifests
│       │   │   ├── config.pp
│       │   │   ├── init.pp
│       │   │   ├── install.pp
│       │   │   ├── params.pp
│       │   │   └── service.pp
│       │   └── templates
│       │       └── puppet.conf.erb
│       └── yum
│           ├── files
│           │   ├── etc
│           │   │   └── yum.conf
│           │   └── PM-GPG-KEY
│           │       ├── RPM-GPG-KEY-puppet-release
│           │       ├── RPM-GPG-KEY-redhat-release-rhel5
│           │       └── RPM-GPG-KEY-redhat-release-rhel6
│           ├── manifests
│           │   ├── config.pp
│           │   ├── init.pp
│           │   ├── install.pp
│           │   └── params.pp
│           └── templates
└── manifests└── site.pp
20 directories, 17 files

5、删除掉默认环境manifests中site.pp文件内容

因为模块已经移除,其次默认环境production已经不再使用了。

[root@puppetmaster environments]# >/etc/puppet/manifests/site.pp

6、创建fileserverconfig文件

[root@puppetmaster ~]# cp /etc/puppet/fileserver.conf{,.kissdev}
[root@puppetmaster ~]# cp /etc/puppet/fileserver.conf{,.kissqa}
[root@puppetmaster ~]# cp /etc/puppet/fileserver.conf{,.kissprd}
[root@puppetmaster ~]# ll /etc/puppet/
total 88
-rw-r--r-- 1 root root  2569 Jan  7 07:51 auth.conf
-rw-r--r-- 1 root root    17 Mar  9 17:54 autosign.conf.bak
drwxr-xr-x 5 root root  4096 Mar 27 22:33 environments
-rw-r--r-- 1 root root   381 Jan  7 07:49 fileserver.conf
-rw-r--r-- 1 root root   381 Mar 27 22:46 fileserver.conf.kissdev  #指向kissdev环境
-rw-r--r-- 1 root root   381 Mar 27 22:46 fileserver.conf.kissprd  #指向kissmq环境
-rw-r--r-- 1 root root   381 Mar 27 22:46 fileserver.conf.kissqa   #指向kissdev环境
drwxr-xr-x 2 root root  4096 Mar 25 05:23 manifests
drwxr-xr-x 2 root root  4096 Mar 27 22:40 modules
-rw-r--r-- 1 root root  1063 Mar 27 21:55 puppet.conf
-rw-r--r-- 1 root root   853 Mar  9 00:48 puppet.conf.bak
-rw-r--r-- 1 root root 42031 Mar  9 03:25 puppet.conf.out

7、重启puppetmaster服务

[root@puppetmaster ~]# /etc/init.d/puppetmaster restart
Stopping puppetmaster:                                     [  OK  ]
Starting puppetmaster:                                     [  OK  ]

8、节点测试验证

[root@agent1 ~]# >/etc/motd
You have new mail in /var/spool/mail/root
[root@agent1 ~]# puppet agent -t  #默认请求的是production环境,由于此环境里面没有模块所有不更新
info: Caching catalog for agent1_cert.kisspuppet.com
info: Applying configuration version '1395931884'
notice: Finished catalog run in 0.02 seconds
[root@agent1 ~]# puppet agent -t --environment=kissprd  #环境指向kissprd
info: Caching catalog for agent1_cert.kisspuppet.com
info: Applying configuration version '1395931962'
notice: /Stage[main]/Motd/File[/etc/motd]/content:
--- /etc/motd    2014-03-27 22:52:27.000000000 +0800
+++ /tmp/puppet-file20140327-26204-29bst1-0    2014-03-27 22:52:44.000000000 +0800
@@ -0,0 +1,3 @@
+--                       --
+--------puppet test---------
+--                       --
info: FileBucket got a duplicate file {md5}d41d8cd98f00b204e9800998ecf8427e
info: /Stage[main]/Motd/File[/etc/motd]: Filebucketed /etc/motd to puppet with sum d41d8cd98f00b204e9800998ecf8427e
notice: /Stage[main]/Motd/File[/etc/motd]/content: content changed '{md5}d41d8cd98f00b204e9800998ecf8427e' to '{md5}87ea3a1af8650395038472457cc7f2b1'
notice: Finished catalog run in 0.68 seconds
[root@agent1 ~]# cat /etc/motd
--                       --
--------puppet test---------
--                       --

9、节点更改环境

如果节点是主动同步的方式,应该在puppet.conf文件中添加environment配置

[root@agent1 ~]# vim /etc/puppet/puppet.conf
### config by  puppet ###
[main]logdir = /var/log/puppetrundir = /var/run/puppetssldir = $vardir/ssl
[agent]classfile = $vardir/classes.txtlocalconfig = $vardir/localconfigserver = puppetmaster.kisspuppet.comcertname = agent1_cert.kisspuppet.comruninterval = 10environment =kissprd   #添加默认环境为kissprd

10、继续测试

[root@agent1 ~]# puppet agent -t
info: Caching catalog for agent1_cert.kisspuppet.com
info: Applying configuration version '1395931962'
notice: /Stage[main]/Motd/File[/etc/motd]/content:
--- /etc/motd    2014-03-27 22:55:43.000000000 +0800
+++ /tmp/puppet-file20140327-30010-8ada2g-0    2014-03-27 22:56:19.000000000 +0800
@@ -0,0 +1,3 @@
+--                       --
+--------puppet test---------
+--                       --
info: FileBucket got a duplicate file {md5}d41d8cd98f00b204e9800998ecf8427e
info: /Stage[main]/Motd/File[/etc/motd]: Filebucketed /etc/motd to puppet with sum d41d8cd98f00b204e9800998ecf8427e
notice: /Stage[main]/Motd/File[/etc/motd]/content: content changed '{md5}d41d8cd98f00b204e9800998ecf8427e' to '{md5}87ea3a1af8650395038472457cc7f2b1'
notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content:
--- /etc/puppet/puppet.conf    2014-03-27 22:56:14.000000000 +0800
+++ /tmp/puppet-file20140327-30010-cmjg48-0    2014-03-27 22:56:19.000000000 +0800
@@ -10,4 +10,3 @@server = puppetmaster.kisspuppet.comcertname = agent1_cert.kisspuppet.comruninterval = 10
-    environment =kissprd
info: FileBucket got a duplicate file {md5}43df60b1aa2638c5f10aa7e6be892b77
info: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Filebucketed /etc/puppet/puppet.conf to puppet with sum 43df60b1aa2638c5f10aa7e6be892b77
notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content: content changed '{md5}43df60b1aa2638c5f10aa7e6be892b77' to '{md5}8c67cb8c039bb6436556b91f0c6678c4'
info: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Scheduling refresh of Class[Puppet::Service]
info: Class[Puppet::Service]: Scheduling refresh of Service[puppet]
notice: /Service[puppet]/ensure: ensure changed 'stopped' to 'running'
notice: /Service[puppet]: Triggered 'refresh' from 1 events
notice: Finished catalog run in 0.68 seconds
[root@agent1 ~]# cat /etc/motd
--                       --
--------puppet test---------
--                       --

Puppet基础篇9-Puppetmaster多环境配置相关推荐

  1. Puppet基础篇7-编写第一个完整测试模块puppet

    Puppet基础篇7-编写第一个完整测试模块puppet 零基础学习Puppet自动化配置管理系列文档 将Puppet部署到生产中第一个要编写的模块就是puppet本身,虽然puppet可以运行其它所 ...

  2. Puppet基础篇5-如何建立master和agent之间的认证关系

    Puppet基础篇5-如何建立master和agent之间的认证关系 零基础学习Puppet自动化配置管理系列文档 Puppet注册方式基本上有三种:自动注册.手动注册和预签名注册,在<Pupp ...

  3. Puppet基础篇6-Puppet更新方式的选型

    Puppet基础篇6-Puppet更新方式的选型 零基础学习Puppet自动化配置管理系列文档 基于C/S架构的Puppet更新方式一般有两种,一种是Agent端设置同步时间主动去PuppetMast ...

  4. puppet基础篇(练习篇)

    puppet基础篇(练习篇) 本文分为两部分:一.安装配置及命令用法:二.puppet资源基础练习 1.安装配置及命令用法 #在epel仓库安装 yum install ./facter-2.4.6- ...

  5. Ansible系列-基础篇-Ansible Inventory的合理化配置

    欢迎关注个人公众号 DailyJobOps 原文地址:Ansible系列-基础篇-Ansible Inventory的合理化配置 这里写目录标题 Ansible Inventory内置参数 Inven ...

  6. Java基础【之】JDK环境配置(Windwos)

    Java基础[之]JDK环境配置(Windwos) 1.官网下载JDK 2.默认安装 3.配置环境变量 4.测试 <下一篇:开发工具.基础语法(包.类.程序入口函数)> <目录:Ja ...

  7. puppet 基础篇

    puppet [TOC] 1.什么是puppet 很多公司经常情况下会遇到这么一个问题,新应用开发完成之后,运维人员耗费了大量的时间在测试环境上完成了项目的部署,而迁移到线上环境依旧需要逐字逐句的变更 ...

  8. g4e基础篇#3 Git安装与配置

    现在你已经对Git有了最基本的了解,现在让我们开始动手开始安装和配置Git环境. Git工具包括Git命令行工具,图形化工具和服务器环境:在我们这个教程中,我们会使用以下软件配置我们的环境: • Wi ...

  9. 大连海事大学计算机基础线上考试虚拟机环境配置

    由于疫情以及学校政策的原因,同学们的计算机基础课程考试改为线上考试,因此需要我们下载线上考试系统以及Microsoft Office 2010.鉴于大部分同学电脑office版本为2019及更新版本, ...

最新文章

  1. HASH Partitioning--转载
  2. 保存图像_06 - matplotlib中应知应会numpy存储、交换图像
  3. win7旗舰版系统电脑没有声音怎么办
  4. Kerberos认证过程学习理解
  5. java pecs_Java 泛型: 什么是PECS(Producer Extends, Consumer Super)
  6. lisp 里在特定图层写字_有温度的“城市客厅”——从景观设计角度感受天目里...
  7. 如果计算机原理程序设计,计算机组成原理程序设计.doc
  8. 读《研发的那些事》有感
  9. 编译HG255D的openwrt固件
  10. 利用遗传算法解决TSP问题
  11. 文献阅读笔记【10】:基于小尺度分形维数的裂缝图像分割方法
  12. 生意场上,这些社交暗语不可不懂
  13. 简单的外网映射工具natapp操作
  14. Deadlock found when trying to get lock; try restarting transaction 【MySQL死锁问题解决】
  15. 黑群晖 无法关机_教你无U盘引导实现黑群晖6.1.3 15152,打造属于自己的私人云空间...
  16. FlyBird飞翔的小鸟
  17. VC驿站《VC++网络编程班》开课啦!
  18. 职业选手cfg文件怎么用_新版本盗贼怎么玩?职业选手来教你!
  19. 哈勃望远镜29周年礼物:美轮美奂的南方蟹状星云。
  20. Linux,下载安装minio

热门文章

  1. 814. Binary Tree Pruning
  2. Linux虚拟机安装配置准备工作之--- VMware ( Bridge )
  3. 7.Redis常用命令:ZSet
  4. 用Play 1.x 实现简单云计算多租户设计(Use Play 1.x To Achieve Multi-Tenancy Design)
  5. 最近开发的一个项目的一些感想
  6. 高级交叉报表例子程序(C#)中明细列统计数据错误改正!
  7. 统一代码段与非一致代码段
  8. Struts2 Hibernate Spring 整合的基本流程和步骤及其相关配置细节
  9. request获取网页单选框的值
  10. Targan 算法[有向图强连通分量]