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/hosts192.168.0.1 ns1.benet.com ns1192.168.0.1 mail.benet.com mail[root@localhost ~]# vim /etc/resolv.conf nameserver 192.168.0.1[root@localhost ~]# vim /etc/sysconfig/networkHOSTNAME=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.confoptions { 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.1mail IN A 192.168.0.1www 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 .区域配置文件的语法检查:[root@mail named]# named-checkzone benet.com benet.com.zone zone benet.com/IN: loaded serial 42OK[root@mail named]# named-checkzone benet.com 192.168.0.arpa zone benet.com/IN: loaded serial 42OK更改正向、反向区域配置文件的属主为named并启动named服务[root@mail named]# chown named benet.com.zone [root@mail named]# chown named 192.168.0.arpa [root@mail named]# service named startDNS的测试:[root@mail named]# nslookup
Server: 192.168.0.1Address: 192.168.0.1#53Name:
Address: 192.168.0.1[root@mail named]# nslookup 192.168.0.1
Server: 192.168.0.1Address: 192.168.0.1#531.0.168.192.in-addr.arpa name = .
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 stopShutting 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.el5cyrus-sasl-plain-2.1.22-5.el5cyrus-sasl-devel-2.1.22-5.el5cyrus-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 busyumount: /: 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
cyrusdovecot[root@mail postfix-2.8.2]# postfix start postfix/postfix-script: starting the Postfix mail systempostfix主配置文件的生成:[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.1myhostname = mail.benet.commydomain = benet.commyorigin = $mydomainmydestination = $mydomain, $myhostnamehome_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 xiaoqiChanging password for user xiaoqi.New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.[root@mail postfix-2.8.2]# passwd lisiChanging 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 Postfixhelo mail.benet.com250 mail.benet.commail from:xiaoqi@benet.com250 2.1.0 Okrcpt to:lisi@benet.com250 2.1.5 Okdata354 End data with <CR><LF>.<CR><LF>subject: a test mailhello lisiwo shi xiaoqi,this is a test mail.250 2.0.0 Ok: queued as 4B25F3B88DBquit221 2.0.0 ByeConnection 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: <>X-Original-To: Delivered-To: Received: from mail.benet.com (ns1.benet.com [192.168.0.1]) by mail.benet.com (Postfix) with SMTP id 4B25F3B88DB for <>; Thu, 4 Apr 2013 02:53:40 -0400 (EDT)subject: a test mailMessage-Id: <>Date: Thu, 4 Apr 2013 02:53:40 -0400 (EDT)From: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 dovenulldovecot源码包的安装:
[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 dovecotdovecot主配置文件的生成
[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.soauth include system-authaccount include system-authsession 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 dovecottcp 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/dovecotPOP3接收邮件测试:[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+OKpass 123.com+OK Logged in.list+OK 1 messages:1 469.retr 1+OK 469 octetsReturn-Path: <>X-Original-To: Delivered-To: Received: from mail.benet.com (ns1.benet.com [192.168.0.1]) by mail.benet.com (Postfix) with SMTP id 4B25F3B88DB for <>; Thu, 4 Apr 2013 02:53:40 -0400 (EDT)subject: a test mailMessage-Id: <>Date: Thu, 4 Apr 2013 02:53:40 -0400 (EDT)From: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服务器都构建成功。================================================================================================================================================================================================================================================刚出道的 小菜鸟 (此实验在虚拟机中做的)