您好,登錄后才能下訂單哦!
Centos X64 6.9版本安裝postfix2.6.6+dovecot+openwebmail
測(cè)試完成日期:2017.06.07
附件為配置文件,可以直接使用
使用系統(tǒng)自帶的帳號(hào)、密碼文件進(jìn)行認(rèn)證,不用安裝mysql,方法簡(jiǎn)單。
測(cè)試發(fā)現(xiàn)Centos 6.5\6.9 x64都使用SHA-512加密。
注意:請(qǐng)不要在ADSL動(dòng)態(tài)IP線路上架設(shè)郵件服務(wù)器,會(huì)被當(dāng)成垃圾郵件服務(wù)器的。建議用阿里云、騰訊云等VPS服務(wù)器,固定IP地址的線路。
一、先卸載sendmail
[root@ser ~]# yum remove sendmail
# chkconfig sendmail off
二、安裝postfix ,dovecot,cyrus-sasl
[root@ser ~]# yum -y install epel-release
[root@ser ~]# yum -y install postfix perl
[root@ser ~]# yum -y install dovecot dovecot-devel dovecot-mysql pam-devel
[root@ser ~]# yum -y install cyrus-sasl cyrus-sasl-plain cyrus-sasl-md5 cyrus-sasl-lib
查看postfix版本
[root@host]# rpm -qa |grep postfix
postfix-2.6.6-8.el6.x86_64
postfix配置文件
[root@ser ~]# vi /etc/postfix/main.cf
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = mail.dongying.com
mydomain = dongying.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain,$mydomain,dongying.com
unknown_local_recipient_reject_code = 550
mynetworks = 127.0.0.0/8,120.25.162.161/32,192.168.88.0/24
smtpd_banner= "Version not Available"
relay_domains = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,mail.$mydomain
disable_vrfy_command=yes
broken_sasl_auth_clients = yes
smtpd_helo_required = yes
strict_rfc821_envelopes = yes
smtpd_reject_unlisted_sender = no
smtpd_data_restrictions = reject_unauth_pipelining
header_checks = pcre:/etc/postfix/header_checks
smtpd_error_sleep_time = 1s
smtpd_soft_error_limit = 10
smtpd_hard_error_limit = 10
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_delay_reject=yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_path = smtpd
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sender_restrictions = permit_mynetworks,
reject_non_fqdn_sender,
reject_unknown_sender_domain,
reject_unauthenticated_sender_login_mismatch,
reject_rhsbl_sender dbl.spamhaus.org,
reject_rhsbl_client dbl.spamhaus.org,
permit
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,
reject_invalid_hostname, reject_non_fqdn_sender,
reject_non_fqdn_recipient, reject_non_fqdn_hostname,
reject_unknown_sender_domain,
reject_unauth_pipelining, reject_unauth_destination,
check_client_access hash:/etc/postfix/client_checks,
check_sender_access hash:/etc/postfix/sender_checks,
reject_rbl_client cblless.anti-spam.org.cn,
reject_rbl_client zen.spamhaus.org,
reject_rbl_client bl.spamcop.net,
reject_rbl_client dyna.spamrats.com,
reject_rbl_client auth.spamrats.com,
reject_rbl_client cbl.abuseat.org,
check_policy_service unix:private/policy-spf,permit
message_size_limit = 41943040
mailbox_size_limit = 500000000
main.cf參數(shù)說(shuō)明如下:
一、注意,以下四行,為你公司的域名及IP信息,請(qǐng)按你實(shí)際地址來(lái)更改好。
myhostname = mail.dongying.com
mydomain = dongying.com
mydestination = $myhostname, localhost.$mydomain,$mydomain,dongying.com
mynetworks = 127.0.0.0/8,120.25.162.161/32,192.168.88.0/24
二、注意,以下六行,為反垃圾郵件規(guī)則,使用國(guó)際反垃圾郵件聯(lián)盟的域名,經(jīng)過(guò)本人親自測(cè)試,均為有效域名,所以一定要加上。
reject_rbl_client cblless.anti-spam.org.cn,
reject_rbl_client zen.spamhaus.org,
reject_rbl_client bl.spamcop.net,
reject_rbl_client dyna.spamrats.com,
reject_rbl_client auth.spamrats.com,
reject_rbl_client cbl.abuseat.org,
三、對(duì)拒絕服務(wù)***的防范。下面三行參數(shù)
smtpd_error_sleep_time = 1s
smtpd_soft_error_limit = 10
smtpd_hard_error_limit = 10
#postfix能累計(jì)客戶端曾經(jīng)發(fā)生錯(cuò)誤的次數(shù),對(duì)于可疑的客戶端,postfix會(huì)主動(dòng)延遲響應(yīng)的時(shí)間
而且錯(cuò)誤次數(shù)越多,延遲時(shí)間越長(zhǎng)。這些都是通過(guò)下面的參數(shù)進(jìn)行設(shè)置
參數(shù)說(shuō)明:初次的延遲時(shí)間由smptd_error_sleep_time參數(shù)決定(默認(rèn)1秒),當(dāng)客戶端累積了
smtpd_soft_error_limit次錯(cuò)誤之后,往后每發(fā)生一次錯(cuò)誤,postfix就多延遲1秒,當(dāng)錯(cuò)誤次數(shù)
超過(guò)smtpd_hard_error_limit時(shí),postfix就放棄該客戶端,并主動(dòng)斷線
四、黑白名單的配置,減少重要客戶郵件被當(dāng)成垃圾郵件。下面二行參數(shù)
check_client_access hash:/etc/postfix/client_checks,
check_sender_access hash:/etc/postfix/sender_checks,
postfxi里有2個(gè)完全不同的參數(shù)來(lái)實(shí)現(xiàn)白名單黑名單,client_checks,通過(guò)客戶端ip,ip段或主機(jī)名屏蔽.
sender_checks,通過(guò)判斷發(fā)件人郵件地址(位于from段)屏蔽,建議將經(jīng)常來(lái)往客戶的郵箱域名地址加入到sender_checks文件中去。 ok為允許,reject為拒絕.
上面2個(gè)文件只要有修改,記得運(yùn)行postmap命令,以便postfix能能查找得到
[root@ postfix]# postmap /etc/postfix/client_checks
[root@ postfix]# postmap /etc/postfix/sender_checks
[root@ postfix]# cat sender_checks
gmail.com ok
example.com REJECT env. from addr any@example.com rejected
.example.com REJECT env. from addr any@sub.example.com rejected
user@example.com REJECT We don't want your email
[root@ postfix]# cat client_checks
61.145.211.19 ok
.example.com REJECT No spammers, from your subdomain
五、SPF反垃圾郵件認(rèn)證。
check_policy_service unix:private/policy-spf
指定域名的spf認(rèn)證,需要在域名中心做“txt域名解析記錄”
六、郵件頭查檢,過(guò)濾指定內(nèi)容的郵件。
header_checks = pcre:/etc/postfix/header_checks
郵件頭查檢,spf認(rèn)證沒(méi)通過(guò)的郵件,直接丟棄
[root@ postfix]# cat /etc/postfix/header_checks
/Received-SPF: softfail/ REJECT
七、郵箱大小及附件的設(shè)定。
message_size_limit = 41943040
mailbox_size_limit = 500000000
是限制使用者郵件目錄的大小,也就是能夠在服務(wù)器上保存郵件的大小500M,那么message_size_limit限制郵件大小是41943040/1024/1024=40M,
附件main.cf文件為加入了spf反垃圾驗(yàn)證,可直接使用
八、生成/etc/postfix/aliases別名數(shù)據(jù)庫(kù),解決出現(xiàn)NIS domain name not set - NIS lookups disabled警告信息
[root@ postfix]# touch /etc/postfix/aliases
[root@ postfix]# postalias /etc/postfix/aliases
下面2行加入到main.cf中即可
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
==========================================================================
再進(jìn)行下面的配置
Postfix配置SPF防發(fā)件人欺騙
http://www.haiyun.me/archives/postfix-spf-spoof.html (參考文章)
首先,需要進(jìn)入公網(wǎng)的“域名管理中心”,加一筆TXT記錄,值為 v=spf1 mx -all
同時(shí)將MX等記錄也配置好,方便收發(fā)郵件。按下圖設(shè)定5項(xiàng)紅色框中的即可
[root@ postfix]# yum install perl-Mail-SPF perl-Sys-Hostname-Long
[root@ postfix]# wget https://launchpad.net/postfix-policyd-spf-perl/trunk/release2.010/+download/postfix-policyd-spf-perl-2.010.tar.gz
[root@ postfix]# tar zxvf postfix-policyd-spf-perl-2.010.tar.gz
[root@ postfix]# mv postfix-policyd-spf-perl-2.010/postfix-policyd-spf-perl /usr/sbin/
[root@ postfix]# chmod +x /usr/sbin/postfix-policyd-spf-perl
開(kāi)啟postfix-policyd-spf-perl服務(wù):
[root@ postfix]# vi /etc/postfix/master.cf
## spf check
policy-spf unix - n n - - spawn
user=nobody argv=/usr/sbin/postfix-policyd-spf-perl
編輯Postfix主配置文件添加SPF過(guò)濾規(guī)則:
[root@ postfix]# vi /etc/postfix/main.cf
smtpd_recipient_restrictions =
permit_mynetworks,
........
check_policy_service unix:private/policy-spf,permit
查看郵件日志
[root@ postfix]# tail -f /var/log/maillog
#下為正確的記錄,如下,有紅色Received-SPF: pass表示通過(guò)。
Jun 7 17:25:56 host-cn postfix/smtpd[12947]: connect from smtpbg331.qq.com[14.17.43.223]
Jun 7 17:26:04 host-cn postfix/policy-spf[12952]: Policy action=PREPEND Received-SPF: pass (qq.com: Sender is authorized to use '3700488@qq.com' in 'mfrom' identity (mechanism 'include:spf.mail.qq.com' matched)) receiver=unknown; identity=mailfrom; envelope-from="3700488@qq.com"; helo=smtpbg331.qq.com; client-ip=14.17.43.223
Jun 7 17:26:04 host-cn postfix/smtpd[12947]: 05CBEC0E16: client=smtpbg331.qq.com[14.17.43.223]
Jun 7 17:26:04 host-cn postfix/cleanup[12955]: 05CBEC0E16: message-id=<tencent_59D1E18B1E12DC422D21A8AA@qq.com>
Jun 7 17:26:04 host-cn postfix/qmgr[12946]: 05CBEC0E16: from=<3700488@qq.com>, size=2286, nrcpt=1 (queue active)
Jun 7 17:26:04 host-cn postfix/smtpd[12947]: disconnect from smtpbg331.qq.com[14.17.43.223]
Jun 7 17:26:04 host-cn postfix/local[12956]: 05CBEC0E16: to=<evan@dongying.com>, relay=local, delay=7.6, delays=7.6/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
Jun 7 17:26:04 host-cn postfix/qmgr[12946]: 05CBEC0E16: removed
#以下為錯(cuò)誤信息
postfix/policy-spf[15857]: Policy action=PREPEND Received-SPF: softfail (www.haiyun.me: Sender is not authorized by default
將postfix加入到root組
[root@ postfix]# usermod -G root postfix
再檢查配置文件,執(zhí)行命令 /usr/sbin/postconf -n
將postfix設(shè)定為MTA
[root@ postfix]# alternatives –set mta /usr/sbin/sendmail.postfix
查看MTA的方法:
[root@ postfix]# alternatives --display mta
將Postfix設(shè)置為自啟動(dòng)
[root@ postfix]# chkconfig --add postfix
[root@ postfix]# chkconfig postfix on
[root@ postfix]# chkconfig saslauthd on
查看是否有安裝認(rèn)證
[root@ postfix]# rpm -qa|grep cyrus
cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-md5-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-plain-2.1.23-15.el6_6.2.x86_64
配置認(rèn)證機(jī)制, 在文件內(nèi)容中加入如下三行
[root@ postfix]# vi /etc/sasl2/smtpd.conf
log_level: 3
pwcheck_method: saslauthd
mech_list: plain login
[root@ postfix]# vi /etc/sysconfig/saslauthd 在文件內(nèi)容中,有如下兩行
MECH=shadow
FLAGS=
再啟動(dòng)認(rèn)證服務(wù)
[root@ postfix]# service saslauthd start
添加郵件用戶的賬戶
[root@ postfix]# groupadd mail 新建立一個(gè)mail用戶組
[root@ postfix]# useradd -g mail -s /sbin/nologin evan 建evan用戶并指定用戶組為mail組,且不讓其SSH登錄
[root@ postfix]# passwd evan 修改evan用戶密碼
為了使添加的郵箱用戶有在/var/spool/mail目錄下的權(quán)限,需要:
[root@ postfix]# usermod -g mail evan 修改evan用戶,設(shè)置主用戶組為mail組
查看mail組中的用戶
[root@host-cn ~]# groups mail
mail : jack evan
查看Linux某用戶屬于哪個(gè)組
[root@host-cn postfix]# id evan
uid=504(evan) gid=12(mail) groups=12(mail)
[root@host-cn postfix]# groups evan
evan : mail
當(dāng)用戶已經(jīng)建立了,如果你在建立時(shí)沒(méi)有控制權(quán)限,現(xiàn)在需要取消用戶登錄權(quán)限,可以使用以下命令
vi /etc/passwd
找到你要修改的用戶所在的那一行,例如username:x:502:502::/home/username:/bin/bash,
修改為以下代碼
username:x:502:502::/home/username:/sbin/nologin
驗(yàn)證密碼是否成功,格式如下,例如:
[root@ postfix]# testsaslauthd -u evan -p miserp007
0: OK "Success."
顯示上面結(jié)果,表示驗(yàn)證成功。
啟動(dòng)postfix服務(wù)
[root@ postfix]# service postfix start
==================================================================================
二、安裝與配置dovecot
[root@ postfix]# yum install -y dovecot dovecot-devel dovecot-mysql pam-devel
查看版本
[root@ postfix]# dovecot --version
2.0.9
只需要配置一個(gè)dovecot.conf文件即可,進(jìn)行普通認(rèn)證,關(guān)掉SSL
[root@ dovecot]# vi /etc/dovecot/dovecot.conf
listen = *
protocols = pop3 imap
default_login_user=postfix
default_internal_user=postfix
disable_plaintext_auth = no
ssl = no
mail_privileged_group = mail
mail_location = mbox:~/mail:INBOX=/var/mail/%u
userdb {
driver = passwd
args = blocking=no
}
passdb {
driver = shadow
}
將conf.d文件夾改名,不需要使用里面的配置文件
[root@ dovecot]# cd /etc/dovecot/
[root@ dovecot]# mv conf.d conf.d.bak
檢查認(rèn)證文件,默認(rèn)是不需要更改的
[root@ dovecot]# vi /etc/pam.d/dovecot
auth required pam_nologin.so
auth include password-auth
account include password-auth
session include password-auth
將dovecot設(shè)置為自啟動(dòng)
[root@ dovecot]# service dovecot start
[root@ dovecot]# chkconfig dovecot on
[root@ dovecot]# chkconfig --add dovecot
測(cè)試是否可以正常登錄dovecot
[root@ dovecot]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user evan 手動(dòng)打入登錄用戶名
+OK
pass miserp007 手動(dòng)打入用戶密碼
+OK Logged in. 此處表示已經(jīng)登錄進(jìn)來(lái)了
quit 退出去
+OK Logging out.
查看郵件日志
[root@ dovecot]# tail -f /var/log/maillog
============================================================================
三、安裝openwebmail
生成openwebmail安裝源
[root@ dovecot]# vi /etc/yum.repos.d/openwebmail.repo
[openwebmail]
## Thomas Chung
## 2008.05.29
name=Openwebmail for Fedora or Enterprise Linux
baseurl=http://openwebmail.org/openwebmail/download/redhat/rpm/release/
enabled=1
gpgcheck=1
gpgkey=http://openwebmail.org/openwebmail/download/redhat/rpm/release/RPM-GPG-KEY-openwebmail
#metadata_expire=0
[root@ dovecot]# yum install openwebmail
安裝完成后,提示運(yùn)行openwebmail-tool.pl --init
[root@ dovecot]# cd /var/www/cgi-bin/openwebmail/
更改dbm.conf內(nèi)容后保存
[root@ openwebmail]# vi /var/www/cgi-bin/openwebmail/etc/dbm.conf
dbm_ext .db
dbmopen_ext .db
dbmopen_haslock no
[root@ openwebmail]# cd /var/www/cgi-bin/openwebmail/
執(zhí)行初始化
[root@ openwebmail]# ./openwebmail-tool.pl --init
Send the site report?(Y/n) 請(qǐng)回答y
最后完成安裝過(guò)程
修改openwebmail語(yǔ)言選項(xiàng)
[root@ openwebmail]# cd /var/www/cgi-bin/openwebmail/etc
[root@ etc]# vi openwebmail.conf
domainnames dongying.com 將auto改成你公司的域名,此處為dongying.com
default_language auto 將en改成auto
default_iconset Cool3D.Chinese.Simplified
[root@ etc]# cd /var/www/cgi-bin/openwebmail/etc/defaults
[root@ defaults]# vi openwebmail.conf
domainnames dongying.com
smtpserver 127.0.0.1
讓 Open WebMail 成為 Server 預(yù)設(shè)的網(wǎng)頁(yè)
[root@ defaults]# cd /var/www/cgi-bin/openwebmail
[root@ openwebmail]# vi index.html
<html><head>
<meta http-equiv="Refresh"
content="0;URL=http://mail.dongying.com:82/cgi-bin/openwebmail/openwebmail.pl">
</head></html>
安裝apache并修改配置文件
[root@ openwebmail]# yum install httpd
[root@ openwebmail]# vi /etc/httpd/conf/httpd.conf
ServerName mail.dongying.com:82
Listen 82
DocumentRoot "/var/www/cgi-bin/openwebmail"
AddHandler cgi-script .cgi .pl
安裝字符編碼
[root@ openwebmail]# wget ftp://ftp.devil-linux.org/pub/devel/sources/1.4/perl-ext/MIME-Base64-3.09.tar.gz
[root@ ~]# tar -xzvf MIME-Base64-3.09.tar.gz
[root@ ~]# cd MIME-Base64-3.09
[root@ MIME-Base64-3.09]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for MIME::Base64
[root@ MIME-Base64-3.09]# make
[root@ openwebmail]# service httpd restart
加入到自動(dòng)啟動(dòng)
[root@ openwebmail]# chkconfig httpd on
停用防火墻或者加入指定端口25、82、110、143、
[root@ openwebmail]# service iptables stop
[root@ openwebmail]# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 110 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 143 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 82 -j ACCEPT
[root@ openwebmail]# service iptables restart
再就可以在瀏覽器中直接打開(kāi)了
http://mail.dongying.com:82
===========================================================
定期備份maillog文件并刪除15天以前的舊備份文件,用于防止maillog文件過(guò)大,造成硬盤(pán)空間的浪費(fèi)
[root@postfix]# vi /etc/posftix/clearmaillog
#!/bin/sh
# clear maillog and Backup .by evanli
rq=`date +%Y-%m-%d`
service postfix stop
service dovecot stop
mv /var/log/maillog /var/log/maillog-$rq.bak
service rsyslog restart
service postfix start
service dovecot start
find /var/log -mtime +15 -name "mail*.bak" -exec rm -rf {} \;
生成的備份日志文件格式為maillog-2017-06-08.bak
給予可執(zhí)行權(quán)限
[root@ postfix]# chmod +x clearmaillog
安裝排程與時(shí)間同步服務(wù)
[root@postfix]# yum install crontabs ntpdate
停用系統(tǒng)自帶的ntpd服務(wù)
[root@postfix]# service ntpd stop
[root@postfix]# chkconfig ntpd off
將以下紅色2行加入到文件最后
[root@host-cn postfix]# vi /etc/crontab
55 23 * * 0 root /etc/postfix/clearmaillog
0 */1 * * * root /usr/sbin/ntpdate 0.pool.ntp.org >& /dev/null
每周日晚上23:55分,備份miallog并清除舊文件。
每隔1小時(shí)同步一次系統(tǒng)時(shí)間
重起一次排程服務(wù)
[root@ postfix]# /sbin/service crond restart
====================================================
郵件日志分析工具pflogsumm
1、pflogsumm功能:
統(tǒng)計(jì)接收、投遞、轉(zhuǎn)發(fā)、延時(shí)、反彈、拒絕、保留、丟棄的郵件
統(tǒng)計(jì)發(fā)件人和收件人
統(tǒng)計(jì)發(fā)送和接受方主機(jī)/域名
統(tǒng)計(jì)SMTPD連接數(shù)
。。。。。。
2、安裝
# yum install postfix-pflogsumm
3、使用
統(tǒng)計(jì)今天的信息
# pflogsumm -d today /var/log/maillog
統(tǒng)計(jì)昨天的信息
# pflogsumm -d yesterday /var/log/maillog
4、使用定時(shí)任務(wù)生成j昨天報(bào)告
每天晚上23:53點(diǎn),將當(dāng)天的郵件系統(tǒng)日志統(tǒng)計(jì)報(bào)表發(fā)送到管理員郵箱中去。
將以下面一行加入到文件最后
[root@ postfix]# vi /etc/crontab
53 23 * * * root /usr/sbin/pflogsumm -d today /var/log/maillog 2>&1 | mail -s "daily mail stats" evan@dongying.com
更多 pflogsumm使用方法:
# man pflogsumm
最后,使用outlook2013或foxmail來(lái)收郵件時(shí),一定要記得,將“我的發(fā)件服務(wù)器(STMP)需要驗(yàn)證”打上勾。另外,用戶名位置一定要按圖設(shè)定。 如下圖
測(cè)試完成日期:2017.06.07
附件為配置文件,可以直接使用
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。