postfix的搭建
实验环境:
前提:一台RHEL5(LAMP):作为服务器,四个角色:DNS服务器 邮件服务器 postfix服务器 dovecot服务器
一台xp:作为客户端 :用来验证邮件的收发
环境的搭建:
=========================
第一步:挂装光盘:系统盘
[root@localhost ~]#umount -a
[root@localhost ~]#mount /dev/cdrom /media
第二步:设置ip地址 修改/etc/hosts /etc/resolv.conf /etc/sysconfig/network
[root@localhost ~]# setup
[root@localhost ~]# vim /etc/hosts
192.168.0.1 ns1.benet.com ns1
192.168.0.1 mail.benet.com mail
[root@localhost ~]# vim /etc/resolv.conf
nameserver 192.168.0.1
[root@localhost ~]# vim /etc/sysconfig/network
HOSTNAME=mail.benet.com
第三步:重启网络服务并让其在开机时在35运行级别下随机启动
[root@localhost ~]# service network restart
[root@localhost ~]# chkconfig --level 35 network on
第四步:重启虚拟机以便主机名生效
[root@localhost ~]# reboot
第五步:DNS的搭建:
[root@mail ~]# rpm -qa |grep bind
[root@mail ~]# cd /media/Server/
[root@mail Server]# rpm -vih bind-9.3.6-4.P1.el5.i386.rpm bind-chroot-9.3.6-4.P1.el5.i386.rpm caching-nameserver-9.3.6-4.P1.el5.i386.rpm (软件包的安装)
主配置文件的编辑:
[root@mail Server]# cd /var/named/chroot/etc/
[root@mail etc]# vim named.conf
options {
directory "/var/named";
};
zone "benet.com" IN {
type master;
file "benet.com.zone";
};
zone "0.168.192.in-addr.arpa" IN {
type master;
file "192.168.0.arpa";
};
主配置文件的语法检查:
[root@mail etc]# named-checkconf named.conf
区域配置文件的编辑:
[root@mail ~]# cd /var/named/chroot/var/named/
[root@mail named]# cp localdomain.zone benet.com.zone
[root@mail named]# cp localhost.zone 192.168.0.arpa
[root@mail named]# vim benet.com.zone (正向区域配置文件)
$TTL 86400
@ IN SOA benet.com. admin.benet.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns1.benet.com.
IN MX 10 mail.benet.com.
ns1 IN A 192.168.0.1
mail IN A 192.168.0.1
www IN A 192.168.0.1
[root@mail named]# vim 192.168.0.arpa(反向区域配置文件)
$TTL 86400
@ IN SOA benet.com. admin.benet.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns1.benet.com.
IN MX 10 mail.benet.com.
1 IN PTR ns1.benet.com.
1 IN PTR mail.benet.com.
1 IN PTR www.benet.com.
区域配置文件的语法检查:
[root@mail named]# named-checkzone benet.com benet.com.zone
zone benet.com/IN: loaded serial 42
OK
[root@mail named]# named-checkzone benet.com 192.168.0.arpa
zone benet.com/IN: loaded serial 42
OK
更改正向、反向区域配置文件的属主为named并启动named服务
[root@mail named]# chown named benet.com.zone
[root@mail named]# chown named 192.168.0.arpa
[root@mail named]# service named start
DNS的测试:
[root@mail named]# nslookup www.benet.com
Server: 192.168.0.1
Address: 192.168.0.1#53
Name: www.benet.com
Address: 192.168.0.1
[root@mail named]# nslookup 192.168.0.1
Server: 192.168.0.1
Address: 192.168.0.1#53
1.0.168.192.in-addr.arpa name = www.benet.com.
1.0.168.192.in-addr.arpa name = mail.benet.com.
1.0.168.192.in-addr.arpa name = ns1.benet.com.
到此环境搭建完毕,做快照DNS
============================================================================================
为了避免发生端口冲突、程序冲突的现象,关闭sendmail服务并让其随机关闭
[root@mail ~]# service sendmail status
sendmail (pid 2501) is running...
[root@mail ~]# service sendmail stop
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
[root@mail ~]# chkconfig --level 35 sendmail off
检查一下postfix所支持的smtp认证所需的软件是否已经安装好
[root@mail ~]# rpm -qa |grep cyrus
cyrus-sasl-lib-2.1.22-5.el5
cyrus-sasl-plain-2.1.22-5.el5
cyrus-sasl-devel-2.1.22-5.el5
cyrus-sasl-2.1.22-5.el5
为了加强对服务器权限的控制,创建专门的运行用户和组
[root@mail ~]# groupadd -g 1200 postdrop
[root@mail ~]# groupadd -g 1000 postfix
[root@mail ~]# useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix
挂第十章的光盘
[root@mail ~]# umount -a
umount: /var/lib/nfs/rpc_pipefs: device is busy
umount: /: device is busy
[root@mail ~]# mount /dev/cdrom /media/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@mail ~]# cd /media/
[root@mail media]# ls
dovecot-2.0.12.tar.gz postfix-2.8.2.tar.gz
确定光盘挂装好以后,将所需要的软件包给复制到/root,切记不可在光盘的根目录下直接解压
[root@mail media]# cp dovecot-2.0.12.tar.gz postfix-2.8.2.tar.gz /root
postfix的源代码安装过程:解压 编译前的预配置 编译 安装
[root@mail ~]# tar zxvf postfix-2.8.2.tar.gz -C /usr/src/cd /usr/src/postfix-2.8.2/
[root@mail postfix-2.8.2]# make makefiles 'CCARGS=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' 'AUXLIBS=-L/usr/lib/sasl2 -lsasl2';make;make install
接下来会出现一个交互式的界面,一路回车
一定要确保看到这两种认证方式:
[root@mail postfix-2.8.2]# postconf -a
cyrus
dovecot
[root@mail postfix-2.8.2]# postfix start
postfix/postfix-script: starting the Postfix mail system
postfix主配置文件的生成:
[root@mail postfix-2.8.2]# postconf -n > tmp.file
[root@mail postfix-2.8.2]# mv /etc/postfix/main.cf /etc/postfix/main.cf.bak
[root@mail postfix-2.8.2]# mv tmp.file /etc/postfix/main.cf
配置SMTP发信服务:
[root@mail postfix-2.8.2]# vim /etc/postfix/main.cfinet_interfaces = 192.168.0.1, 127.0.0.1
myhostname = mail.benet.com
mydomain = benet.com
myorigin = $mydomain
mydestination = $mydomain, $myhostname
home_mailbox = Maildir/
[root@mail postfix-2.8.2]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
添加邮箱账号,以方便测试用
[root@mail postfix-2.8.2]# groupadd mailusers
[root@mail postfix-2.8.2]# useradd -g mailusers -s /sbin/nologin xiaoqi
[root@mail postfix-2.8.2]# useradd -g mailusers -s /sbin/nologin lisi
[root@mail postfix-2.8.2]# passwd xiaoqi
Changing password for user xiaoqi.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@mail postfix-2.8.2]# passwd lisi
Changing password for user lisi.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
SMTP的发送邮件测试:
[root@mail ~]# telnet mail.benet.com 25
Trying 192.168.0.1...
Connected to mail.benet.com (192.168.0.1).
Escape character is '^]'.
220 mail.benet.com ESMTP Postfix
helo mail.benet.com
250 mail.benet.com
mail from:xiaoqi@benet.com
250 2.1.0 Ok
rcpt to:lisi@benet.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject: a test mail
hello lisi
wo shi xiaoqi,this is a test mail
.
250 2.0.0 Ok: queued as 4B25F3B88DB
quit
221 2.0.0 Bye
Connection closed by foreign host.
去lisi的宿主目录下去查看:
[root@mail ~]# cd /home/lisi/
[root@mail lisi]# ls
Maildir
[root@mail lisi]# cd Maildir/
[root@mail Maildir]# ls
cur new tmp
[root@mail Maildir]# cd new/
[root@mail new]# ls
1365058456.Vfd00Id001aM607518.mail.benet.com
[root@mail new]# cat 1365058456.Vfd00Id001aM607518.mail.benet.com
Return-Path: <xiaoqi@benet.com>
X-Original-To: lisi@benet.com
Delivered-To: lisi@benet.com
Received: from mail.benet.com (ns1.benet.com [192.168.0.1])
by mail.benet.com (Postfix) with SMTP id 4B25F3B88DB
for <lisi@benet.com>; Thu, 4 Apr 2013 02:53:40 -0400 (EDT)
subject: a test mail
Message-Id: <20130404065349.4B25F3B88DB@mail.benet.com>
Date: Thu, 4 Apr 2013 02:53:40 -0400 (EDT)
From: xiaoqi@benet.com
hello lisi
wo shi xiaoqi,this is a test mail
若能够看到如上结果,则表示postfix服务器搭建成功。
部署dovecot
先创建dovecot的运行用户
[root@mail ~]# useradd -M -s /sbin/nologin dovecot
[root@mail ~]# useradd -M -s /sbin/nologin dovenull
dovecot源码包的安装:
[root@mail ~]# tar zxvf dovecot-2.0.12.tar.gz -C /usr/src/
[root@mail ~]# cd /usr/src/dovecot-2.0.12/
[root@mail dovecot-2.0.12]# ./configure --sysconfdir=/etc/ ;make;make install
将dovecot添加为系统服务:
[root@mail dovecot-2.0.12]# cp doc/dovecot-initd.sh /etc/init.d/dovecot
[root@mail dovecot-2.0.12]# chmod +x /etc/init.d/dovecot
[root@mail dovecot-2.0.12]# chkconfig --add dovecot
dovecot主配置文件的生成
[root@mail ~]# cp -r /usr/local/share/doc/dovecot/example-config/* /etc/dovecot/
若要支持系统用户认证,则必须要创建PAM认证文件
[root@mail ~]# vim /etc/pam.d/dovecot
auth required pam_nologin.so
auth include system-auth
account include system-auth
session include system-auth
调整主配置文件:(修改20行、83,手动添加后三行)
[root@mail ~]# vim /etc/dovecot/dovecot.conf
20 protocols = imap pop3
83 !include conf.d/10-auth.conf
84 ssl = no
85 disable_plaintext_auth = no
86 mail_location = maildir:~/Maildir
启动dovecot服务并查看其端口号,确保110、143端口都处于监听状态
[root@mail ~]# service dovecot start
Starting Dovecot.
[root@mail ~]# netstat -anpt |grep dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 3538/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 3538/dovecot
tcp 0 0 :::110 :::* LISTEN 3538/dovecot
tcp 0 0 :::143 :::* LISTEN 3538/dovecot
POP3接收邮件测试:
[root@mail ~]# telnet mail.benet.com 110
Trying 192.168.0.1...
Connected to mail.benet.com (192.168.0.1).
Escape character is '^]'.
+OK Dovecot ready.
user lisi
+OK
pass 123.com
+OK Logged in.
list
+OK 1 messages:
1 469
.
retr 1
+OK 469 octets
Return-Path: <xiaoqi@benet.com>
X-Original-To: lisi@benet.com
Delivered-To: lisi@benet.com
Received: from mail.benet.com (ns1.benet.com [192.168.0.1])
by mail.benet.com (Postfix) with SMTP id 4B25F3B88DB
for <lisi@benet.com>; Thu, 4 Apr 2013 02:53:40 -0400 (EDT)
subject: a test mail
Message-Id: <20130404065349.4B25F3B88DB@mail.benet.com>
Date: Thu, 4 Apr 2013 02:53:40 -0400 (EDT)
From: xiaoqi@benet.com
hello lisi
wo shi xiaoqi,this is a test mail
.
quit
+OK Logging out.
Connection closed by foreign host.
若能看到上述结果,则说明dovecot服务器搭建成功。创建dovecot快照
另外要到客户端xp去做测试:记得一定要填写首选DNS服务器:192.168.0.1
使用客户端的OE去做测试,创建两个用户xiaoqi lisi xiaoqi给lisi发信,若lisi能够收到则表示postfix和dovecot服务器都构建成功。========================================================================================================================
========================================================================================================================
刚出道的 小菜鸟 (此实验在虚拟机中做的)
转载于:https://blog.51cto.com/5983944/1287626