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

[经验分享] Puppet模块(十):postfix模块

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2016-3-25 09:13:11 | 显示全部楼层 |阅读模式
一、模块说明
    postfix是centos系统自带的邮件发送服务,本模块只实现邮件发送和SASL认证功能,目的是为了给程序提供发送注册等通知类邮件给用户的功能。

二、目录结构
wKiom1bzOfCwRxLbAAALOsPxkNY540.jpg

三、代码展示
1、manifests目录
    init.pp
1
2
3
class postfix{
    include postfix::install,postfix::config,postfix::service
}



    install.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class postfix::install {
    package { ['postfix','cyrus-sasl','cyrus-sasl-plain','cyrus-sasl-md5']:
     ensure => installed,
      before => User["postfix"],
    }
    package { 'sendmail':
      ensure => absent,
    }
    file { '/usr/lib/sasl2':
      ensure => directory,
    }
    file {"/home/service1":
        ensure => directory,
        group  => service1,
        owner  => service1,
        mode   => 755,
    }
    user { "service1":
      ensure   => present,
      shell    => '/sbin/nologin',
      home     => '/home/service1',
      password => '$6$mFk7ouL3$pJ1OHG1HF4nM/DKF14iPxn5UQOVoGnQcfngAnukn9.JCflW18mI10zUUVgEzDk21zLhdKTqSy0quvL1jH46qk0',
    }
    user { "postfix":
      ensure => present,
      groups => 'root',
    }
    Exec{  path => ['/usr/bin','/usr/sbin','/bin','/sbin'] }
    exec { 'open_port_25':
        command => 'iptables -I INPUT -p tcp --dport 25 -j ACCEPT',
        unless  => 'grep "tcp --dport 25" /etc/sysconfig/iptables 2>/dev/null',
    }
    exec { 'save_port_25':
        command     => 'service iptables save',
        refreshonly => true,
        subscribe   => Exec['open_port_25'],
    }
}



    config.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class postfix::config {
file { '/etc/postfix/main.cf':
      ensure   => file,
      content  => template("postfix/main.cf.erb"),
      owner    => root,
      group    => root,
      mode     => '0644',
      require  => Class['postfix::install'],
    }
    file { '/usr/lib/sasl2/smtpd.conf':
      ensure   => file,
      content  => template("postfix/smtpd.conf.erb"),
      owner    => root,
      group    => root,
      mode     => '0644',
      require  => Class['postfix::install'],
    }
    file { '/etc/sysconfig/saslauthd':
      ensure   => file,
      content  => template("postfix/saslauthd.erb"),
      owner    => root,
      group    => root,
      mode     => '0644',
      require  => Class['postfix::install'],
    }
}






    service.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class postfix::service {
    service { 'postfix':
        ensure     => 'running',
        enable     => 'true',
        hasrestart => 'true',
        hasstatus  => 'true',
        subscribe  => File['/etc/postfix/main.cf'],
    }
    service { 'saslauthd':
        ensure     => 'running',
        enable     => 'true',
        hasrestart => 'true',
        hasstatus  => 'true',
        subscribe  => File[['/usr/lib/sasl2/smtpd.conf'],['/etc/sysconfig/saslauthd']],
    }
}



2、templates目录
    main.cf.erb        #配置文件,centos6.5默认会安装postfix2.6.6版本;根据网络环境修改mynetworks参数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
myhostname = mail.eworkpal.com
mydomain = eworkpal.com
myorigin = $mydomain
mynetworks = 127.0.0.1,10.188.1.0/24
home_mailbox = Maildir/
smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous



    saslauthd.erb
1
2
3
4
5
6
7
8
9
10
11
# Directory in which to place saslauthd's listening socket, pid file, and so
# on.  This directory must already exist.
SOCKETDIR=/var/run/saslauthd
# Mechanism to use when checking passwords.  Run "saslauthd -v" to get a list
# of which mechanism your installation was compiled with the ablity to use.
MECH=shadow
# Options sent to the saslauthd. If the MECH is other than "pam" uncomment the next line.
# DAEMONOPTS=--user saslauth
# Additional flags to pass to saslauthd on the command line.  See saslauthd(8)
# for the list of accepted flags.
FLAGS=



    smtpd.conf.erb
1
pwcheck_method: saslauthd




四、Foreman配置
    参考前面文章,这里不需要设置参数


五、测试
1、设置DNS解析
A记录:mail.ewin.com 10.188.1.41
MX记录:mail.ewin.com
2、添加用户
1
[iyunv@T-Master-41 postfix]#



3、测试sasl认证

1
[iyunv@T-Master-41 postfix]#




4、测试SMTP认证
    获取账号密码的加密字符串
1
2
3
4
[iyunv@T-Master-41 postfix]# perl -e 'use MIME::Base64; print encode_base64("username01@ewin.com")'
c2VydmljZTFAZXdvcmtwYWwuY29t
[iyunv@T-Master-41 postfix]# perl -e 'use MIME::Base64; print encode_base64("password")'
ZXdpbmluZm8=



    邮件发送测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[iyunv@T-Master-41 postfix]# telnet localhost 25
Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.ewin.com ESMTP Postfix - by ewin.com
ehlo mail.ewin.com
250-mail.ewin.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:username01@ewin.com
250 2.1.0 Ok
rcpt to:xxxxx@qq.com      #这里换成你的正常邮箱
554 5.7.1 <xxxxx@qq.com>: Relay access denied      #没有登陆,提示访问拒绝
auth login
334 VXNlcm5hbWU6
c2VydmljZTFAZXdvcmtwYWwuY29t    #输入用户名加密字符串
334 UGFzc3dvcmQ6
ZXdpbmluZm8=                    #输入密码加密字符串
235 2.7.0 Authentication successful
rcpt to:xxxxx@qq.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject:smtp test3
this is test mail3 .!
.
250 2.0.0 Ok: queued as 9E9EC40B0F
quit
221 2.0.0 Bye
Connection closed by foreign host.



5、查看日志
1
2
3
4
5
6
7
8
[iyunv@T-Master-41 postfix]# tail -n 30 /var/log/maillog
Sep 19 19:13:13 T-Master-41 postfix/smtpd[26064]: connect from localhost[::1]
Sep 19 19:14:45 T-Master-41 postfix/smtpd[26064]: 9E9EC40B0F: client=localhost[::1], sasl_method=login, sasl_username=username01@ewin.com
Sep 19 19:15:19 T-Master-41 postfix/cleanup[26183]: 9E9EC40B0F: message-id=<20150919111445.9E9EC40B0F@mail.ewin.com>
Sep 19 19:15:19 T-Master-41 postfix/qmgr[16895]: 9E9EC40B0F: from=<username01@ewin.com>, size=383, nrcpt=1 (queue active)
Sep 19 19:15:22 T-Master-41 postfix/smtpd[26064]: disconnect from localhost[::1]
Sep 19 19:15:24 T-Master-41 postfix/smtp[26193]: 9E9EC40B0F: to=<xxxxx@qq.com>, relay=mail.qq.com[xxx.xx.x.xxx]:25, delay=44, delays=39/0.01/4.1/0.72, dsn=2.6.0, status=sent (250 2.6.0 <20150919111445.9E9EC40B0F@mail.ewin.com> [InternalId=618792] Queued mail for delivery)
Sep 19 19:15:24 T-Master-41 postfix/qmgr[16895]: 9E9EC40B0F: removed



6、查看邮箱目录
1
/home/username01/Maildir



运维网声明 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-195350-1-1.html 上篇帖子: Puppet模块(九):redis模块 下篇帖子: Puppet之基础篇 都市报
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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