Postfix+Courier-IMAP+Cyrus-SASL+PAM_MySQL+MySQL安装
2004-04-23 15:18 pm来自:Linux文档
现载:Www.8s8s.coM
地址:无名
基本思路:
courier-imap提供pop3服务,直接访问mysql
postfix的所有用户,别名和多域名支持均存储在mysql中
smtp auth使用了sasl,通过pam_mysql对mysql进行访问。
相关软件:
mysql-4.0.12.tar.gz
courier-imap-1.7.1.tar.bz2
cyrus-sasl-1.5.28.tar.gz
pam_mysql-0.5.tar.gz
postfix-2.0.6.tar.gz
安装MySQL,这个网上资料很多,如果有不清楚的,请去查文档。
#/usr/sbin/useradd mysql
#tar zvxf mysql-4.0.12.tar.gz
#cd mysql*
#./configure --prefix=/usr/local/mysql
#make
#make install
#scripts/mysql_install_db
#chown -R mysql.root /usr/local/mysql/var
#/usr/local/mysql/bin/mysqld_safe -u mysql &
#cd ..
好了,MySQL已经搞定了。
安装pam_mysql
#tar zvxf pam_mysql*gz
#cd pam_mysql*
将pam_mysql.c中第54行注释掉,/* #define DEBUG */
#make
#cp pam_mysql.so /lib/security
#cd ..
安装Cyrus-SASL
#tar zvxf cyrus-sasl*gz
#cd cyrus-sasl*
#./configure --disable-sample --disable-pwcheck --disable-cram --disable-digest --disable-krb4
--disable-gssapi --disable-anon --enable-plain --enable-login
#make
#make install
#ln -s /usr/local/lib/sasl /usr/lib/sasl
#echo /usr/local/lib >> /etc/ld.so.conf
#echo /usr/local/lib/sasl >> /etc/ld.so.conf
#echo /usr/local/mysql/lib/mysql >> /etc/ld.so.conf
#/sbin/ldconfig
#echo pwcheck_method: pam > /usr/lib/sasl/smtpd.conf
#cd ..
安装Postfix
如果系统上有sendmail,请先将其停止,并备份sendmail的二进制文件和配置文件。
#tar zvxf postfix*gz
#cd postfix*
#/usr/sbin/groupadd postfix
#/usr/sbin/groupadd postdrop
#/usr/sbin/useradd -g postfix -d /dev/null -s /bin/false postfix
#make -f Makefile.init makefiles 'CCARGS=-DUSE_SASL_AUTH -DHAS_MYSQL -I/usr/local/mysql/include/mysql -I/usr/local/include'
'AUXLIBS=-L/usr/local/mysql/lib/mysql -L/usr/local/lib/sasl -lmysqlclient -lsasl -lz -lm'
#make install
#cd ..
安装courier-imap
#tar jvxf courier-imap*bz2
#cd courier-imap*
#./configure --without-authpwd --without-authpam --without-authuserdb --without-authshadow
--without-cram --without-chkpw --without-ldap --without-pgsql --without-authdaemon
--without-authcustom --with-authmysql
#make
#make check
#make install
#make install-configure
#cd ..
创建数据库,表。表结构见下:
#/usr/local/mysql/bin/mysql
mysql>create database postfix;
mysql>exit;
#/usr/local/mysql/bin/mysql < /tmp/postfix.sql
#####cut from here#####(postfix.sql)
CREATE TABLE postfix_mailauth (
userid char(20) binary NOT NULL default '',
username char(60) NOT NULL default '',
domain char(50) NOT NULL default '',
uid smallint(5) unsigned NOT NULL default '12345',
gid smallint(5) unsigned NOT NULL default '12345',
clearpw char(20) binary NOT NULL default '',
home char(100) NOT NULL default '',
maildir char(150) NOT NULL default '',
quota char(100) NOT NULL default '',
last_access int(10) unsigned NOT NULL default '0',
status tinyint(3) unsigned NOT NULL default '1',
passwd_lastchanged int(10) unsigned NOT NULL default '0',
PRIMARY KEY (username),
KEY status (status)
) TYPE=MyISAM;
CREATE TABLE postfix_forward (
username varchar(50) NOT NULL default '',
domain varchar(40) NOT NULL default '',
forward_addr text NOT NULL,
PRIMARY KEY (username)
) TYPE=MyISAM;
CREATE TABLE postfix_transport (
domain varchar(50) NOT NULL default '',
transport varchar(8) NOT NULL default 'virtual:',
PRIMARY KEY (domain)
) TYPE=MyISAM;
#####cut end#####
其中的uid和gid的default值请设置为系统用户postfix的uid和gid
配置pam
在/etc/pam.d/下创建文件smtp,内容如下:
#####
auth sufficient pam_mysql.so user=your_userid passwd=your_password host=localhost db=postfix table=postfix_mailauth usercolumn=username passwdcolumn=clearpw crypt=0
account required pam_mysql.so user=your_userid passwd=your_password host=localhost db=postfix table=postfix_mailauth usercolumn=username passwdcolumn=clearpw crypt=0
auth sufficient pam_unix_auth.so
account sufficient pam_unix_acct.so
#####
编辑courier-imap配置文件/usr/lib/courier-imap/etc/authmysqlrc,设置访问mysql的一些参数,比较简单,参见注释就行。
编辑/etc/postfix/main.cf
一般的配置请参见文件内的注释,需要注意的是以下几处:
#####所有的帐号,别名均在数据库中
virtual_mailbox_domains = $mydomain, esphere.info, capitaltech.net, netruth.com, netruth.biz
transport_maps = mysql:/etc/postfix/transport.cf
virtual_mailbox_base = /
virtual_uid_maps = mysql:/etc/postfix/uid.cf
virtual_gid_maps = mysql:/etc/postfix/gid.cf
virtual_mailbox_maps = mysql:/etc/postfix/users.cf
virtual_maps = mysql:/etc/postfix/forward.cf
#####注意这里的最后的/不能丢
home_mailbox = Maildir/
#####SASL
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated permit_auth_destination reject
smtpd_sasl_security_options = noanonymous
smtpd_client_restrictions = permit_sasl_authenticated
broken_sasl_auth_clients = yes
#####uid.cf
user = your_userid
password = your_password
dbname = postfix
table = postfix_mailauth
select_field = uid
where_field = username
hosts = localhost
#####gid.cf
user = your_userid
password = your_password
dbname = postfix
table = postfix_mailauth
select_field = gid
where_field = username
hosts = localhost
#####transport.cf
user = your_userid
password = your_password
dbname = postfix
table = postfix_transport
select_field = transport
where_field = domain
hosts = localhost
#####forward.cf
user = your_userid
password = your_password
dbname = postfix
table = postfix_forward
select_field = forward_addr
where_field = username
hosts = localhost
#####users.cf
user = your_userid
password = your_password
dbname = postfix
table = postfix_mailauth
select_field = maildir
where_field = username
hosts = localhost
到此基本成功,剩下的写些php脚本,所有的事情(添加、删除、修改用户、别名、域名)都可以通过web来做。
注:上文中的your_userid和your_password是指访问mysql的用户名和密码。
#####boot pop3 service
/usr/lib/courier-imap/libexec/pop3d.rc start
#####boot postfix
/usr/sbin/postfix start