CentOS7 部署mail服务

1.基础环境配置
主机名IP地址节点
mail.testmail.com172.16.51.20Mail服务器
master172.16.51.8DNS服务器

(1)更改两台虚拟机的主机名

[root@localhost ~]# hostnamectl set-hostname mail.testmail.com
[root@localhost ~]# bash

[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash

(2)两台虚拟机关闭防火墙和selinux

[root@mail ~]# systemctl stop firewalld
[root@mail ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@mail ~]# setenforce 0

[root@master ~]# systemctl stop firewalld
[root@master ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@master ~]# setenforce 0

(3)两台虚拟机配置本地yum源

[root@mail ~]# mkdir /opt/centos
[root@mail ~]# mount /dev/cdrom /opt/centos
mount: /dev/sr0 is write-protected, mounting read-only
[root@mail ~]# mv /etc/yum.repos.d/* /home/
[root@mail ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1

[root@master ~]# mkdir /opt/centos
[root@master ~]# mount /dev/cdrom /opt/centos
mount: /dev/sr0 is write-protected, mounting read-only
[root@master ~]# mv /etc/yum.repos.d/* /home/
[root@master ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
2.DNS服务安装与配置

(1)安装和配置DNS

[root@mail ~]# yum -y install bind-chroot bind-utils
[root@mail ~]# systemctl restart named
[root@mail ~]# systemctl enable named
[root@mail ~]# systemctl status named

[root@master ~]# yum -y install bind-chroot bind-utils
[root@master ~]# systemctl restart named
[root@master ~]# systemctl enable named
[root@master ~]# systemctl status named

(2)启动DNS服务

[root@mail ~]# yum install -y net-tools
[root@mail ~]# netstat -lntp | grep named

[root@master ~]# yum install -y net-tools
[root@master ~]# netstat -lntp | grep named

(3)修改DNS配置文件

[root@mail ~]# vi /etc/named.conf
listen-on port 53 { any; }; //监听所有的53号端口
   ...
   allow-query   { any; }; //允许所有的查询

[root@master ~]# vi /etc/named.conf
listen-on port 53 { any; };
   ...
   allow-query   { any; };

(4)配置DNS服务器

[root@master ~]# cp -rf /var/named/named.localhost /var/named/testmail.com.zone //拷贝模版
[root@master ~]# cd /var/named
[root@master named]# vi testmail.com.zone
$TTL 1D
@    IN SOA testmail.com. admin.testmail.com. (
                   0    ; serial
                   1D   ; refresh
                   1H   ; retry
                   1W   ; expire
                   3H )  ; minimum
   IN NS dns.testmail.com.
   IN MX 10 mail
dns IN A 172.16.51.20
mail IN A 172.16.51.20
www IN A 172.16.51.20
smtp IN A 172.16.51.20
[root@master named]# chmod 755 testmail.com.zone
[root@master named]# vi /etc/named.rfc1912.zones
//在文件最下面添加解析内容
zone "testmail.com" IN{
   type master;
   file "testmail.com.zone";
};

[root@master named]# named-checkconf /etc/named.conf //conf文件检查
[root@master named]# named-checkzone testmail.com testmail.com.zone //zone文件检查

[root@master named]# systemctl restart named
[root@master named]# systemctl status named
[root@master named]# vi /etc/resolv.conf
nameserver 172.16.51.8
nameserver 172.16.51.20
[root@master named]# ping www.testmail.com //测试DNS解析是否正常

[root@master named]# vi /etc/named.rfc1912.zones
zone "51.16.172.in-addr.arpa" IN{
   type master;
   file "20.51.16.172.in-addr.local";
};
[root@master named]# cp -p testmail.com.zone 20.51.16.172.in-addr.local
[root@master named]# vi 20.51.16.172.in-addr.local
$TTL 1D
@    IN SOA testmail.com. admin.testmail.com. (
                   0    ; serial
                   1D   ; refresh
                   1H   ; retry
                   1W   ; expire
                   3H )  ; minimum
   IN NS dns.testmail.com.
   148 IN PTR mail.testmail.com.
   148 IN PTR www.testmail.com.

[root@master named]# named-checkzone mail.testmail.com 20.51.16.172.in-addr.local //检查配置
[root@master named]# systemctl restart named
[root@master named]# dig -x 172.16.51.20

(5)配置Mail服务器

[root@mail ~]# vi /etc/named.rfc1912.zones
zone "testmail.com" IN {
   type slave;
   file "slaves/testmail.com.zone";
   masters{172.16.51.8;};
   };
zone "51.16.172.in-addr.arpa" IN{
   type slave;
   file "slaves/20.51.16.172.in-addr.local";
   masters{172.16.51.8;};
   };
[root@mail ~]# vi /etc/resolv.conf
nameserver 172.16.51.20
nameserver 172.16.51.8
[root@mail ~]# systemctl restart named
[root@mail ~]# dig -t A mail.testmail.com

(6)测试配置是否成功

在DNS服务器上关闭named服务,使用3条查询命令,有则说明配置成功
[root@master named]# systemctl stop named
[root@master named]# dig dns.testmail.com
[root@master named]# dig -x 172.16.51.20
[root@master named]# nslookup dns.testmail.com

在Mail服务器上查看是否有文件,有则说明配置成功
[root@mail ~]# ll /var/named/slaves/
3.在Mail服务器上安装配置Postfix以发送邮件
[root@mail ~]# yum -y install postfix
[root@mail ~]# postconf -a //检查兼容性
[root@mail ~]# vi /etc/postfix/main.cf
#修改邮局主机名
myhostname = mail.testmail.com
#修改邮局域名
mydomain = testmail.com
#寄出邮件域名,删除注释
myorigin = $mydomain
#修改监听所有网卡,删除inet_interfaces = all的注释,将inet_interfaces = localhost注释
inet_interfaces = all
#inet_interfaces = localhost
#修改可接收邮件的主机名和域名,可被中继的域名
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#修改可接收邮件的主机名和域名,可被中继的主机
mynetworks = 172.16.51.0/24, 127.0.0.0/8
#取消注释
home_mailbox = Maildir/
#指定信任网段类型,取消注释
mynetworks_style = host
#指定允许中转邮件的域名,取消注释
relay_domains = $mydestination

[root@mail ~]# postfix check //检查配置文件是否有语法错误
[root@mail ~]# systemctl enable postfix
[root@mail ~]# systemctl restart postfix

[root@mail ~]# useradd cwl //创建测试邮件接收用户,设置密码为“111111”
[root@mail ~]# echo "111111" | passwd --stdin cwl

[root@mail ~]# yum -y install telnet
[root@mail ~]# telnet mail.testmail.com 25 //Telnet连接邮件服务器25端口,发送邮件
Trying 172.16.51.20...
Connected to mail.testmail.com.
Escape character is '^]'.
220 mail.testmail.com ESMTP Postfix
mail from:root@testmail.com (发件人,需要自行输入)
250 2.1.0 Ok
rcpt to:cwl (收件人,需要自行输入)
250 2.1.5 Ok
data (填写邮件,需要自行输入)
354 End data with <CR><LF>.<CR><LF>
hello,this is test mail. (输入邮件内容,需要自行输入)
. (以“.”结束输入,需要自行输入)
250 2.0.0 Ok: queued as BA6886095AAC
quit (退出,需要自行输入)
221 2.0.0 Bye
Connection closed by foreign host.

[root@mail ~]# tail /var/log/maillog|grep sent //查看发送状态
Jun 20 20:41:42 localhost postfix/local[3764]: B281A2086EC3: to=
<cwl@testmail.com>, orig_to=<cwl>, relay=local, delay=12, delays=12/0.01/0/0,
dsn=2.0.0, status=sent (delivered to maildir)
4. 在Mail服务器上安装配置Dovecot以接收邮件
[root@mail ~]# yum install -y dovecot
[root@mail ~]# vi /etc/dovecot/dovecot.conf
删除注释#
protocols = imap pop3 lmtp
listen = *, ::

[root@mail ~]# vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no

[root@mail ~]# vi /etc/dovecot/conf.d/10-mail.conf
删除注释#
mail_location = maildir:~/Maildir

[root@mail ~]# systemctl restart dovecot
[root@mail ~]# telnet mail.testmail.com 110
Trying 172.16.51.20...
Connected to mail.testmail.com.
Escape character is '^]'.
+OK Dovecot ready.
user cwl (登录用户,需要自行输入)
+OK
pass 111111 (密码,需要自行输入)
+OK Logged in.
List (邮件列表,需要自行输入)
+OK 1 messages:
1 404
.
retr 1 (输入邮件编号查看邮件,需要自行输入)
+OK 411 octets
Return-Path: <root@testmail.com>
X-Original-To: cwl
Delivered-To: cwl@mail.testmail.com
Received: from localhost (localhost [127.0.0.1])
   by mail.testmail.com (Postfix) with SMTP id BA6886095AAC
   for <cwl>; Thu, 20 Jun 2024 20:55:48 -0400 (EDT)
Message-Id: <20240621005551.BA6886095AAC@mail.testmail.com>
Date: Thu, 20 Jun 2024 20:55:48 -0400 (EDT)
From: root@testmail.com

hello,this is test mail.
.
quit (退出,需要自行输入)
+OK Logging out.
Connection closed by foreign host.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值