我所写的postfix搭建是一气呵成的,前面发布的是基本搭建的内容,后续都是以前面为基础的发表,实验环境还是redhat 5.4服务器版,其实这就是为安装Extmail做准备
---------------------
建立虚拟用户数据库
[root@mail mail]# service mysqld restart
Shutting down MySQL. [确定]
Starting MySQL [确定]
[root@mail mail]#
[root@mail mail]# tar xzvf extman-0.2.5.tar.gz
[root@mail mail]# cd extman-0.2.5/docs/
[root@mail docs]#
[root@mail docs]# mysql -u root -p < extmail.sql
Enter password:
[root@mail docs]# mysql -u root -p < init.sql
Enter password:
---------------------
修改 Postfix的配置
[root@mail docs]# vim /etc/postfix/main.cf
#mydestination = $mydomain, $myhostname //这一行注释掉
......
virtual_mailbox_base = /mailbox
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
[root@mail docs]# cp mysql_virtual_* /etc/postfix/
[root@mail docs]# postfix reload // 重新加载配置
----------------------
为虚拟用户设置 SMTP 发信认证
[root@mail mail]# tar jxvf courier-authlib-0.60.2.tar.bz2
[root@mail mail]#
[root@mail mail]# cd courier-authlib-0.60.2
[root@mail courier-authlib-0.60.2]#
[root@mail courier-authlib-0.60.2]# vim courier-authlib.sh
./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir \
--with-authmysql --with-redhat --with-mysql-libs=/usr/local/mysql/lib/mysql \
--with-mysql-includes=/usr/local/mysql/include/mysql
[root@mail courier-authlib-0.60.2]# chmod a+x courier-authlib.sh
[root@mail courier-authlib-0.60.2]#
[root@mail courier-authlib-0.60.2]# ./courier-authlib.sh
[root@mail courier-authlib-0.60.2]# make
[root@mail courier-authlib-0.60.2]# make install
[root@mail courier-authlib-0.60.2]# make install-configure //生成默认配置文件
[root@mail courier-authlib-0.60.2]# vim /etc/ld.so.conf //末尾添加如下行内容
......
/usr/local/courier-authlib/lib/courier-authlib
[root@mail courier-authlib-0.60.2]# ldconfig
[root@mail courier-authlib-0.60.2]# cd /usr/local/courier-authlib/etc/authlib/
[root@mail authlib]# vim authdaemonrc //修改27行和34行,保留authmysql认证方式
27 authmodulelist="authmysql"
......
34 authmodulelistorig="authmysql"
[root@mail authlib]# chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/
[root@mail authlib]# cp authmysqlrc authmysqlrc.bak
[root@mail authlib]# vim authmysqlrc
// 修改下列行,描述如何向MySQL查询数据
26 MYSQL_SERVER localhost
27 MYSQL_USERNAME extmail
28 MYSQL_PASSWORD extmail
49 MYSQL_SOCKET /tmp/mysql.sock
68 MYSQL_DATABASE extmail
83 MYSQL_USER_TABLE mailbox
92 MYSQL_CRYPT_PWFIELD password
113 MYSQL_UID_FIELD uidnumber
119 MYSQL_GID_FIELD gidnumber
128 MYSQL_LOGIN_FIELD username
133 MYSQL_HOME_FIELD concat('/mailbox/',homedir)
139 MYSQL_NAME_FIELD name
150 MYSQL_MAILDIR_FIELD concat('/mailbox/',maildir)
-------------------
复制启动脚本,启动courier-authlib服务,这个脚本在源码包的目录里
[root@mail authlib]# cd /home/tom/LNS-SG7/courier-authlib-0.60.2
[root@mail courier-authlib-0.60.2]# pwd
/home/tom/mail/courier-authlib-0.60.2
[root@mail courier-authlib-0.60.2]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail courier-authlib-0.60.2]# chmod 755 /etc/init.d/courier-authlib
[root@mail courier-authlib-0.60.2]# chkconfig courier-authlib on
[root@mail courier-authlib-0.60.2]# service courier-authlib start
Starting Courier authentication services: authdaemond
-----------------
修改Cyrus sasl设置
[root@mail courier-authlib-0.60.2]# vim /usr/lib/sasl2/smtpd.conf
#pwcheck_method:saslauthd
pwcheck_method: authdaemond
authdaemond_path: /usr/local/courier-authlib/var/spool/authdaemon/socket
-----------------
修改 Dovecot 的配置
修改邮件存储位置,设置启用数据库查询功能
[root@mail ~]# vim /etc/dovecot.conf
218 mail_location = maildir:/mailbox/%d/%n/Maildir
.....
794 auth default {
799 mechanisms = plain
903 passdb sql {
904 # Path for SQL configuration file, see doc/dovecot-sql-example.conf
905 args = /etc/dovecot-mysql.conf
906 }
966 userdb sql {
967 # Path for SQL configuration file, see doc/dovecot-sql-example.conf
968 args = /etc/dovecot-mysql.conf
969 }
.....
}
--------------------
建立数据库查询配置文件
[root@mail ~]# vim /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
--------------------
建立虚拟用户
[email protected]的邮箱目录,调整权限
username = '%u'
[root@mail ~]# mkdir -p /mailbox/extmail.org/postmaster/Maildir/
[root@mail ~]# chown -R postfix:postfix /mailbox
--------------------
重启Dovecot服务
[root@mail ~]# killall -9 dovecot
[root@mail ~]# dovecot
[root@mail ~]# netstat -nlpt |grep dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 27034/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 27034/dovecot
[root@mail ~]#
--------------------
测试虚拟用户实现结果
测试Postfix 支持虚拟用户
[root@mail ~]# /usr/local/courier-authlib/sbin/authtest -s login
[email protected] extmail
Authentication succeeded. // 表示成功
Authenticated:
[email protected] (uid 1000, gid 1000)
Home Directory: /mailbox/extmail.org/postmaster
Maildir: /mailbox/extmail.org/postmaster/Maildir/
Quota: (none)
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options: (none)
--------------------
测试虚拟用户SMPT发信认证
[root@mail ~]# printf "
[email protected]" | openssl base64
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
[root@mail ~]# printf "extmail" | openssl base64
ZXh0bWFpbA==
[root@mail ~]#
[root@mail ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.benet.com ESMTP Postfix
auth login
334 VXNlcm5hbWU6
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
334 UGFzc3dvcmQ6
ZXh0bWFpbA==
235 2.0.0 Authentication successful // 表示成功
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@mail ~]#