邮件收发服务器安装部署

(一)postfix的安装

0.修改host文件
线上的参考,如下
… …
127.0.0.1 xxxxxxx..net
a.b.c.d xxxxxxx.net
127.0.0.1 mail.xxxxxxx..net
… …

1.停用sendmail服务,并设置默认启动状态为关闭
# service sendmail stop
2.编译安装,源码编译及安装postfix(postfix-2.8.20.tar.gz)(版本号查看方法postconf -d | grep mail_version)
a. 创建postfix程序用户及程序组
# groupadd -g 2525 postfix
# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
# groupadd -g 2526 postdrop
# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
b.解包,预配置,编译,安装
# tar -zxvf postfix-2.8.20.tar.gz
# cd postfix-2.8.20
# make makefiles ‘CCARGS=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl’ ‘AUXLIBS=-L/usr/libsasl2 -lsasl2’ ;make ; make install
查看postfix支持的模块
# postconf -m
c.Postfix服务控制
# postfix start

d.简化postfix邮件服务器主配置文件main.cf
# cd /etc/postfix/
# ls
access bounce.cf.default generic LICENSE main.cf.default master.cf TLS_LICENSE virtual
aliases canonical header_checks main.cf makedefs.out relocated transport

# cp main.cf main.cf.bak
# postconf -n > main.cf

5.编辑主配置文件,添加以下几行
inet_interfaces = xxx.xxx.xxx.xxx, 127.0.0.1
myhostname = mail.xxx.xxx
mydomain = xxx.xxx
myorigin = $mydomain
mydestination = $mydomain, $myhostname
home_mailbox = Maildir/

//可参考线上的配置文件,如下
# cat main.cf |grep -v “^#\|^$”
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = mail.xxxxxxx.net
mydomain = xxxxxxx.net
inet_interfaces = all
inet_protocols = ipv4
mydestination = xxxxxxx.net
unknown_local_recipient_reject_code = 550
mynetworks = a.b.c.d/32, 127.0.0.0/8
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.6/samples
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

6.添加邮箱账号并测试
# groupadd mailusers
# useradd -g mailusers -s /sbin/nologin mailuser1
# useradd -g mailusers -s /sbin/nologin mailuser2
# passwd mailuser / mailuser2 密码都是passwd
# telnet mail.xxx.xxx 25
helo mail.xxx.xxx
mail from:mailuser1@xxx.xxx
rcpt to:mailuser2@xxx.xxx
data
subject:A test mail
hello
2019
bye
.
quit

配置开机启动:
# cat /etc/init.d/postfix

#!/bin/bash
#
# postfix Postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
# that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ $NETWORKING = “no” ] && exit 3

[ -x /usr/sbin/postfix ] || exit 4
[ -d /etc/postfix ] || exit 5
[ -d /var/spool/postfix ] || exit 6

RETVAL=0
prog=”postfix”

start() {
# Start daemons.
echo -n $”Starting postfix: “
/usr/bin/newaliases >/dev/null 2>&1
/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $”$prog start”
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
echo
return $RETVAL
}

stop() {
# Stop daemons.
echo -n $”Shutting down postfix: “
/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $”$prog stop”
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
echo
return $RETVAL
}

reload() {
echo -n $”Reloading postfix: “
/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $”$prog reload”
RETVAL=$?
echo
return $RETVAL
}

abort() {
/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $”$prog abort”
return $?
}

flush() {
/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $”$prog flush”
return $?
}

check() {
/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $”$prog check”
return $?
}

restart() {
stop
start
}

# See how we were called.
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
abort)
abort
;;
flush)
flush
;;
check)
check
;;
status)
status master
;;
condrestart)
[ -f /var/lock/subsys/postfix ] && restart || :
;;
*)
echo $”Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}”
exit 1
esac

exit $?

chkconfig –add postfix
chkconfig postfix on

(二)Dovecot的安装
编译安装Dovecot邮件接收服务器(dovecot-2.0.12.tar.gz)
a.创建程序用户
# useradd -M -s /sbin/nologin dovecot
# useradd -M -s /sbin/nologin dovenull
b.编译安装
# cd /opt
# tar zxf dovecot-2.0.12.tar.gz
# cd dovecot-2.0.12
# ./configure –sysconfdir=/etc ; make ; make install
c.添加系统服务dovecot
# cp doc/dovecot-initd.sh /etc/init.d/dovecot
# chmod +x /etc/init.d/dovecot
# chkconfig –add dovecot
# chkconfig dovecot on
d.建立配置文件,并启动服务
a. 建立配置文档
# cp -r /usr/local/share/doc/dovecot/example-config/* /etc/dovecot/
auth required pam_nologin.so
auth include system-auth
account include system-auth
session include system-auth
b. 调整主配置文件
83 !include conf.d/10-auth.conf
84 ssl = no
85 disable_plaintext_auth = no
86 mail_location = maildir:~/Maildir
e. 启动dovecot
# /etc/init.d/dovecot start

# netstat -antpl | grep dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 16028/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 16028/dovecot
tcp 0 0 :::110 :::* LISTEN 16028/dovecot
tcp 0 0 :::143 :::* LISTEN 16028/dovecot
f. POP3接收邮件测试
[root@svr1 dovecot-2.0.12]# telnet mail.benet.com 110
user mailuser2
pass passwd
list
retr 1
quit

iptables配置:
可参考线上防火墙

Print Friendly

发表评论

电子邮件地址不会被公开。 必填项已用*标注