搭建Postfix邮件服务器
(文章copy,不过一些点没注意到,补充了一些,其他自己搭建就知道失误在哪,错误百度,最后步骤是操作,打字是看不懂的可以自己查,需要请看下个文章,其中mail的用户可以多个自行添加,文章为加3)
1 将sendmail服务停止
[root@mail ~]# service sendmail stop //停止sendmail服务
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
2 安装配置dns (略)
MX记录
3 安装postfix
[root@localhost ~]# cd /media/RHEL_5.5\ i386\ DVD/Server/
[root@localhost Server]# rpm -ivh postfix-2.3.3-2.1.el5_2.i386.rpm
4 配置postfix
[root@mail ~]# vim /etc/postfix/main.cf
myhostname = mail.159.cn
mydomain = 159.cn
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, $mydomain
mynetworks = 172.16.42.0, 127.0.0.0/8
relay_domains = 159.cn
wq—退出
5 在postfix配置虚拟别名
#virtual
virtual_alias_domains = sina.com
virtual_alias_maps = hash:/etc/postfix/virtual //在main.cf文件中写入这两行
[root@mail ~]# vim /etc/postfix/virtual //配置virtual
[root@mail ~]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
[root@mail ~]# vim /etc/postfix/main.cf
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases//检查postfix配置文件中有这两条
[root@mail ~]# vim /etc/aliases//配置用户别名
mail: mail,mail1,mail2,mail3
[root@mail ~]# postalias /etc/aliases
[root@mail ~]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system//注意这里错误一般是postalia服务器没开,还有防火墙限制,用了我挺多时间找
6 配置smtp
[root@mail ~]# rpm -qa | grep sasl
cyrus-sasl-plain-2.1.22-5.el5_4.3
cyrus-sasl-lib-2.1.22-5.el5_4.3
cyrus-sasl-2.1.22-5.el5_4.3
[root@mail ~]# saslauthd -v
saslauthd 2.1.22
authentication mechanisms: getpwent kerberos5 pam rimap shadow ldap
[root@mail ~]# vi /etc/sysconfig/saslauthd
MECH=shadow //将认证方式改为shadow
[root@mail ~]# /etc/init.d/saslauthd start
Starting saslauthd: [ OK ]
[root@mail ~]# chkconfig --level 35 saslauthd on
[root@mail ~]# useradd mail1 //创建一个mail1用户,用来测试
[root@mail ~]# passwd mail1
Changing password for user mail1.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@mail ~]# testsaslauthd -u mail1 -p '123456'
0: OK "Success." //验证成功
在main.cf 中加入如下配置。
[root@localhost ~]# vi /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = ''
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
[root@mail ~]# postfix reload //重新加载postfix
postfix/postfix-script: refreshing the Postfix mail system
[root@mail ~]# telnet 172.16.42.165 25 //测试
Trying 192.168.1.104...
Connected to mail.159.cn (192.168.1.104).
Escape character is '^]'.
220 mail.159.cn ESMTP Postfix
ehlo 159.cn
250-mail.159.cn
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host. //测试成功
7 安装和配置dovecot
[root@mail Server]# rpm -ivh perl-DBI-1.52-2.el5.i386.rpm
warning: perl-DBI-1.52-2.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing... ########################################### [100%]
1:perl-DBI ########################################### [100%]
[root@mail Server]# rpm -ivh mysql-5.0.77-4.el5_4.2.i386.rpm
warning: mysql-5.0.77-4.el5_4.2.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing... ########################################### [100%]
1:mysql ########################################### [100%]
[root@mail Server]# rpm -ivh dovecot-1.0.7-7.el5.i386.rpm
warning: dovecot-1.0.7-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: Failed dependencies:
libpq.so.4 is needed by dovecot-1.0.7-7.el5.i386
[root@mail Server]#
[root@mail Server]# rpm -ivh postgresql-libs-8.1.18-2.el5_4.1.i386.rpm
warning: postgresql-libs-8.1.18-2.el5_4.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing... ########################################### [100%]
1:postgresql-libs ########################################### [100%]
[root@mail Server]# rpm -ivh dovecot-1.0.7-7.el5.i386.rpm
warning: dovecot-1.0.7-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing... ########################################### [100%]
1:dovecot ########################################### [100%]
[root@mail ~]#vim /etc/dovecot.conf
protocols = pop3 pop3s
protocol pop3 {
listen = *:10100
# ..
}
[root@mail ~]# service dovecot start
启动 Dovecot Imap: [确定]
[root@mail ~]# chkconfig dovecot on
8cyrus-imapd服务安装于配置
Db4
cyrus-imapd
cyrus-imapd-perl
cyrus-imapd-utils
db4-utils
lm_sensors
[root@mail Server]# rpm -ivh cyrus-imapd-perl-2.3.7-7.el5_4.3.i386.rpm
warning: cyrus-imapd-perl-2.3.7-7.el5_4.3.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: failed to stat /media/RHEL_5.5 i386 DVD: 没有那个文件或目录
Preparing... ########################################### [100%]
1:cyrus-imapd-perl ########################################### [100%]
[root@mail Server]#
[root@mail Server]# rpm -ivh cyrus-imapd-utils-2.3.7-7.el5_4.3.i386.rpm
[root@mail Server]# rpm -ivh db4-utils-4.3.29-10.el5.i386.rpm
[root@mail Server]# rpm -ivh lm_sensors-2.10.7-9.el5.i386.rpm
[root@mail Server]# rpm -ivh cyrus-imapd-2.3.7-7.el5_4.3.i386.rpm
[root@mail Server]# rpm -ivh cyrus-imapd-devel-2.3.7-7.el5_4.3.i386.rpm
[root@mail ~]# vim /etc/postfix/main.cf //修改以下文件
mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp
[root@mail ~]# service cyrus-imapd restart
正在关闭cyrus-imapd: [确定]
导出cyrus-imapd数据库: [确定]
导入cyrus-imapd数据库: [确定]
启动cyrus-imapd: [确定]
[root@mail ~]# chkconfigcyrus-imapd on
[root@mail ~]# chkconfig --list cyrus-imapd
cyrus-imapd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
10 添加用户,并设置用户邮箱
[root@mail ~]# passwd cyrus
Changing password for user cyrus.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@mail ~]# cat /etc/shadow
mail1:$1$QnL01QC.$LNczdCW9f3buqoxcRiRpk.:14772:0:99999:7::: //shadow
dovecot:!!:14772::::::
cyrus:$1$/8WvEEC8$6KVzTAY7ByqSyMRzMQkmS/:14772::::::
mail2:$1$HX.I.cOD$F.N2yM8VbbRyCVdynWf2K.:14772:0:99999:7:::
mail3:$1$gaE/q13U$lWKOj7d.aKeSW4ZuyvXKM0:14772:0:99999:7:::
mail4:$1$d.mlgRGf$hvaDYlOLY331C6MqBXpyD1:14772:0:99999:7:::
[root@mail ~]# /usr/bin/cyradm -u cyrus localhost //创建用户邮箱,这里用3用户,如果是自己搭建测试,可以先配mail1
IMAP Password:
localhost.localdomain>createmailbox user.mail1
localhost.localdomain>createmailbox user.mail1.Send
localhost.localdomain>createmailbox user.mail1.Trash
localhost.localdomain>createmailbox user.mail1.Drafts
localhost.localdomain>setquota user.mail 3000
quota:3000 //设置用户邮箱配额
setquota: Mailbox does not exist
localhost.localdomain>createmailbox user.mail2
localhost.localdomain>createmailbox user.mail2.Send
localhost.localdomain>createmailbox user.mail2.Trash
localhost.localdomain>createmailbox user.mail2.Drafts
localhost.localdomain>createmailbox user.mail3
localhost.localdomain>createmailbox user.mail3.Send
localhost.localdomain>createmailbox user.mail3.Trash
localhost.localdomain>createmailbox user.mail3.Drafts
11 squirrelmail安装于配置
[root@localhost Server]# rpm -ivh squirrelmail-1.4.8-5.el5_4.10.noarch.rpm //安装squirrelmail
[root@mail ~]# /usr/share/squirrelmail/config/conf.pl
========================================================
中间的操作需要图,明天发
======================================
[root@mail ~]# vim /etc/httpd/conf/httpd.conf //修改apache配置(可以不配置)
ServerNamemail.159.cn:80
[root@mail ~]# service httpd restart //重启apache服务
停止httpd: [确定]
启动httpd: [确定]
12 测试
本机测试,mail1给自己发信,mail2,mail3都同时收到了