初衷:在测试nagios的时候,QQ企业邮局直接拒收(查看记录才知道),163邮箱收信不及时(我以为我nagios配置错误了),为了解决如上两个问题,我决定自己配置一个邮局系统。
[root@mail /]# uname -a
Linux mail.selmy.org 3.16.5-x86_64-linode46 #1 SMP Mon Oct 13 09:42:16 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
准备工作:
[root@mail /]# mkdir /mos
[root@mail /]# cd /mos
[root@mail mos]# wget http://mirror.extmail.org/iso/emos/EMOS_1.6_x86_64.iso
[root@mail mos]# yum install createrepo -y
[root@mail mos]# mkdir /mnt/EMOS
[root@mail mos]# mount -o loop /mos/EMOS_1.6_x86_64.iso /mnt/EMOS
mount: /mos/EMOS_1.6_x86_64.iso is write-protected, mounting read-only
[root@mail mos]# cd /mnt/
[root@mail mnt]# createrepo .
[root@mail mnt]# cat /etc/yum.repos.d/EMOS-Base.repo
[EMOS]
name=EMOS
baseurl=file:///mnt/
enabled=1
gpgcheck=0
[root@mail mnt]# yum clean all && yum clean metadata && yum clean dbcache && yum makecache && yum list
安装postfix
[root@mail mnt]# yum install postfix -y
[root@mail mnt]# postconf -n > /etc/postfix/main2.cf
[root@mail mnt]# mv /etc/postfix/main.cf /etc/postfix/main.cf.old
[root@mail mnt]# mv /etc/postfix/main2.cf /etc/postfix/main.cf
[root@mail mnt]# tail -16 /etc/postfix/main.cf
# hostname
mynetworks = 127.0.0.1
myhostname = mail.extmail.org
mydestination = $mynetworks $myhostname
# banner
mail_name = Postfix - by extmail.org
smtpd_banner = $myhostname ESMTP $mail_name
# response immediately
smtpd_error_sleep_time = 0s
# Message and return code control
message_size_limit = 5242880
mailbox_size_limit = 5242880
show_user_unknown_table_name = no
# Queue lifetime control
bounce_queue_lifetime = 1d
maximal_queue_lifetime = 1d
[root@mail mnt]# /etc/init.d/postfix start
Starting postfix: [ OK ]
[root@mail mnt]# netstat -tunlp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2931/master
安装Courier-Authlib
[root@mail mnt]# yum install courier-authlib -y
[root@mail mnt]# yum install courier-authlib-mysql -y
[root@mail mnt]# cp /etc/authlib/authmysqlrc /etc/authlib/authmysqlrc.$(date +%F%N)
[root@mail mnt]# >/etc/authlib/authmysqlrc
[root@mail mnt]# cat /etc/authlib/authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_PORT 3306
MYSQL_OPT 0
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD uidnumber
MYSQL_GID_FIELD gidnumber
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD homedir
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD quota
MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,
CONCAT('/home/domains/',homedir),
CONCAT('/home/domains/',maildir),
quota,
name
FROM mailbox
WHERE username = '$(local_part)@$(domain)'
[root@mail mnt]# sed -i 's#authmodulelist="authuserdb authpam authpgsql authldap authmysql authcustom authpipe"#authmodulelist="authmysql"#g' /etc/authlib/authdaemonrc
[root@mail mnt]# sed -i 's#authmodulelistorig="authuserdb authpam authpgsql authldap authmysql authcustom authpipe"#authmodulelistorig="authmysql"#g' /etc/authlib/authdaemonrc
[root@mail mnt]# service courier-authlib start
Starting Courier authentication services: authdaemond #启动成功
[root@mail mnt]# chmod 755 /var/spool/authdaemon/
安装maildrop
[root@mail mnt]# yum install maildrop -y
[root@mail mnt]# tail -2 /etc/postfix/master.cf
maildrop unix - n n - - pipe
flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}
[root@mail mnt]# tail -1 /etc/postfix/main.cf
maildrop_destination_recipient_limit = 1 #由于maildrop不支持一次接收多个收件人,因此必须在main.cf里增加此参数
虚拟主机设置
[root@mail mnt]# yum install httpd -y
[root@mail mnt]# mkdir /etc/httpd/conf/extra
[root@mail mnt]# echo "Include conf/extra/*.conf" >>/etc/httpd/conf/httpd.conf
[root@mail mnt]# cat /etc/httpd/conf/extra/vhost_extmail.conf
# VirtualHost for ExtMail Solution
ServerName mail.selmy.org
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/
Alias /extmail /var/www/extsuite/extmail/html/
ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman /var/www/extsuite/extman/html/
# Suexec config
SuexecUserGroup vuser vgroup
安装ExtMail
[root@mail mnt]# yum install extsuite-webmail -y
[root@Mail mnt]# cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf
[root@mail extmail]# sed -i 's#SYS_MYSQL_USER = db_user#SYS_MYSQL_USER = extmail#g' /var/www/extsuite/extmail/webmail.cf
[root@mail extmail]# sed -i 's#SYS_MYSQL_PASS = db_pass#SYS_MYSQL_PASS = extmail#g' /var/www/extsuite/extmail/webmail.cf
[root@mail extmail]# chown -R vuser:vgroup /var/www/extsuite/extmail/cgi/
yum安装ExtMan
[root@mail extmail]# yum install extsuite-webman -y
[root@mail extmail]# chown -R vuser:vgroup /var/www/extsuite/extman/cgi/
[root@mail extmail]# mkdir /tmp/extman
[root@mail extmail]# chown -R vuser:vgroup /tmp/extman
[root@mail extmail]# yum install mysql-server -y
[root@mail extmail]# /etc/init.d/mysqld start
[root@mail extmail]# mysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql
[root@mail extmail]# mysql -u root -p < /var/www/extsuite/extman/docs/init.sql
####
sed -i 's/TYPE=MyISAM/ENGINE=MyISAM/g' /usr/local/www/extman/docs/extmail.sql #MYSQL5.5.x 版本不支持 TYPE=MyISAM 这样的语句,请执行以下脚本后,再导入数据库。
####
[root@mail extmail]# cd /var/www/extsuite/extman/docs
[root@mail docs]# cp mysql_virtual_alias_maps.cf /etc/postfix/
[root@mail docs]# cp mysql_virtual_domains_maps.cf /etc/postfix/
[root@mail docs]# cp mysql_virtual_mailbox_maps.cf /etc/postfix/
[root@mail docs]# cp mysql_virtual_sender_maps.cf /etc/postfix/
[root@mail docs]# tail -5 /etc/postfix/main.cf
# extmail config here
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_transport = maildrop:
[root@mail docs]# /etc/init.d/postfix restart
[root@mail docs]# cd /var/www/extsuite/extman/tools
[root@mail tools]# ./maildirmake.pl /home/domains/extmail.org/postmaster/Maildir
[root@mail tools]# chown -R vuser:vgroup /home/domains/extmail.org
[root@mail tools]# /usr/sbin/authtest -s login [email protected] extmail
Authentication succeeded.
Authenticated: [email protected] (uid 1000, gid 1000)
Home Directory: /home/domains/extmail.org/postmaster
Maildir: /home/domains/extmail.org/postmaster/Maildir/
Quota: 104857600S
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options: (none)
[root@mail tools]# /usr/local/mailgraph_ext/mailgraph-init start
Starting mail statistics grapher: mailgraph_ext
Starting queue statistics grapher: qmonitor
[root@mail tools]# /var/www/extsuite/extman/daemon/cmdserver --daemon
loaded ok
[root@mail tools]# echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.d/rc.local
[root@mail tools]# echo "/var/www/extsuite/extman/daemon/cmdserver -v -d" >> /etc/rc.d/rc.local
[root@mail tools]# echo '0 4 * * * /var/www/extsuite/extman/tools/expireusers.pl -all [email protected]' >>/var/spool/cron/root
[root@mail tools]# echo '30 4 * * * /var/www/extsuite/extman/tools/reportusage.pl -all /home/domains [email protected]' >>/var/spool/cron/root
###
ExtMan的默认超级管理员帐户:[email protected],初始密码:extmail*123*
###
安装cyrus-sasl
[root@mail tools]# rpm -e cyrus-sasl --nodeps
[root@mail tools]# yum install cyrus-sasl -y
[root@mail tools]# tail -24 /etc/postfix/main.cf
# smtpd related config
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname,
# SMTP sender login matching config
smtpd_sender_restrictions =
permit_mynetworks,
reject_sender_login_mismatch,
reject_authenticated_sender_login_mismatch,
reject_unauthenticated_sender_login_mismatch
smtpd_sender_login_maps =
mysql:/etc/postfix/mysql_virtual_sender_maps.cf,
mysql:/etc/postfix/mysql_virtual_alias_maps.cf
# SMTP AUTH config here
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
[root@mail tools]# cat /usr/lib64/sasl2/smtpd.conf
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/var/spool/authdaemon/socket
[root@mail tools]# perl -e 'use MIME::Base64; print encode_base64("[email protected]")'
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
[root@mail tools]# perl -e 'use MIME::Base64; print encode_base64("extmail")'
ZXh0bWFpbA==
[root@mail tools]# yum install telnet -y
[root@mail tools]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.extmail.org ESMTP Postfix - by extmail.org
ehlo demo.domain.tld << 输入内容
250-mail.extmail.org
250-PIPELINING
250-SIZE 5242880
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login << 输入内容
334 VXNlcm5hbWU6
cG9zdG1hc3RlckBleHRtYWlsLm9yZw== << 输入内容
334 UGFzc3dvcmQ6
ZXh0bWFpbA== << 输入内容
235 2.7.0 Authentication successful
quit << 输入内容
221 2.0.0 Bye
Connection closed by foreign host.
安装Courier-imap
[root@mail tools]# yum install courier-imap -y
[root@mail tools]# sed -i 's#IMAPDSTART=YES#IMAPDSTART=NO#g' /usr/lib/courier-imap/etc/imapd
[root@mail tools]# sed -i 's#IMAPDSSLSTART=YES#IMAPDSSLSTART=NO#g' /usr/lib/courier-imap/etc/imapd-ssl
[root@mail tools]# service courier-imap start
Starting Courier-IMAP server: pop3 generating-SSL-certificate... pop3-ssl
[root@mail tools]# telnet localhost 110
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Hello there.
user [email protected] << 输入内容
+OK Password required.
pass ADMIN << 输入内容
+OK logged in.
list << 输入内容
+OK POP3 clients that break here, they violate STD53.
.
quit << 输入内容
+OK Bye-bye.
Connection closed by foreign host.
发信日志:
[root@mail /]# tail -f /var/log/maillog
Dec 7 12:17:34 mail extmail[13439]: user=
Dec 7 12:17:40 mail extmail[13442]: user=
Dec 7 12:18:22 mail postfix/smtpd[13450]: connect from localhost[127.0.0.1]
Dec 7 12:18:22 mail postfix/smtpd[13450]: 76BBB4066: client=localhost[127.0.0.1]
Dec 7 12:18:22 mail postfix/cleanup[13456]: 76BBB4066: message-id=<[email protected]>
Dec 7 12:18:22 mail postfix/qmgr[11692]: 76BBB4066: from=
Dec 7 12:18:22 mail postfix/smtpd[13450]: disconnect from localhost[127.0.0.1]
Dec 7 12:18:25 mail postfix/smtp[13458]: 76AAA4066: to=
Dec 7 12:18:25 mail postfix/qmgr[11692]: 76AAA4066: removed
收信日志:
Dec 7 12:20:36 mail postfix/smtpd[13460]: connect from smtpbg343.qq.com[14.17.44.38]
Dec 7 12:20:37 mail postfix/smtpd[13460]: 3490A4066: client=smtpbg343.qq.com[14.17.44.38]
Dec 7 12:20:37 mail postfix/cleanup[13469]: 3490A4066: message-id=
Dec 7 12:20:37 mail postfix/qmgr[11692]: 3490A4066: from=
Dec 7 12:20:37 mail postfix/pipe[13471]: 3490A4066: to=
Dec 7 12:20:37 mail postfix/qmgr[11692]: 3490C4066: removed
Dec 7 12:20:37 mail postfix/smtpd[13460]: disconnect from smtpbg343.qq.com[14.17.44.38]
Dec 7 12:23:57 mail postfix/anvil[13462]: statistics: max connection rate 1/60s for (smtp:14.17.44.38) at Dec 7 12:20:36
Dec 7 12:23:57 mail postfix/anvil[13462]: statistics: max connection count 1 for (smtp:14.17.44.38) at Dec 7 12:20:36
Dec 7 12:23:57 mail postfix/anvil[13462]: statistics: max cache size 1 at Dec 7 12:20:36
到此,mail服务基本配置完成,域名设置mx即可。
由于这台服务器在在日本(linode主机),只设置同一个IP地址。
备注:
1:EMOS1.5下载(适用于centos5.X系列):http://mirror.extmail.org/iso/emos/EMOS_1.5_x86_64.iso
2:EMOS1.6下载(适用于centos6.X系列):http://mirror.extmail.org/iso/emos/EMOS_1.6_x86_64.iso