设为首页 收藏本站
查看: 1227|回复: 0

[经验分享] Puppet 通过基础模块、类、节点正则表达式批量管理Apache服务器

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-22 09:01:12 | 显示全部楼层 |阅读模式
=> 创建httpd基础模块
# mkdir /etc/puppet/modules/httpd/{files,manifests,templates} -pv
# tree /etc/puppet/modules/httpd/
/etc/puppet/modules/httpd/
├── files  //基础模块所调用的配置文件,agent可以通过puppet协议将files目录所定义的文件下载到本地。
├── manifests   //主要存放基础模块所使用的类文件及相关资源,如init.pp文件。
└── templates//主要存放定义的模板文件,例如虚拟主机的定义等等。

3 directories, 0 files

=> 存放测试页面或者存放http的配置文件,这里一测试页面为例进行演示。
# ls /etc/puppet/modules/httpd/files/
index.html

=> 定义各资源清单,如package、services、file、init等资源。
     manifests主要存放管理代码以及site.pp入口,并根据init.pp定义进行调用资源清单。
# cd /etc/puppet/modules/httpd/manifests

=> 定义package资源
# cat install.pp
class httpd::install {
package {'httpd':
ensure => installed,
allow_virtual => false,
require => Class[httpd::file],
}
}

=> 定义file资源,主要用于定义agent获取资源的方式以及属性信息
# cat file.pp
class httpd::file {
file {"/var/www/html/index.html":
ensure => file,
owner => root,
group => root,
source => "puppet:///modules/httpd/index.html"
}
}

=> 定义service资源
# cat service.pp
class httpd::service {
service {"httpd":
ensure => running,
enable => true,
}
}


=> 定义init.pp资源主要用于调用manifests所定义的类资源
# cat manifests/init.pp
class httpd {
include httpd::install    调用install资源清单
include httpd::service    调用service资源清单
include httpd::file    调用文件资源清单
}

=> 通过正则表达式管理节点
   主要用于判断agent所匹配的信息,满足执行相关资源定义,不满足则匹配默认(default)所定义的资源。
# cat /etc/puppet/manifests/site.pp
node /^(agent|zabbix)\.gdy\.com$/ {  //只有满足主机名为agent.gdy.com和zabbix.gdy.com两台主机,才会加载httpd基础模块,其他则加载default所定义的资源。
include httpd
}
node default {   ==>  当agent不满足需求时,则执行通知机制。
notify {"Notice error,Not match your node,this is default node":}
}

=> 通过基础模块的形式部署Apache基本完成,下面我们一起看下测试结果,是否正常安装Apache呢?
注意:
其他相关组件的安装和定义类似,例如(LNMP/LAMP/tomcat...),大家只需定义相关资源即可。
================

=> agent端测试:
[iyunv@zabbix ~]# hostname
zabbix.gdy.com   
[iyunv@zabbix ~]# rpm -qa | grep httpd
httpd-tools-2.2.15-29.el6_4.x86_64
[iyunv@zabbix ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for zabbix.gdy.com
Info: Applying configuration version '1435386756'
Notice: /Stage[main]/Httpd::Install/Package[httpd]/ensure: created
Notice: /Stage[main]/Httpd::Service/Service[httpd]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Httpd::Service/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: /Stage[main]/Httpd::File/File[/var/www/html/index.html]/ensure: defined content as '{md5}d72717e69f29438790d728bdcad27913'
Notice: Finished catalog run in 9.86 seconds
[iyunv@zabbix ~]# rpm -qa | grep httpd
httpd-tools-2.2.15-29.el6_4.x86_64
httpd-2.2.15-29.el6_4.x86_64
[iyunv@zabbix ~]# service httpd status
httpd (pid  1298) is running...
[iyunv@zabbix ~]# chkconfig --list httpd
httpd          0:off1:off2:on3:on4:on5:on6:off
[iyunv@zabbix ~]#
//当前系统主机名为zabbix.gdy.com,满足我们所定义的主机,所以会加载httpd基础模块下的资源。

===============================================
[iyunv@test01 ~]# hostname
test01.gdy.com           => 当前主机名为test01.gdy.com,是不满足我们的需求,则会执行default所定义的通知机制。
[iyunv@test01 ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for test01.gdy.com
Info: Applying configuration version '1436147237'
Notice: Notice error,Not match your node,this is default node
Notice: /Stage[main]/Main/Node[default]/Notify[Notice error,Not match your node,this is default node]/message: defined 'message' as 'Notice error,Not match your node,this is default node'
Notice: Finished catalog run in 0.05 seconds
//当前系统主机名为test01.gdy.com,不满足所定义的主机资源,故执行默认所定义的default资源。

=> ok,今天就先到这,谢谢大家



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-89314-1-1.html 上篇帖子: Puppet基于Master/Agent模式实现LNMP平台部署 下篇帖子: puppet学习总结之证书自动认证 服务器 表达式
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表