1. 程式人生 > >Centos X64 6.9版本安裝postfix2.6.6+dovecot+openwebmail

Centos X64 6.9版本安裝postfix2.6.6+dovecot+openwebmail

"dovecot+openwebmail" "postfix 2.6安裝" "centos 6.9安裝postfix2.6.6"

Centos X64 6.9版本安裝postfix2.6.6+dovecot+openwebmail

測試完成日期:2017.06.07

附件為配置文件,可以直接使用


使用系統自帶的帳號、密碼文件進行認證,不用安裝mysql,方法簡單。

測試發現Centos 6.5\6.9 x64都使用SHA-512加密。



一、先卸載sendmain

[[email protected] ~]# yum remove sendmail

# chkconfig sendmail off


二、安裝postfix ,dovecot,cyrus-sasl

[[email protected] ~]# yum -y install epel-release

[[email protected] ~]# yum -y install postfix perl

[[email protected] ~]# yum -y install dovecot dovecot-devel dovecot-mysql pam-devel

[[email protected] ~]# yum -y install cyrus-sasl cyrus-sasl-plain cyrus-sasl-md5 cyrus-sasl-lib


查看postfix版本

[[email protected]]# rpm -qa |grep postfix

postfix-2.6.6-8.el6.x86_64


postfix配置文件

[[email protected] ~]# 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

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_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 ix.dnsbl.manitu.net,

reject_rbl_Client sbl-xbl.spamhaus.org,

reject_rbl_Client bl.spamcop.net,

reject_rbl_client noptr.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參數說明如下:

一、註意,以下四行,為你公司的域名及IP信息,請按你實際地址來更改好。

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


二、註意,以下六行,為反垃圾郵件規則,使用國際反垃圾郵件聯盟的域名,一定要加上。

reject_rbl_client cblless.anti-spam.org.cn, reject_rbl_client ix.dnsbl.manitu.net,

reject_rbl_Client sbl-xbl.spamhaus.org,

reject_rbl_Client bl.spamcop.net,

reject_rbl_client noptr.spamrats.com,

reject_rbl_client cbl.abuseat.org,


三、對拒絕服務攻擊的防範。下面三行參數

smtpd_error_sleep_time = 1s

smtpd_soft_error_limit = 10

smtpd_hard_error_limit = 10


#postfix能累計客戶端曾經發生錯誤的次數,對於可疑的客戶端,postfix會主動延遲響應的時間

而且錯誤次數越多,延遲時間越長。這些都是通過下面的參數進行設置

參數說明:初次的延遲時間由smptd_error_sleep_time參數決定(默認1秒),當客戶端累積了

smtpd_soft_error_limit次錯誤之後,往後每發生一次錯誤,postfix就多延遲1秒,當錯誤次數

超過smtpd_hard_error_limit時,postfix就放棄該客戶端,並主動斷線


四、黑白名單的配置,減少重要客戶郵件被當成垃圾郵件。下面二行參數

check_client_access hash:/etc/postfix/client_checks,

check_sender_access hash:/etc/postfix/sender_checks,

postfxi裏有2個完全不同的參數來實現白名單黑名單,client_checks,通過客戶端ip,ip段或主機名屏蔽.

sender_checks,通過判斷發件人郵件地址(位於from段)屏蔽,建議將經常來往客戶的郵箱域名地址加入到sender_checks文件中去。 ok為允許,reject為拒絕.

上面2個文件只要有修改,記得運行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 [email protected] rejected

.example.com REJECT env. from addr [email protected] rejected

[email protected] 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反垃圾郵件認證。

check_policy_service unix:private/policy-spf

指定域名的spf認證,需要在域名中心做“txt域名解析記錄”


六、郵件頭查檢,過濾指定內容的郵件。

header_checks = pcre:/etc/postfix/header_checks

郵件頭查檢,spf認證沒通過的郵件,直接丟棄

[root@ postfix]# cat /etc/postfix/header_checks

/Received-SPF: softfail/ REJECT


七、郵箱大小及附件的設定。

message_size_limit = 41943040

mailbox_size_limit = 500000000

是限制使用者郵件目錄的大小,也就是能夠在服務器上保存郵件的大小500M,那麽message_size_limit限制郵件大小是41943040/1024/1024=40M,

附件main.cf文件為加入了spf反垃圾驗證,可直接使用


八、生成/etc/postfix/aliases別名數據庫,解決出現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


==========================================================================

再進行下面的配置

Postfix配置SPF防發件人欺騙

http://www.haiyun.me/archives/postfix-spf-spoof.html (參考文章)


首先,需要進入公網的“域名管理中心”,加一筆TXT記錄,值為 v=spf1 mx -all

同時將MX等記錄也配置好,方便收發郵件。按下圖設定5項紅色框中的即可

技術分享

