歡迎您光臨本站 註冊首頁

Puppet--自動化管理postfix

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0

Puppet自動化管理postfix

創建postfix模塊對應的文件和目錄

  1. [root@master ~]# mkdir -p /etc/puppet/modules/postfix/{files,manifests,templates}
  2. [root@master ~]# touch /etc/puppet/modules/postfix/manifests/{init.pp,install.pp,config.pp,service.pp}
  3. [root@master ~]# touch /etc/puppet/modules/postfix/files/master.cf
  4. [root@master ~]# touch /etc/puppet/modules/postfix/templates/main.cf.erb

配置

install.pp
  1. [root@master ~]# vim /etc/puppet/modules/postfix/manifests/install.pp
  2. class postfix::install {
  3. package{["postfix","mailx"]:
  4. ensure=>present,
  5. }
  6. }

配置config.pp

  1. [root@master ~]# vim /etc/puppet/modules/postfix/manifests/config.pp
  2. class postfix::config{
  3. File{
  4. owner=>"postfix",
  5. group=>"postfix",
  6. mode=>0644,
  7. }
  8. file{"/etc/postfix/master.cf":
  9. ensure=>present,
  10. source=>"puppet://$puppetserver/modules/postfix/master.cf",
  11. require=>Class["postfix::install"],
  12. notify=>Class["postfix::service"],
  13. }
  14. file{"/etc/postfix/main.cf":
  15. ensure=>present,
  16. content=>template("postfix/main.cf.erb"),
  17. require=>Class["postfix::install"],
  18. notify=>Class["postfix::service"],
  19. }
  20. }

配置

postfix模板文件
  1. [root@master ~]# vim /etc/puppet/modules/postfix/templates/main.cf.erb
  2. soft_bounce = no
  3. command_directory = /usr/sbin
  4. daemon_directory = /usr/libexec/postfix
  5. mail_owner = postfix
  6. myhostname = <%= hostname %>
  7. mydomain = <%= domain %>
  8. myorigin = $mydomain
  9. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
  10. unknown_local_recipient_reject_code = 550
  11. relay_domains = $mydestination
  12. smtpd_reject_unlisted_recipient = yes
  13. unverified_recipient_reject_code = 550
  14. smtpd_banner = $myhostname ESMTP
  15. setgid_group = postdrop

配置service.pp文件

  1. [root@master ~]# vim /etc/puppet/modules/postfix/manifests/service.pp
  2. class postfix::service{
  3. service {"postfix":
  4. ensure=>running,
  5. hasstatus=>true,
  6. hasrestart=>true,
  7. enable=>true,
  8. require=>Class["postfix::config"],
  9. }
  10. }

最后編輯

init.pp
  1. [root@master ~]# vim /etc/puppet/modules/postfix/manifests/init.pp
  2. class postfix{
  3. include postfix::install,postfix::config,postfix::service
  4. }

Postfix的模板配置完成,接下來需要將該模板應用到節點

  1. [root@master ~]# vim /etc/puppet/manifests/nodes.pp
  2. class base {
  3. include sudo,ssh
  4. }
  5. node 'client1.centos' {
  6. include base
  7. include postfix
  8. }

到節點上檢查模塊的配置是否生效
  1. [root@client1 ~]# puppetd --server master.puppet --test
  2. info: FileBucket adding {md5}49b648101b0e361231a977aa89e0dd60
  3. info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Filebucketed /etc/postfix/main.cf to puppet with sum 49b648101b0e361231a977aa89e0dd60
  4. notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/content: content changed '{md5}49b648101b0e361231a977aa89e0dd60' to '{md5}e952770fbd49dcac604e41b689a9f871'
  5. notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/owner: owner changed 'root' to 'postfix'
  6. notice: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]/group: group changed 'root' to 'postfix'
  7. info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix]
  8. info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix]
  9. info: /Stage[main]/Postfix::Config/File[/etc/postfix/main.cf]: Scheduling refresh of Service[postfix]
  10. notice: /Stage[main]/Postfix::Service/Service[postfix]: Triggered 'refresh' from 6 events
  11. notice: Finished catalog run in 2.70 seconds

查看postfix服務狀態

  1. [root@client1 ~]# service postfix status
  2. master (pid 30794) 正在運行...

本文出自 「Waydee的博客」 博客,請務必保留此出處http://waydee.blog.51cto.com/4677242/847137


[火星人 ] Puppet--自動化管理postfix已經有449次圍觀

http://coctec.com/docs/linux/show-post-45811.html