Puppet--自动化管理postfix
Puppet自动化管理postfix创建postfix模块对应的文件和目录
[*]# mkdir -p /etc/puppet/modules/postfix/{files,manifests,templates}
[*]
[*]# touch /etc/puppet/modules/postfix/manifests/{init.pp,install.pp,config.pp,service.pp}
[*]
[*]# touch /etc/puppet/modules/postfix/files/master.cf
[*]
[*]# touch /etc/puppet/modules/postfix/templates/main.cf.erb
配置install.pp
[*]# vim /etc/puppet/modules/postfix/manifests/install.pp
[*]
[*]
[*]
[*] class postfix::install {
[*]
[*] package{["postfix","mailx"]:
[*]
[*] ensure=>present,
[*]
[*] }
[*]
[*] }
配置config.pp
[*]# vim /etc/puppet/modules/postfix/manifests/config.pp
[*]
[*] class postfix::config{
[*]
[*] File{
[*]
[*] owner=>"postfix",
[*]
[*] group=>"postfix",
[*]
[*] mode=>0644,
[*]
[*] }
[*]
[*] file{"/etc/postfix/master.cf":
[*]
[*] ensure=>present,
[*]
[*] source=>"puppet://$puppetserver/modules/postfix/master.cf",
[*]
[*] require=>Class["postfix::install"],
[*]
[*] notify=>Class["postfix::service"],
[*]
[*] }
[*]
[*] file{"/etc/postfix/main.cf":
[*]
[*] ensure=>present,
[*]
[*] content=>template("postfix/main.cf.erb"),
[*]
[*] require=>Class["postfix::install"],
[*]
[*] notify=>Class["postfix::service"],
[*]
[*] }
[*]
[*]}
配置postfix模板文件
[*]# vim /etc/puppet/modules/postfix/templates/main.cf.erb
[*]
[*] soft_bounce = no
[*]
[*] command_directory = /usr/sbin
[*]
[*] daemon_directory = /usr/libexec/postfix
[*]
[*] mail_owner = postfix
[*]
[*] myhostname = <%= hostname %>
[*]
[*] mydomain = <%= domain %>
[*]
[*] myorigin = $mydomain
[*]
[*] mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
[*]
[*]unknown_local_recipient_reject_code = 550
[*]
[*]relay_domains = $mydestination
[*]
[*]smtpd_reject_unlisted_recipient = yes
[*]
[*]unverified_recipient_reject_code = 550
[*]
[*]smtpd_banner = $myhostname ESMTP
[*]
[*] setgid_group = postdrop
配置service.pp文件
[*]# vim /etc/puppet/modules/postfix/manifests/service.pp
[*]
[*] class postfix::service{
[*]
[*] service {"postfix":
[*]
[*] ensure=>running,
[*]
[*] hasstatus=>true,
[*]
[*] hasrestart=>true,
[*]
[*] enable=>true,
[*]
[*] require=>Class["postfix::config"],
[*]
[*] }
[*]
[*] }
最后编辑init.pp
[*]# vim /etc/puppet/modules/postfix/manifests/init.pp
[*]
[*] class postfix{
[*]
[*] include postfix::install,postfix::config,postfix::service
[*]
[*] }
Postfix的模板配置完成,接下来需要将该模板应用到节点
[*]# vim /etc/puppet/manifests/nodes.pp
[*]
[*]class base {
[*]
[*] include sudo,ssh
[*]
[*] }
[*]
[*]
[*]
[*] node 'client1.centos' {
[*]
[*] include base
[*]
[*] include postfix
[*]
[*] }
到节点上检查模块的配置是否生效
[*]# puppetd --servermaster.puppet --test
[*]
[*]info: FileBucket adding {md5}49b648101b0e361231a977aa89e0dd60
[*]
[*]info: /Stage/Postfix::Config/File: Filebucketed /etc/postfix/main.cf to puppet with sum 49b648101b0e361231a977aa89e0dd60
[*]
[*]notice: /Stage/Postfix::Config/File/content: content changed '{md5}49b648101b0e361231a977aa89e0dd60' to '{md5}e952770fbd49dcac604e41b689a9f871'
[*]
[*]notice: /Stage/Postfix::Config/File/owner: owner changed 'root' to 'postfix'
[*]
[*]notice: /Stage/Postfix::Config/File/group: group changed 'root' to 'postfix'
[*]
[*]info: /Stage/Postfix::Config/File: Scheduling refresh of Service
[*]
[*]info: /Stage/Postfix::Config/File: Scheduling refresh of Service
[*]
[*]info: /Stage/Postfix::Config/File: Scheduling refresh of Service
[*]
[*]notice: /Stage/Postfix::Service/Service: Triggered 'refresh' from 6 events
[*]
[*]notice: Finished catalog run in 2.70 seconds
查看postfix服务状态
[*]# service postfix status
[*]
[*]master (pid30794) 正在运行...
页:
[1]