=> 创建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端测试:
[root@zabbix ~]# hostname
zabbix.gdy.com
[root@zabbix ~]# rpm -qa | grep httpd
httpd-tools-2.2.15-29.el6_4.x86_64
[root@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
[root@zabbix ~]# rpm -qa | grep httpd
httpd-tools-2.2.15-29.el6_4.x86_64
httpd-2.2.15-29.el6_4.x86_64
[root@zabbix ~]# service httpd status
httpd (pid 1298) is running...
[root@zabbix ~]# chkconfig --list httpd
httpd 0:off1:off2:on3:on4:on5:on6:off
[root@zabbix ~]#
//当前系统主机名为zabbix.gdy.com,满足我们所定义的主机,所以会加载httpd基础模块下的资源。
===============================================
[root@test01 ~]# hostname
test01.gdy.com => 当前主机名为test01.gdy.com,是不满足我们的需求,则会执行default所定义的通知机制。
[root@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