配置環境:RHEL5.5 i386
===DNS MX====
[root@station40 ~]# host -t MX tianyun.com
tianyun.com mail is handled by 10 mail.tianyun.com.
[root@station40 ~]#?
[root@station40 ~]# ping mail.tianyun.com
PING mail.tianyun.com (192.168.0.2) 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_seq=1 ttl=64 time=0.337 ms
64 bytes from 192.168.0.2: icmp_seq=2 ttl=64 time=0.387 ms
一、準備工作
1. IP,Iptables,SELinux,hosts
[root@station11 ~]# service iptables status
防火墻已停
[root@station11 ~]# getenforce?
Disabled
# vim /etc/hosts
127.0.0.1? ? ? ?localhost
192.168.2.115? ?station115.uplooking.com station115
2. #; yum -y groupinstall "Development Libraries" "Development Tools" "Legacy Software Development" "X Software Development"
3. 關閉sendmail,并將它的隨系統自動啟動功能關閉:
# service sendmail stop?
# chkconfig sendmail off
4.安裝所需的rpm包,這包括以下這些:?
# yum -y install httpd php php-mysql mysql mysql-server mysql-devel openssl-devel \
? dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect
5. 啟動mysql數據庫,并給mysql的root用戶設置密碼
# service mysqld start
# chkconfig mysqld on
# mysqladmin -uroot password '123456'
# mysql -uroot -p123456?
6.啟動saslauthd服務,并將其加入到自動啟動隊列
# service saslauthd start
# chkconfig saslauthd on
二、安裝postfix
1. postfix
# groupadd -g 1200 postdrop
# groupadd -g 1000 postfix?
# useradd -u 1000 -g postfix -G postdrop -M -s /sbin/nologin postfix
# tar xvf postfix-2.6.5.tar.gz
# cd postfix-2.6.5
# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS' \
? 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
# make
# make install
按照以下的提示輸入相關的路徑([]號中的是缺省值,”]”后的是輸入值,省略的表示采用默認值)
install_root: [/]?
tempdir: [/usr/local/src/ postfix-2.6.5] /tmp <===
config_directory: [/etc/postfix]
daemon_directory: [/usr/libexec/postfix]?
command_directory: [/usr/sbin]?
queue_directory: [/var/spool/postfix]
sendmail_path: [/usr/sbin/sendmail]
newaliases_path: [/usr/bin/newaliases]
mailq_path: [/usr/bin/mailq]
mail_owner: [postfix]
setgid_group: [postdrop]? ?
? ? html_directory: [no] /var/www/postfix_html <===
? ? manpages: [/usr/local/man]
? ? readme_directory: [no]
? ? BTW: Check your /etc/aliases file and be sure to set up aliases
? ? that send mail for root and postmaster to a real person, then run
? ? /usr/bin/newaliases.
生成別名二進制文件,這個步驟如果忽略,會造成postfix效率極低:
#? newaliases
2.進行一些基本配置,測試啟動postfix并進行發信
[root@server ~]# cp /etc/postfix/main.cf /etc/postfix/main.cf.bak
[root@server ~]# postconf -n > /etc/postfix/main.cf1
[root@server ~]# cp /etc/postfix/main.cf1 /etc/postfix/main.cf
#vi /etc/postfix/main.cf
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
html_directory = /var/www/postfix_html
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
修改以下幾項需要的配置
inet_interfaces = all //監聽在所有接口
myhostname = mail.tianyun.com //主機名(DNS)
mydomain = tianyun.com //域名
myorigin = $mydomain //偽裝
mydestination = $mydomain,$myhostname,localhost //定義郵件服務器收取郵件范圍
啟動postfix
[root@tianyun postfix-2.6.5]# /usr/sbin/postfix start
postfix/postfix-script: starting the Postfix mail system
[root@tianyun postfix-2.6.5]# echo "/usr/sbin/postfix start" >> /etc/rc.local
[root@station230 ~]# netstat -tnlp |grep :25
tcp? ? ? ? 0? ? ? 0 0.0.0.0:25? ? ? ? ? ? ? ? ? 0.0.0.0:*? ? ? LISTEN? ? ? 12127/master? ??
===================================可選操作部分=======================================
連接postfix,驗證服務啟動狀況:
[root@tianyun ~]# useradd alice
[root@tianyun ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
220 mail.tianyun.com ESMTP Postfix
ehlo mail.tianyun.com <===
250-mail.tianyun.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from: root@tianyun.com <===
250 2.1.0 Ok
rcpt to: alice@tianyun.com <===
250 2.1.5 Ok
data <===
354 End data with <CR><LF>.<CR><LF>
I love you!
. <===
250 2.0.0 Ok: queued as 01D418F633
quit <===
221 2.0.0 Bye
Connection closed by foreign host.
[root@tianyun ~]#
切換到alice用戶進行收信:
[root@tianyun ~]# su - alice
[alice@tianyun ~]$ mail
Mail version 8.1 6/6/93.? Type ? for help.
"/var/spool/mail/alice": 1 message 1 new
>N? 1 root@tianyun.com? ? ? Thu Sep 27 04:50? 14/488
& 1
Message 1:
From root@tianyun.com? Thu Sep 27 04:50:56 2012
X-Original-To: alice@tianyun.com
Delivered-To: alice@tianyun.com
Date: Thu, 27 Sep 2012 04:50:36 +0800 (CST)
From: root@tianyun.com
To: undisclosed-recipients:;
I love you!
&
====================================================================================
三、為postfix開啟基于cyrus-sasl的認證功能
使用以下命令驗正postfix是否支持cyrus風格的sasl認證,如果您的輸出為以下結果,則是支持的:?
[root@tianyun ~]# postconf -a
cyrus
dovecot
[root@tianyun ~]# vim /etc/postfix/main.cf
添加以下內容:
############################CYRUS-SASL############################
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
[root@tianyun ~]# vim /usr/lib/sasl2/smtpd.conf
添加如下內容:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
讓postfix重新加載配置文件
[root@tianyun ~]# postfix reload
===========================測試部分可選操作===========================================
[root@tianyun ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
220 Welcome to our mail.tianyun.com ESMTP,Warning: Version not Available!
ehlo mail.tianyun.com
250-mail.tianyun.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN //
250-AUTH=PLAIN LOGIN //表示已支持sasl認證
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
四、安裝Courier authentication library
[root@tianyun ~]# tar xvf courier-authlib-0.62.4.tar.bz2
[root@tianyun ~]# cd courier-authlib-0.62.4
[root@tianyun courier-authlib-0.62.4]# ./configure \
--prefix=/usr/local/courier-authlib \
--sysconfdir=/etc \
--with-authmysql \
--with-mysql-libs=/usr/lib/mysql \
--with-mysql-includes=/usr/include/mysql \
--with-redhat \
--with-authmysqlrc=/etc/authmysqlrc \
--with-authdaemonrc=/etc/authdaemonrc \
--with-ltdl-lib=/usr/lib \
--with-ltdl-include=/usr/include
[root@tianyun courier-authlib-0.62.4]# make
[root@tianyun courier-authlib-0.62.4]# make install
[root@tianyun courier-authlib-0.62.4]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
[root@tianyun ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@tianyun ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
修改/etc/authdaemonrc 文件
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
編輯/etc/authmysqlrc 為以下內容,其中1000,1000 為postfix 用戶的UID和GID。
MYSQL_SERVER localhost
MYSQL_USERNAME? extmail //連接數據庫使用的用戶名
MYSQL_PASSWORD extmail //連接數據庫使用的密碼
MYSQL_SOCKET? /var/lib/mysql/mysql.sock //去掉注釋并修改
MYSQL_PORT 3306
MYSQL_DATABASE? extmail
MYSQL_USER_TABLE? mailbox
MYSQL_CRYPT_PWFIELD? password
MYSQL_UID_FIELD? '1000'
MYSQL_GID_FIELD? '1000'
MYSQL_LOGIN_FIELD? username
MYSQL_HOME_FIELD? concat('/var/mailbox/',homedir)
MYSQL_NAME_FIELD? name
MYSQL_MAILDIR_FIELD? concat('/var/mailbox/',maildir) //去掉注釋并修改
[root@tianyun courier-authlib-0.62.4]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@tianyun courier-authlib-0.62.4]# chmod 755 /etc/init.d/courier-authlib
[root@tianyun courier-authlib-0.62.4]# chkconfig --add courier-authlib
[root@tianyun courier-authlib-0.62.4]# chkconfig courier-authlib on
[root@tianyun ~]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
[root@tianyun ~]# ldconfig -v
[root@tianyun ~]# /etc/init.d/courier-authlib start
Starting Courier authentication services: authdaemond? ? (啟動服務)
新建虛擬用戶郵箱所在的目錄,并將其權限賦予postfix用戶:
[root@tianyun ~]# mkdir -p /var/mailbox
[root@tianyun ~]# chown -R postfix /var/mailbox/
接下來重新配置SMTP 認證,編輯 /usr/lib/sasl2/smtpd.conf,確保其為以下內容:?
[root@tianyun ~]# vim /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
mech_list: PLAIN LOGIN?
log_level: 3?
authdaemond_path: /usr/local/courier-authlib/var/spool/authdaemon/socket
五、讓postfix支持虛擬域和虛擬用戶
1、編輯/etc/postfix/main.cf,添加如下內容:
########################Virtual Mailbox Settings########################
virtual_mailbox_base = /var/mailbox
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
##########################QUOTA Settings########################
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.
virtual_overquota_bounce = yes
2、使用extman源碼目錄下docs目錄中的extmail.sql和init.sql建立數據庫:
[root@tianyun ~]# tar xvf extman-1.1.tar.gz
[root@tianyun ~]# cd extman-1.1/docs/
[root@tianyun docs]# mysql -uroot -p123456 < extmail.sql
[root@tianyun docs]# mysql -uroot -p123456 < init.sql
[root@tianyun docs]# cp mysql* /etc/postfix/
3、授予用戶extmail訪問extmail數據庫的權限
[root@tianyun docs]# mysql -uroot -p123456
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO extmail@127.0.0.1 IDENTIFIED BY 'extmail';
注意:啟用虛擬域以后,需要取消默認域,即注釋掉myhostname, mydestination, mydomain, myorigin幾個指令;
[root@tianyun docs]# vim /etc/postfix/main.cf
#myhostname = mail.tianyun.com
#mydomain = tianyun.com
#myorigin = $mydomain
#mydestination = $mydomain,$myhostname,localhost
六、配置dovecot
[root@tianyun docs]# vim /etc/dovecot.conf
mail_location = maildir:/var/mailbox/%d/%n/Maildir
……
auth default {
? ? mechanisms = plain
? ? passdb sql {
? ? ? ? args = /etc/dovecot-mysql.conf
? ? }
? ? userdb sql {
? ? ? ? args = /etc/dovecot-mysql.conf
? ? }
? ? ……
[root@tianyun docs]# vi /etc/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail
default_pass_scheme = CRYPT
password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'? ? ? ? ? ? ? ? ? ? ? ? ? ??
user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'
啟動dovecot服務:
[root@tianyun docs]# service dovecot start
[root@tianyun docs]# chkconfig dovecot on
七、安裝Extmail-1.2
1、安裝
[root@tianyun ~]# tar xvf extmail-1.2.tar.gz
[root@tianyun ~]# mkdir -p /var/www/extsuite
[root@tianyun ~]# mv extmail-1.2 /var/www/extsuite/extmail
[root@tianyun ~]# cd /var/www/extsuite/extmail/
[root@tianyun extmail]# cp webmail.cf.default webmail.cf
2、修改主配置文件,部分修改選項的說明:
[root@tianyun ~]# vim /var/www/extsuite/extmail/webmail.cf
SYS_MESSAGE_SIZE_LIMIT = 5242880 用戶可以發送的最大郵件,默認為5M
SYS_USER_LANG = zh_CN 中文支持
SYS_MAILDIR_BASE = /var/mailbox 此處即在前面所設置的用戶郵件的存放目錄
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail 以上兩句句用來設置連接數據庫服務器所使用用戶名、密碼和郵件服務器用到的數據庫
SYS_MYSQL_HOST = localhost 指明數據庫服務器主機名,這里默認即可
SYS_MYSQL_TABLE = mailbox
SYS_MYSQL_ATTR_USERNAME = username
SYS_MYSQL_ATTR_DOMAIN = domain
SYS_MYSQL_ATTR_PASSWD = password 以上用來指定驗正用戶登錄里所用到的表,以及用戶名、域名和用戶密碼分別對應的表中列的名稱;這里默認即可?
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket 此句用來指明authdaemo socket文件的位置
3、apache相關配置
由于extmail要進行本地郵件的投遞操作,故必須將運行apache服務器用戶的身份修改為您的郵件投遞代理的用戶;
本例中打開了apache服務器的suexec功能,故使用以下方法來實現虛擬主機運行身份的指定。
此例中的MDA為postfix自帶,因此將指定為postfix用戶:
[root@tianyun ~]# vim /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
? ? ? ? ServerName mail.test.com
? ? ? ? DocumentRoot /var/www/extsuite/extmail/html/
? ? ? ? ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
? ? ? ? Alias /extmail /var/www/extsuite/extmail/html
? ? ? ? SuexecUserGroup postfix postfix
</VirtualHost>
修改 cgi執行文件屬主為apache運行身份用戶:
[root@tianyun ~]# chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
4、依賴關系的解決
extmail將會用到perl的Unix::syslogd功能
[root@tianyun ~]# tar xvf Unix-Syslog-0.100.tar.gz
[root@tianyun ~]# cd Unix-Syslog-0.100
[root@tianyun Unix-Syslog-0.100]# perl Makefile.PL
[root@tianyun Unix-Syslog-0.100]# make
[root@tianyun Unix-Syslog-0.100]# make install
5、啟動apache服務
[root@tianyun ~]# service httpd start
[root@tianyun ~]# chkconfig httpd on
八、安裝Extman-1.1
1、安裝及基本配置
[root@tianyun ~]# tar xvf extman-1.1.tar.gz
[root@tianyun ~]# mv extman-1.1 /var/www/extsuite/extman
[root@tianyun ~]# cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf
[root@tianyun ~]# vim /var/www/extsuite/extman/webman.cf
SYS_MAILDIR_BASE = /var/mailbox
SYS_CAPTCHA_ON = 0 //驗證碼是否開啟
修改cgi目錄的屬主:
[root@tianyun ~]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
在apache的主配置文件中Extmail的虛擬主機部分,添加如下兩行:
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/html
創建其運行時所需的臨時目錄,并修改其相應的權限:
[root@tianyun ~]# mkdir -p /tmp/extman
[root@tianyun ~]# chown postfix.postfix /tmp/extman/
重新啟動apache,配置基本結構,可從瀏覽器中訪問Webmail和Extman
[root@tianyun ~]# service httpd restart
http://mail.tianyun.com
extman默認管理帳號為:root@extmail.org? 密碼為:extmail*123*
郵件服務器登陸extman 后臺時顯示 系統信息 錯誤 no such file or directory
[root@tianyun ~]# /var/www/extsuite/extman/daemon/cmdserver -v -d
loaded ok
[root@server ~]# echo "/var/www/extsuite/extman/daemon/cmdserver -v -d" >> /etc/rc.local
創建域uplooking.com, 注冊2個賬號 相互發封郵件試試,可以收到那就祝賀了。。配置成功
[root@server ~]# tail -f /var/log/maillog
登陸mysql看一下相關的數據庫信息,有數據,則表明整個認證機制是基于mysql數據庫實現的。
===========================================================================================================
錯誤1:郵件目錄沒有權限
[root@station11 ~]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
user jack@tianyun.com
+OK
pass 123?
+OK Logged in.
-ERR Internal error occurred. Refer to server log for more information. [2012-10-11 16:05:59]
Connection closed by foreign host.
[root@station40 ~]# printf "jack@tianyun.com" |openssl base64
amFja0B0aWFueXVuLmNvbQ==
[root@station40 ~]#?
[root@station40 ~]# printf "123" |openssl base64
MTIz
[root@station11 ~]# telnet 192.168.0.2 25
Trying 192.168.0.2...
Connected to 192.168.0.2 (192.168.0.2).
Escape character is '^]'.
220 Welcome to our station11.uplooking.com ESMTP,Warning: Version not Available!
ehlo nihao
250-station11.uplooking.com
250-PIPELINING
250-SIZE 14336000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
amFja0B0aWFueXVuLmNvbQ==
334 UGFzc3dvcmQ6
MTIz
mail from: alice@tianyun.com //發件人
rcpt to: jack@tianyun.com //收件人
data
輸入正文
.
quit
[root@station11 ~]# telnet 192.168.0.2 110 收信
Trying 192.168.0.2...
Connected to 192.168.0.2 (192.168.0.2).
Escape character is '^]'.
+OK Dovecot ready.
user jack@tianyun.com
+OK
pass 123
+OK Logged in.
list //列出郵件
+OK 1 messages:
1 1542
.
retr 1 //讀第一封郵件
dele 1 //刪除第一封郵件
MUA: outlook,foxmail
用戶名必須是全名 jack@tianyun.com
支持SASL認證:? 我的服務器需要身份驗證
Can't chdir to /var/mailbox/bingo.com/111/Maildir/, No such file or directory
轉載于:https://blog.51cto.com/13763261/2170519