[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


開啟postfix-policyd-spf-perl服務:

[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過濾規則:

[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表示通過。


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 [email protected] in ‘mfrom‘ identity (mechanism ‘include:spf.mail.qq.com‘ matched)) receiver=unknown; identity=mailfrom; envelope-from="[email protected]"; 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=<[email protected]>

Jun 7 17:26:04 host-cn postfix/qmgr[12946]: 05CBEC0E16: from=<[email protected]>, 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=<[email protected]>, 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


#以下為錯誤信息

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

再檢查配置文件,執行命令 /usr/sbin/postconf -n



將postfix設定為MTA

[root@ postfix]# alternatives –set mta /usr/sbin/sendmail.postfix

查看MTA的方法:

[root@ postfix]# alternatives --display mta

將Postfix設置為自啟動

[root@ postfix]# chkconfig --add postfix

[root@ postfix]# chkconfig postfix on 

[root@ postfix]# chkconfig saslauthd on


查看是否有安裝認證 

[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


配置認證機制, 在文件內容中加入如下三行

[root@ postfix]# vi /etc/sasl2/smtpd.conf

log_level: 3

pwcheck_method: saslauthd

mech_list: plain login


[root@ postfix]# vi /etc/sysconfig/saslauthd 在文件內容中,有如下兩行

MECH=shadow

FLAGS=


再啟動認證服務

[root@ postfix]# service saslauthd start


建立用戶

[root@ postfix]# useradd evan

[root@ postfix]# passwd evan

為了使添加的郵箱用戶有在/var/spool/mail目錄下的權限,需要:

[root@ postfix]# usermod -g mail evan


驗證密碼是否成功,格式如下,例如:

[root@ postfix]# testsaslauthd -u evan -p miserp007

0: OK "Success."

顯示上面結果,表示驗證成功。


啟動postfix服務

[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


只需要配置一個dovecot.conf文件即可,進行普通認證,關掉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


檢查認證文件,默認是不需要更改的

[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設置為自啟動

[root@ dovecot]# service dovecot start  

[root@ dovecot]# chkconfig dovecot on

[root@ dovecot]# chkconfig --add dovecot


測試是否可以正常登錄dovecot

[root@ dovecot]# telnet localhost 110

Trying 127.0.0.1...

Connected to localhost.

Escape character is ‘^]‘.

+OK Dovecot ready.

user evan 手動打入登錄用戶名

+OK

pass miserp007 手動打入用戶密碼

+OK Logged in. 此處表示已經登錄進來了

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

安裝完成後,提示運行openwebmail-tool.pl --init

[root@ dovecot]# cd /var/www/cgi-bin/openwebmail/

更改dbm.conf內容後保存

[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/

執行初始化

[root@ openwebmail]# ./openwebmail-tool.pl --init


Send the site report?(Y/n) 請回答y

最後完成安裝過程


修改openwebmail語言選項

[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 預設的網頁

[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


加入到自動啟動

[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


再就可以在瀏覽器中直接打開了



http://mail.dongying.com:82


===========================================================

定期備份maillog文件並刪除15天以前的舊備份文件,用於防止maillog文件過大,造成硬盤空間的浪費
[[email protected]]# 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


給予可執行權限
[root@ postfix]# chmod +x clearmaillog


安裝排程與時間同步服務
[[email protected]]# yum install crontabs ntpdate


停用系統自帶的ntpd服務
[[email protected]]# service ntpd stop
[[email protected]]# chkconfig ntpd off


將以下紅色2行加入到文件最後
[[email protected] 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小時同步一次系統時間


重起一次排程服務
[root@ postfix]# /sbin/service crond restart


====================================================

郵件日誌分析工具pflogsumm

1、pflogsumm功能:
統計接收、投遞、轉發、延時、反彈、拒絕、保留、丟棄的郵件
統計發件人和收件人
統計發送和接受方主機/域名
統計SMTPD連接數
。。。。。。

2、安裝
# yum install postfix-pflogsumm


3、使用
統計今天的信息
# pflogsumm -d today /var/log/maillog


統計昨天的信息
# pflogsumm -d yesterday /var/log/maillog


4、使用定時任務生成j昨天報告

每天晚上23:53點,將當天的郵件系統日誌統計報表發送到管理員郵箱中去。

將以下面一行加入到文件最後

[root@ postfix]# vi /etc/crontab

53 23 * * * root /usr/sbin/pflogsumm -d today /var/log/maillog 2>&1 | mail -s "daily mail stats" [email protected]


更多 pflogsumm使用方法:
# man pflogsumm


最後,使用outlook2013或foxmail來收郵件時,一定要記得,將“我的發件服務器(STMP)需要驗證”打上勾。另外,用戶名位置一定要按圖設定。 如下圖

技術分享

測試完成日期:2017.06.07

附件為配置文件,可以直接使用


本文出自 “虛擬化應用” 博客,請務必保留此出處http://liwenhn.blog.51cto.com/854522/1933540

Centos X64 6.9版本安裝postfix2.6.6+dovecot+openwebmail