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

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能能查找得到

[[email protected] postfix]# postmap /etc/postfix/client_checks

[[email protected] postfix]# postmap /etc/postfix/sender_checks

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

[[email protected] 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认证没通过的邮件,直接丢弃

[[email protected] 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警告信息

[[email protected] postfix]# touch /etc/postfix/aliases

[[email protected] 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项红色框中的即可

[[email protected] postfix]# yum install perl-Mail-SPF perl-Sys-Hostname-Long

[[email protected] postfix]# wget https://launchpad.net/postfix-policyd-spf-perl/trunk/release2.010/+download/postfix-policyd-spf-perl-2.010.tar.gz


[[email protected] postfix]# tar zxvf postfix-policyd-spf-perl-2.010.tar.gz 

[[email protected] postfix]# mv postfix-policyd-spf-perl-2.010/postfix-policyd-spf-perl /usr/sbin/

[[email protected] postfix]# chmod +x /usr/sbin/postfix-policyd-spf-perl

开启postfix-policyd-spf-perl服务:

[[email protected] 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过滤规则:

[[email protected] postfix]# vi /etc/postfix/main.cf

smtpd_recipient_restrictions =

permit_mynetworks,

........

check_policy_service unix:private/policy-spf,permit

查看邮件日志

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

[[email protected] postfix]# usermod -G root postfix

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


将postfix设定为MTA

[[email protected] postfix]# alternatives –set mta /usr/sbin/sendmail.postfix

查看MTA的方法:

[[email protected] postfix]# alternatives --display mta

将Postfix设置为自启动

[[email protected] postfix]# chkconfig --add postfix

[[email protected] postfix]# chkconfig postfix on 

[[email protected] postfix]# chkconfig saslauthd on


查看是否有安装认证 

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


配置认证机制, 在文件内容中加入如下三行

[[email protected] postfix]# vi /etc/sasl2/smtpd.conf

log_level: 3

pwcheck_method: saslauthd

mech_list: plain login

[[email protected] postfix]# vi /etc/sysconfig/saslauthd   在文件内容中,有如下两行

MECH=shadow

FLAGS=

再启动认证服务

[[email protected] postfix]# service saslauthd start

建立用户

[[email protected] postfix]# useradd evan

[[email protected] postfix]# passwd evan

为了使添加的邮箱用户有在/var/spool/mail目录下的权限,需要:

[[email protected] postfix]# usermod -g mail evan

验证密码是否成功,格式如下,例如:

[[email protected] postfix]# testsaslauthd -u evan -p miserp007

0: OK "Success."

显示上面结果,表示验证成功。

启动postfix服务

[[email protected] postfix]# service postfix start

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

二、安装与配置dovecot

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

查看版本

[[email protected] postfix]# dovecot --version

2.0.9

只需要配置一个dovecot.conf文件即可,进行普通认证,关掉SSL

[[email protected] 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文件夹改名,不需要使用里面的配置文件

[[email protected] dovecot]# cd /etc/dovecot/

[[email protected] dovecot]# mv conf.d  conf.d.bak

检查认证文件,默认是不需要更改的

[[email protected] dovecot]# vi /etc/pam.d/dovecot

auth       required     pam_nologin.so

auth       include      password-auth

account    include      password-auth

session    include      password-auth

将dovecot设置为自启动

[[email protected] dovecot]# service dovecot start  

[[email protected] dovecot]# chkconfig dovecot on

[[email protected] dovecot]#  chkconfig --add dovecot

测试是否可以正常登录dovecot

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

查看邮件日志

[[email protected] dovecot]# tail -f /var/log/maillog

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

三、安装openwebmail

生成openwebmail安装源

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

[[email protected] dovecot]# yum install openwebmail

安装完成后,提示运行openwebmail-tool.pl --init

[[email protected] dovecot]# cd /var/www/cgi-bin/openwebmail/

更改dbm.conf内容后保存

[[email protected] openwebmail]# vi /var/www/cgi-bin/openwebmail/etc/dbm.conf  

dbm_ext                 .db

dbmopen_ext             .db

dbmopen_haslock         no

[[email protected] openwebmail]#  cd /var/www/cgi-bin/openwebmail/

执行初始化

[[email protected] openwebmail]#  ./openwebmail-tool.pl --init

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

最后完成安装过程

修改openwebmail语言选项

[[email protected] openwebmail]# cd /var/www/cgi-bin/openwebmail/etc

[[email protected] etc]# vi openwebmail.conf

domainnames           dongying.com     将auto改成你公司的域名,此处为dongying.com

default_language        auto          将en改成auto

default_iconset         Cool3D.Chinese.Simplified

[[email protected] etc]# cd /var/www/cgi-bin/openwebmail/etc/defaults

[[email protected] defaults]# vi openwebmail.conf

domainnames             dongying.com

smtpserver              127.0.0.1

让 Open WebMail 成为 Server 预设的网页

[[email protected] defaults]# cd /var/www/cgi-bin/openwebmail

[[email protected] 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并修改配置文件

[[email protected] openwebmail]# yum install httpd

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

安装字符编码
[[email protected] openwebmail]# wget ftp://ftp.devil-linux.org/pub/devel/sources/1.4/perl-ext/MIME-Base64-3.09.tar.gz

[[email protected] ~]#  tar -xzvf  MIME-Base64-3.09.tar.gz
[[email protected] ~]# cd MIME-Base64-3.09
[[email protected] MIME-Base64-3.09]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for MIME::Base64
[[email protected] MIME-Base64-3.09]# make

[[email protected] openwebmail]# service httpd restart


加入到自动启动

[[email protected] openwebmail]# chkconfig httpd on

停用防火墙或者加入指定端口25、82、110、143、

[[email protected] openwebmail]# service iptables stop

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

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

给予可执行权限
[[email protected] 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小时同步一次系统时间

重起一次排程服务
 [[email protected] 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点,将当天的邮件系统日志统计报表发送到管理员邮箱中去。

将以下面一行加入到文件最后

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

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

时间: 2024-08-11 05:44:25

Centos X64 6.9版本安装postfix2.6.6+dovecot+openwebmail的相关文章

centos系统php5.6版本安装gd扩展库

由于项目需要显示验证码登录系统,所以这里需要开启php的gd扩展 这边提供安装php5.6的yum方法扩展自选.# rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm # yum install --enablerepo=remi -

[openfair]解决在centos x64 上安装openfire出现的错误

在centos x64 上安装openfire,运行  /etc/init.d/openfire start后发现服务器没法开启,查看log日志: nohup: failed to run command `/opt/openfire/jre/bin/java': No such file or directory 很奇怪,我是在centos上安装了java,openfire自带的jre就没法使用了,在论坛上搜索到下面的解决办法: http://community.igniterealtime.

Centos 6.5 SNMP客户端安装及配置版本net-snmp-5.7.3

Centos 6.5 SNMP客户端安装及配置SNMP版本:net-snmp-5.7.3.tar.gz1.下载软件cd /usr/local/srcyum -y install gccwget http://nchc.dl.sourceforge.net/project/net-snmp/net-snmp/5.7.3/net-snmp-5.7.3.tar.gz 2.解压编译安装tar -zxvf net-snmp-5.7.3.tar.gzcd net-snmp-5.7.3./configure

CentOS x64上Matlab R2015b的镜像安装方法与卸载

CentOS x64上Matlab R2015b的镜像安装方法与卸载 0. 原料 (1). CentOS_x64系统 CentOS 2.6.32-573.el6.x86_64 (2). Matlab  R2015b_glnxa64.iso,可以从百度网盘下载到:链接: http://pan.baidu.com/s/1dD9F8RJ 密码: t8zi 1. CentOS/Linux 安装MATLAB (0). Matlab的安装说明readme.txt,全文摘抄如下(可略过). I offer t

centos x64搭建 hadoop2.4.1 HA

Hadoop  HA的实现方式 上图大致架构包括: 1.  利用共享存储来在两个NN间同步edits信息.以前的HDFS是share nothing but NN,现在NN又share storage,这样其实是转移了单点故障的位置,但中高端的存储设备内部都有各种RAID以及冗余硬件包括电源以及网卡等,比服务器的可靠性还是略有提高.通过NN内部每次元数据变动后的flush操作,加上NFS的close-to-open,数据的一致性得到了保证. 2.DataNode同时向两个NN汇报块信息.这是让S

CentOS 6.3(x86_64)下安装Oracle 10g R2

目 录 一.硬件要求二.软件三.系统安装注意四.安装Oracle前的系统准备工作五.安装Oracle,并进行相关设置六.升级Oracle到patchset 10.2.0.4七.使用rlwrap调用sqlplus中历史命令 一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal /proc/meminfo # grep SwapTotal /proc/meminfo

centos x64 vsftpd 530登陆错误问题

近来在centos 6.0 x64版本下安装vsftpd,中间出现一些问题,解决过程总结如下: 安装vsftpd:yum install vsftpd 安装后配置为虚拟用户登陆,然后用:ftp localhost 登陆测试 总是出现错误提示: 530 Login incorrect.Login failed. google了一下,普遍的解决办法是:在/etc/vsftpd/vsftpd.conf中添加 pam_service_name=vsftpd 这是为了解决pam与vsftpd配合问题,可以

CentOS 7.2 yum方式安装MySQL 5.7

CentOS 7之后的版本yum的默认源中使用MariaDB替代原先MySQL,因此安装方式较为以往有一些改变: 下载mysql的源 wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm 安装yum库 yum localinstall -y mysql57-community-release-el7-7.noarch.rpm 安装MySQL yum install -y mysql-community-s

CentOS 6.5下编译安装httpd+mysql+php+phpMyAdmin

CentOS 6.5下编译安装httpd+mysql+php+phpMyAdmin+cacti+nagios 一.安装环境 Linux系统:CentOS 6.5 Apache版本:http-2.4.12 MySQL版本:MySQL 5.6.24 PHP版本:PHP-5.6.8 基本的安装顺序为:先安装httpd,然后安装mysql,最后安装PHP. 软件包: [[email protected] httpdbao]# ll total 334908 -rwxrw-rw-. 1 root root