我们现在要安装一个postfix,要求其支持web mail,并安装web mail实现邮箱的注册、邮件的发送接收。

一、安装配置DNS

    参考:DNS的快速配置和安装

 

未完待续:

 

二、安装postfix前的准备工作

1.关闭sendmail

service sendmail stop 

chkconfig sendmail off

2.安装编译环境(工具)

安装以下开发所用到的rpm包组:

Development Libraries

Development Tools

Legacy Software Development

X Software Development

yum -y groupinstall "Development Libraries" "Development Tools" "Legacy Software  Development" "X Software Development"

3.安装所需的rpm

包括: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

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

4.启动mysql数据库

service mysqld start

chkconfig mysqld on

5.启动saslauthd服务

service saslauthd start

chkconfig saslauthd on

准备工作完成

三、安装配置postfix

1.下载并解压postfix (可以在官网www.postfix.org下载)

tar xf postfix-2.6.5.tar.gz 

2.添加用户和组

groupadd -g 2525 postfix

groupadd -g 2526 postdrop

useradd -g postfix -u 2525 -s /sbin/nologin -M postfix

useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop

2.编译安装

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

3.生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低:

Newaliases

4.编辑配置文件main.cf

cd /etc/postfix

cp main.cf main.cf.bak        备份main.cf

vim main.cf   

修改以下几项为您需要的配置

myhostname = mail.zsl.com

myorigin = zsl.com

mydomain = zsl.com

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

mynetworks = 192.168.19.0/24, 127.0.0.0/8

5.启动postfix

postfix start

6.拷贝一个已经写好的 postfix 到 /etc/init.d/postfix并启动postfix

chomd +x /etc/init.d/postfix

chkconfig --add postfix

chkconfig postfix on

OKPostfix安装完成了。

四、为postfix开启基于cyrus-sasl的认证功能

1.验证postfix是否支持cyrus风格的sasl认证,如果您的输出为以下结果,则是支持的:

/usr/local/postfix/sbin/postconf  -a

cyrus

dovecot

2.编辑配置文件main.cf

vim /etc/postfix/main.cf

添加以下内容:

############################CYRUS-SASL############################

broken_sasl_auth_clients = yes

smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_h ostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sende r,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reje ct_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!

3.编辑/usr/lib/sasl2/smtpd.conf

vim /usr/lib/sasl2/smtpd.conf

添加如下内容:

pwcheck_method: saslauthd

mech_list: PLAIN LOGIN

4.postfix重新加载配置文件

/usr/sbin/postfix/sbin/postfix reload

OK!现在postfix可以使用cyrus-sasl认证了。

五、安装Courier authentication library

1.下载并解压courier-authlib-0.62.4.tar.bz2

tar jxvf courier-authlib-0.62.4.tar.bz2

2.编译安装

cd 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

make

make install

3.修改文件权限

chmod 755 /usr/local/courier-authlib/var/spool/authdaemon

4.修改配置文件/etc/authdaemonrc cp/etc/authmysqlrc

cp /etc/authdaemonrc.dist  /etc/authdaemonrc

cp /etc/authmysqlrc.dist  /etc/authmysqlrc

修改/etc/authdaemonrc 文件

authmodulelist="authmysql"

authmodulelistorig="authmysql"

daemons=10

编辑/etc/authmysqlrc 为以下内容,其中25252525 postfix 用户的UIDGID

MYSQL_SERVER 

MYSQL_PORT 3306             (指定你的mysql监听的端口,这里使用默认的3306)

MYSQL_USERNAME  extmail   (这时为后文要用的数据库的所有者的用户名)

MYSQL_PASSWORD extmail     (密码)

MYSQL_SOCKET  /var/lib/mysql/mysql.sock

MYSQL_DATABASE  extmail

MYSQL_USER_TABLE  mailbox

MYSQL_CRYPT_PWFIELD  password

MYSQL_UID_FIELD  '2525'

MYSQL_GID_FIELD  '2525'

MYSQL_LOGIN_FIELD  username

MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)

MYSQL_NAME_FIELD  name

MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)

5.配置/etc/init.d中加入courier-authlib并开机启动

cp courier-authlib.sysvinit /etc/init.d/courier-authlib

chmod 755 /etc/init.d/courier-authlib

chkconfig --add courier-authlib

chkconfig courier-authlib on

6.编辑默认库文件路径,并重新引导

vim /etc/ld.so.conf.d/courier-authlib.conf

写入

/usr/local/courier-authlib/lib/courier-authlib

ldconfig -v

7.启动服务

service courier-authlib start

8.新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:

mkdir pv /var/mailbox

chown R postfix /var/mailbox

9.接下来重新配置SMTP 认证,编辑 /usr/lib/sasl2/smtpd.conf ,确保其为以下内容:

pwcheck_method: authdaemond

log_level: 3

mech_list:PLAIN LOGIN

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:2525

virtual_gid_maps = static:2525

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.sqlinit.sql建立数据库:

tar zxvf  extman-1.1.tar.gz

cd extman-1.1/docs

mysql -u root -p <extmail.sql

mysql -u root -p <init.sql

cp mysql*  /etc/postfix/

3.授予用户extmail访问extmail数据库的权限

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';

FLUSH PRIVILEGES;

说明:启用虚拟域以后,需要取消中心域,即注释掉myhostname, mydestination, mydomain, myorigin几个指令;当然,你也可以把mydestionation的值改为你自己需要的。

未完待续……

七、配置dovecot

1.编辑配置文件dovecot.conf

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

    }

2.编辑dovecot-mysql.conf

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 username = '%u'

3.启动dovecot服务:

service dovecot start

chkconfig dovecot on