企业级邮件服务器的搭建postfix.docx
《企业级邮件服务器的搭建postfix.docx》由会员分享,可在线阅读,更多相关《企业级邮件服务器的搭建postfix.docx(18页珍藏版)》请在冰豆网上搜索。
企业级邮件服务器的搭建postfix
mail
企业级邮件服务器的搭建——postfix
电子邮件:
电子邮件的收发流程:
MUA:
MailUserAgent邮件用户代理
MTA:
MailTransferAgent邮件传输代理
MDA:
MailDeliveryAgent邮件投递代理
MRA:
MailReceivedAgent邮件收取代理
使用的协议:
发:
smtp:
简单邮件传输协议tcp25
simplemailtransferprotocol
收:
pop3:
邮局协议第三版tcp110
postofficeprotocol3
imap:
互联网消息访问协议tcp143
internetmessageaccessprotocol
常见的电子邮件的应用程序比较:
redhat5默认sendmail:
古老的MTA,安全和易用性不太好
redhat6默认postfix:
qmail:
非常安全,更新和补丁跟不上。
postfix的优势:
1、免费的
2、更快速
3、兼容性
4、更健壮
5、更灵活
6、安全性
Postfix的安装与配置步骤:
安装与配置postfix:
准备软件安装包
[root@localhostdocs]#lspostfix.tar.gz
postfix.tar.gz
解压压缩包
[root@localhostdocs]#tarzxvfpostfix.tar.gz-C/
进入解压路径
[root@localhost/]#cd/postfix/
[root@localhostpostfix]#ls
配yum:
配置yum源,dhcp获取
[root@localhostpostfix]#vim/etc/yum.repos.d/ftp.repo
[base]
name=base
baseurl=ftp:
//192.168.7.249/iso/Server
enabled=1
gpgcheck=0
[postfix]
name=postfix
baseurl=file:
///postfix
enabled=1
gpgcheck=0
1、安装postfix:
[root@localhostpostfix]#yuminstall-ypostfix
2、处理后事:
停掉所有占用25端口的服务。
[root@localhostpostfix]#/etc/init.d/sendmailstop
[root@localhostpostfix]#chkconfigsendmailoff
切换MTA:
***
[root@localhostpostfix]#alternatives--configmta
Thereare2programswhichprovide'mta'.
SelectionCommand
-----------------------------------------------
*+1/usr/sbin/sendmail.sendmail
2/usr/sbin/sendmail.postfix
Entertokeepthecurrentselection[+],ortypeselectionnumber:
2
设置主机名:
临时:
[root@localhostpostfix]#hostnamemail.extmail.org
vim/etc/sysconfig/network
HOSTNAME=
配置DNS:
[root@localhostpostfix]#yuminstall-ybindbind-chroot
[root@localhostpostfix]#cd/var/named/chroot/etc/
[root@localhostetc]#ls
localtimerndc.key
编辑配置文件
[root@localhostetc]#vimnamed.conf
options{
directory"/var/named";
};
zone"extmail.org"{
typemaster;
file"extmail.org.zone";
};
进入配置文件样例目录,并拷贝样例配置文件
[root@localhostetc]#cd../var/named/
[root@localhostnamed]#cp/usr/share/doc/bind-9.3.6/sample/var/named/localhost.zoneextmail.org.zone
编辑区域配置文件
[root@localhostnamed]#vimextmail.org.zone
$TTL86400
@INSOAns.extmail.org.root(
42;serial(d.adams)
3H;refresh
15M;retry
1W;expiry
1D);minimum
@INNSns.extmail.org.
nsINA127.0.0.1
@INMX3mail.extmail.org.
mailINA192.168.7.249
启动dns配置
[root@localhostnamed]#/etc/init.d/namedrestart
测试:
指定dns服务器
[root@localhostnamed]#vim/etc/resolv.conf
[root@localhostnamed]#cat/etc/resolv.conf
searchlocaldomain
nameserver192.168.7.249
测试dns服务器是否解析成功
[root@localhostnamed]#host-tmxextmail.org
extmail.orgmailishandledby3mail.extmail.org.
[root@localhostnamed]#nslookupmail.extmail.org
Server:
192.168.7.249
Address:
192.168.7.249#53
Name:
mail.extmail.org
Address:
192.168.7.249
===========
配置MTA:
===========
[root@mailnamed]#cd/etc/postfix/
[root@mailpostfix]#ls
配置文件解释
[root@mailpostfix]#lsreadme/#有各种配置文件参数的解释
生成新的配置文件:
[root@mailpostfix]#postconf-n>main.cf
编辑配置文件
[root@mailpostfix]#vimmain.cf
config_directory=/etc/postfix
mynetworks=127.0.0.1192.168.7.0/24#定义信任的邮件转发列表
myhostname=mail.extmail.org#定义主机名,必须的
mydomain=extmail.org#定义域名
mydestination=$mynetworks$myhostname#定义哪些是本域的邮件
mail_name=My_Postfix#定义登录服务器显示的信息
smtpd_banner=$myhostnameMySMTP$mail_name#定义欢迎信息
smtpd_error_sleep_time=0s#有错误,立即响应
message_size_limit=5120000#限制单个邮件的大小,字节
mailbox_size_limit=51200000#限制邮箱的大小
show_user_unknown_table_name=no#不显示未知的邮件
maximal_queue_lifetime=1d#邮件在邮件队列里的存活时间,1天
bounce_queue_lifetime=1d#邮件在弹回队列里的存活时间,1天
[root@mailpostfix]#/etc/init.d/postfixrestart
查看端口,是否正常监听
[root@mailpostfix]#netstat-antp|grep25
tcp000.0.0.0:
250.0.0.0:
*LISTEN14860/master
===================
配置验证用的mysql
安装所需软件
[root@mailpostfix]#yuminstall-ycourier-authlibcourier-authlib-mysqlcourier-authlib-devel
[root@mailpostfix]#cd/etc/authlib/
[root@mailauthlib]#ls
编辑配置文件
[root@mailauthlib]#vimauthmysqlrc
26MYSQL_SERVERlocalhost
27MYSQL_USERNAMEextmail
28MYSQL_PASSWORDextmail
49MYSQL_SOCKET/var/lib/mysql/mysql.sock
56MYSQL_PORT3306
68MYSQL_DATABASEextmail
83MYSQL_USER_TABLEmailbox
92MYSQL_CRYPT_PWFIELDpassword
113MYSQL_UID_FIELDuidnumber
119MYSQL_GID_FIELDgidnumber
128MYSQL_LOGIN_FIELDusername
133MYSQL_HOME_FIELDhomedir
150MYSQL_MAILDIR_FIELDmaildir
165MYSQL_QUOTA_FIELDquota
243MYSQL_SELECT_CLAUSEselectusername,password,"",uidnumber,gidnumber,concat('/home/domains/',homedir),concat('/home/domains/',maildir),quota,namefrommailboxwhereusername='$(local_part)@$(domain)'
[root@mailauthlib]#vimauthdaemonrc
27authmodulelist="authmysql"
34authmodulelistorig="authmysql"
启动验证服务
[root@mailauthlib]#/etc/init.d/courier-authlibstart
StartingCourierauthenticationservices:
authdaemond
安装mysql:
[root@mailauthlib]#yuminstall-ymysql-server
[root@mailauthlib]#/etc/init.d/mysqldstart
[root@mailauthlib]#cd/var/spool/
检查认证文件的所有者
[root@mailspool]#ls-ldauthdaemon/
drwxr-x---2daemondaemon4096Sep1311:
34authdaemon/
[root@mailspool]#lsauthdaemon/
pidpid.locksocket
改变认证文件的权限
[root@mailspool]#chmodo=rxauthdaemon/
[root@mailspool]#ls-ldauthdaemon/
drwxr-xr-x2daemondaemon4096Sep1311:
34authdaemon/
保证每个用户都能进入读取里面的验证信息
MRA配完了。
=========================
配置投递邮件的maildrop
安装所需的软件
[root@mailspool]#yuminstall-ymaildrop
Addingvmailgrouptosystem
Addingvmailusertosystem
[root@mailspool]#tail-1/etc/passwd
vuser:
x:
1000:
1000:
:
/home/domains:
/bin/true
[root@mailspool]#tail-1/etc/group
vgroup:
x:
1000:
[root@mailspool]#cd/etc/postfix/
[root@mailpostfix]#vimmaster.cf
"man5master"
#==========================================================================
#servicetypeprivateunprivchrootwakeupmaxproccommand+args
#(yes)(yes)(yes)(never)(100)
#==========================================================================
60#maildrop.SeethePostfixMAILDROP_READMEfilefordetails.
61#Alsospecifyinmain.cf:
maildrop_destination_recipient_limit=1
63maildropunix-nn--pipe
64flags=DRhuuser=vuserargv=maildrop-w90-d${user}@${nexthop}${recipient}${user}${extension}{nexthop}
[root@mailpostfix]#vimmain.cf
maildrop_destination_recipient_limit=1#一次投递一封邮件
测试:
[root@mailpostfix]#maildrop-v
maildrop2.0.4Copyright1998-2005DoublePrecision,Inc.
GDBMextensionsenabled.
CourierAuthenticationLibraryextensionenabled.
Maildirquotaextensionenabled.
ThisprogramisdistributedunderthetermsoftheGNUGeneralPublic
License.SeeCOPYINGforadditionalinformation.
MDA配完了
==================================
配置web服务器和收发邮件的webmail
安装所需软件
[root@mailpostfix]#yuminstall-yhttpd
编辑配置文件
[root@mailpostfix]#vim/etc/httpd/conf/httpd.conf
NameVirtualHost*:
80
80>
ServerAdminroot@mail.extmail.org
DocumentRoot/var/www/extsuite/extmail/html
ServerNamemail.extmail.org
ErrorLoglogs/extmail.org-error_log
CustomLoglogs/extmail.org-access_logcommon
scriptalias/extmail/cgi//var/www/extsuite/extmail/cgi/
alias/extmail/var/www/extsuite/extmail/html/
scriptalias/extman/cgi//var/www/extsuite/extman/cgi/
alias/extman/var/www/extsuite/extman/html/
suexecusergroupvuservgroup
配置webmail的前台邮箱:
[root@mailpostfix]#yuminstall-yextsuite-webmail
[root@mailpostfix]#cd/var/www/extsuite/extmail/
[root@mailextmail]#ls
配置文件:
[root@mailextmail]#cpwebmail.cf.defaultwebmail.cf
[root@mailextmail]#vimwebmail.cf
136SYS_MYSQL_USER=extmail
137SYS_MYSQL_PASS=extmail
138SYS_MYSQL_DB=extmail
139SYS_MYSQL_HOST=localhost
140SYS_MYSQL_SOCKET=/var/lib/mysql/mysql.sock
改变目录的所有者
[root@mailextmail]#chown-Rvuser:
vgroupcgi/
配置webmail的后台管理:
[root@mailextmail]#yuminstall-yextsuite-webman
[root@mailextman]#pwd
/var/www/extsuite/extman
[root@mailextman]#chown-Rvuser:
vgroupcgi/
创建目录,用来保存临时文件
[root@mailextman]#mkdir/tmp/extman
[root@mailextman]#chown-Rvuser:
vgroup/tmp/extman
[root@mailextman]#cddocs/
[root@maildocs]#ls
导入数据库:
[root@maildocs]#ls*.sql
extmail.sqlinit.sql
[root@maildocs]#mysql[root@maildocs]#mysql设置虚拟帐号+独立邮箱:
***
[root@maildocs]#cpmysql_virtual_alias_maps.cf/etc/postfix/
[root@maildocs]#cpmysql_virtual_domains_maps.cf/etc/postfix/
[root@maildocs]#cpmysql_virtual_mailbox_maps.cf/etc/postfix/
[root@maildocs]#vim/etc/postfix/main.cf
virtual_alias_maps=mysql:
/etc/postfix/mysql_virtual_alias_maps.cf
#定义虚拟邮箱的别名,别名的信息保存在mysql
virtual_mailbox_maps=mysql:
/etc/postfix/mysql_virtual_mailbox_maps.cf
#定义虚拟邮箱能够允许的帐户,帐户信息保存在mysql里
virtual_mailbox_domains=mysql:
/etc/postfix/mysql_virtual_domains_maps.cf
#定义虚拟邮箱能够接受哪些域名,域名的信息保存在mysql里
virtual_transport=maildrop:
#定义使用哪个程序进行邮件的投递操作
重启postfix
[root@maildocs]#/etc/init.d/postfixrestart
测试:
[root@maildocs]#/usr/sbin/authtest-sloginpostmaster@extmail.orgextmail
Authenticationsucceeded.
Authenticated:
postmaster@extmail.org(uid1000,gid1000)
HomeDirectory:
/home/domains/extmail.org/postmaster
Maildir:
/home/domains/extmail.org/postmaster/Maildir/
Quota:
104857600S
EncryptedPassword:
$1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
CleartextPassword:
extmail
Options:
(none)
成功了!
客户端登录测试:
后台管理:
http:
//mail.extmail.org/extman/
root@extmail.org
extmail*123*
前台界面:
http:
//mail.extmail.org/extmail/
可能出现的问题及解答
排错:
(1)
[root@mail~]#/usr/sbin/authtest-sloginpostmaster@extmail.orgextmail
AuthenticationFAILED:
Input/outputerror
[root@mail~]#vim/etc/authlib/authmysqlrc
(2)
[root@mail~]#/usr/sbin/authtest-sloginpostmaster@extmail.orgextmail
AuthenticationFAILED:
Operationnotpermitted
[root@mail~]#/etc/init.d/courier-authlibrestart