變通實現dovecot + postfix + postfixadmin + mysql 虛擬用戶認證伺服器
dovecot + postfix + postfixadmin 建立mail伺服器中的幾個事項
我是新手!
第一次建立自己單位的mail伺服器。根據網上的資料都無法通過md5加密口令的smtp認證。自己改動了幾個地方,終於實現了。
從網上得到了很多資料,這次回報一下,有什麼不對的地方,請大家指出。
首先你可以網上搜一下完整的PHP APACHE MYSQL DOVECOT POSTFIX的安裝事項,再看看這篇能不能解決你遇到的問題。
伺服器版本:CentOS 4.5 X86_64
其它的相關軟體都是最新版本
1.安裝PHP的時候,在configure的時候,加上 --with-mycrypt --with-hash ,網上有安裝的方法;
2.安裝好mysql , 我的mysql裝在 /db/mysql
3.創建相應的用戶和工作組
#groupadd -g 2002 postfix
#groupadd -g 2003 postdrop
#useradd -u 2002 -g 2002 -G postdrop -d /dev/null -s /sbin/nologin postfix
#useradd -d /dev/null -s /sbin/nologin dovecot
4.安裝dovecot
#./configure --prefix=/usr/local/dovecot --sysconfdir=/etc/dovecot --with-sql --with-sql-drivers --with-mysql
#make && make install
配置dovecot.conf
#cd /etc/dovecot
#cp dovecot-example.conf dovecot.conf
#vi dovecot.conf
base_dir=/var/run/dovecot
protocols=imap imaps pop3 pop3s
listen=*
disable_plaintext_auth = no
ssl_disable = yes
mail_location = maildir:/mail/%d/%n //伺服器郵箱的統一位置,maildir格式,如/mail/xyz.com/username
pop3_uidl_format=%08Xu%08Xv
auth default {
...
mechanisms = PLAIN LOGIN CRAM-MD5 DIGEST-MD5
passdb sql { //去掉註釋
args = /etc/dovecot/dovecot-sql.conf
}
...
userdb sql {//去掉註釋
args = /etc/dovecot/dovecot-sql.conf
}
...
socket listen {
...
client {
path = /var/run/dovecot/auth-client //postfix依靠dovecot 實現 SMTP AUTH 時要用,在postfix中的main.cf配置文件中的smtpd_sasl_path=要引用這項
mode = 0660
user = postfix
group = postfix
}
}
}
配置dovecot-sql.conf
#cp dovecot-sql-example.conf dovecot-sql.conf
#vi dovecot-sql.conf
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfixPnp1993
default_pass_scheme=MD5 //改成PLAIN-MD5 后就不會與postfixadmin生成的密碼兼容,除非使用下面介紹的修改postfixadmin,
//dovecot的加密方式見 http://wiki.dovecot.org/Authentication/PasswordSchemes
//關鍵的地方的,搞了好一陣子。初始是,郵件地址:username@xyz.com pop3賬號username,會出現密碼不正確,除非pop3賬號也填username@xyz.com,否則登陸不上。其實就是PASSWORD_QUERY的代碼,改后就可以了,怪的是用where username='%u' 也不可以!!只能substring一下了
password_query = select username as user,password from mailbox where substring(username,1,instr(username,'@')-1) = '%n' And active='1'
user_query = select maildir as home,2002 as uid ,2002 as gid from mailbox where username='%u' And active='1'
創建符號鏈接
#ln -s /usr/local/dovecot/sbin/dovecot /usr/bin/dovecot
5.安裝postfixadmin 以及裡面的DATABASE_MYSQL.TXT同,網上有很多
6.安裝postfix
解壓postfix的郵箱限額補丁,如網上介紹
#gzip -d postfix-2.4.1-vda-ng.patch.gz
#cp postfix-2.4.1-vda-ng.patch postfix-2.4.1
#cd postfix-2.4.1
#patch -p1 < postfix-2.4.1-vda-ng.patch
#如下編譯
#看這裡Postfix SASL Howto http://www.postfix.org/SASL_README.html
#make -f Makefile.init makefiles \
'CCARGS=-DHAS_MYSQL -I/db/mysql/include/mysql \
-DUSE_TLS -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\"dovecot\"' \
'AUXLIBS=-L/db/mysql/lib/mysql -lmysqlclient -lz -lm'
#make
#make install //一切按照預設的就行了,可以把tmp設置成/tmp/postfix
#mv /etc/aliases /etc/aliases.old
#ln -s /etc/postfix/aliases /etc/aliases
#/usr/bin/newaliases
#vi /etc/postfix/main.cf
myhostname = mail.xyz.com ##不能與mysql里的domain重名
mydomain = xyz.com
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain #一定不要出現與MYSQL->postfix->domain表中重名的 如:$mydomain,所以我就選這行
mynetworks = 127.0.0.0/8
inet_interfaces = all
home_mailbox=Maildir/
#=====================Vritual Mailbox settings=========================
virtual_mailbox_base = /mail/
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:2002
virtual_gid_maps = static:2002
virtual_transport = virtual
#====================QUOTA========================
message_size_limit = 52428800 //每個郵件最大尺寸50M
mailbox_size_limit = 209715200 //郵箱大小限制200M
virtual_mailbox_limit = 209715200
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_overquota_bounce = yes
#====================SASL ESMTP Authenticat=================
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot //用dovecot進行認證
smtpd_sasl_path = /var/run/dovecot/auth-client //與dovecot.conf中如下的的path一致,前面講過
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks, //注意,後面到smtpd_sals_local_domain的每一行前面都有一個空格
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_local_domain =
smtpd_sasl_security_options = noanonymous
smtpd_banner=$myhostname ESMTP
查看master.cf文件必須包含下面一行
virtual unix - n n - - virtual
編輯/etc/postfix/mysql_virtual_alias_maps.cf 為以下內容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
編輯/etc/postfix/mysql_virtual_domains_maps.cf 為以下內容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
編輯/etc/postfix/mysql_virtual_mailbox_limit_maps.cf 為以下內容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
編輯/etc/postfix/mysql_virtual_mailbox_maps.cf 為以下內容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
如果你在dovecot-sql.conf中用的是default_pass_scheme=PLAIN-MD5,就要修改postfixadmin中的functions.inc.php的函數pacrypt
function pacrypt($pw,$pw_db){
//加入普通的md5加密
if ($CONF['encrypt']=='md5'){
$password=md5($pw);
}
}
//同時也要改其它相關webmail操作中的有關加密password一項
修改config.inc.php
$CONF['encrypt']='md5';
如果你在dovecot-sql.conf中用的是default_pass_scheme=MD5 ,就不需要修改任何地方
好了,使用postfixadmin創建域和帳號
域:xyz.com
用戶:test
啟動
echo "" > /var/log/maillog
dovecot
postfix start
vi /var/log/maillog
看有沒有錯誤
在客戶端用outlook,foxmail,選中發信時伺服器需要驗證 SMTP AUTH, 測試一下。
這裡只是介紹一下自己在安裝dovecot+postfix實現smtp auth時的解決辦法,其它的問題就google一下!
[ 本帖最後由 yn5411 於 2007-6-23 13:28 編輯 ]
《解決方案》
不錯~~~~~~~~~~~~
《解決方案》
好東西
《解決方案》
myhostname = mail.xyz.com ##不能與mysql里的domain重名
mydomain = xyz.com
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain #一定不要出現與MYSQL->postfix->domain表中重名的 如:$mydomain,所以我就選這行
----------------------
virtual_mailbox_base = /var/mailbox/
為什麼我用postfixadmin建xyz.com域和test@xyz.com 不能在/var/mailbox/下建相關郵箱目錄??
請問,要是只想用xyz.com真實域名做為域名,test@xyz.com 如何做?只用postfixadmin建個虛擬郵箱就成嗎??
《解決方案》
//關鍵的地方的,搞了好一陣子。初始是,郵件地址:username@xyz.com pop3賬號username,會出現密碼不正確,除非pop3賬號也填username@xyz.com,否則登陸不上。其實就是PASSWORD_QUERY的代碼,改后就可以了,怪的是用where username='%u' 也不可以!!只能substring一下了
password_query = select username as user,password from mailbox where substring(username,1,instr(username,'@')-1) = '%n' And active='1'
user_query = select maildir as home,2002 as uid ,2002 as gid from mailbox where username='%u' And active='1'
樓主,下面這個語句還的要斟酌下
password_query = select username as user,password from mailbox where substring(username,1,instr(username,'@')-1) = '%n' And active='1'
如果你這樣些的話,對下面兩中情況沒影響
1)單域
2)多域不同名用戶
如果是多域中有相同用戶呢?
如何處理?
《解決方案》
回復 #1 yn5411 的帖子
socket listen {
...
client {
path = /var/run/dovecot/auth-client //postfix依靠dovecot 實現 SMTP AUTH 時要用,在postfix中的main.cf配置文件中的smtpd_sasl_path=要引用這項
mode = 0660
user = postfix
group = postfix
}
}
}
按照LZ說的使用devoct認證,設置后,
telnet locahost 110 陷入忙等,無法正常進入收郵件
這是什麼原因呢?
《解決方案》
回復 #1 yn5411 的帖子
隨便問一下,對虛擬用戶sasl認證是不是也要為它們創建密碼文件?(dovecot默認為系統用戶)
不知道LZ是怎麼實現的?
可否把您的sasl相關配置文件貼出來,參考一下。
《解決方案》
make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql5/include/ -DUSE_TLS -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE=\"dovecot\"' 'AUXLIBS=-L/usr/local/mysql5/lib/ -lmysqlclient -lz -lm'
make
出現的問題
/root/lcc/postfix-2.3.12/src/tls/tls_verify.c:161: undefined reference to `X509_NAME_oneline'
../../lib/libtls.a(tls_certkey.o): In function `set_cert_stuff':
/root/lcc/postfix-2.3.12/src/tls/tls_certkey.c:111: undefined reference to `SSL_CTX_use_certificate_chain_file'
/root/lcc/postfix-2.3.12/src/tls/tls_certkey.c:116: undefined reference to `SSL_CTX_use_PrivateKey_file'
/root/lcc/postfix-2.3.12/src/tls/tls_certkey.c:125: undefined reference to `SSL_CTX_check_private_key'
../../lib/libtls.a(tls_certkey.o): In function `tls_set_ca_certificate_info':
/root/lcc/postfix-2.3.12/src/tls/tls_certkey.c:85: undefined reference to `SSL_CTX_load_verify_locations'
/root/lcc/postfix-2.3.12/src/tls/tls_certkey.c:90: undefined reference to `SSL_CTX_set_default_verify_paths'
collect2: ld returned 1 exit status
make: *** Error 1
make: *** Error 1
《解決方案》
已經解決 就是去掉 「-DUSE_TLS 」
就可以了