RedHat 5.4下构建postfix全功能电子邮(六)-postfix详细配置

RedHat 5.4下构建postfix全功能电子邮(六)-postfix详细配置

一、配置 Postfix

查看模块,#postconf -m |grep mysql 返回值有mysql,说明可以支持mysql 数据库的查询表

[root@mail docs]# cd

[root@mail ~]# postconf -m |grep mysql

mysql

1、修改配置文件

[root@mail ~]# vim /etc/postfix/main.cf

162-163行需要注释掉

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

163 # mail.$mydomain, www.$mydomain, ftp.$mydomain

652 virtual_mailbox_base = /mailbox

653 virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf

654 virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

655 virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

656 virtual_uid_maps = static:1000

657 virtual_gid_maps = static:1000

658 virtual_transport = virtual

[root@mail ~]# cd /usr/local/src/extman-1.1/docs/

[root@mail docs]# cp mysql_virtual_* /etc/postfix/

二、虚拟用户设置SMTP发信认证

2.1 软件安装

注意:确认系统中的rpm格式的mysql 软件被卸载

[root@mail ~]# cd /soft

[root@mail soft]# tar -jxvf courier-authlib-0.62.4.tar.bz2 -C /usr/local/src/

[root@mail soft]# cd /usr/local/src/courier-authlib-0.62.4/

[root@mail courier-authlib-0.62.4]# ./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

/*install-configure #生成默认配置文件authmysqlrc authdaemonrc*/

[root@mail courier-authlib-0.62.4]# make && make install && make install-configure

2.2、 添加courier-authlib的库文件路径

[root@mail courier-authlib-0.62.4]# vim /etc/ld.so.conf.d/courier-authlib.conf

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

[root@mail courier-authlib-0.62.4]# ldconfig -v |grep courier-authlib

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

2.3、 修改authdaemonrc主配置文件

[root@mail courier-authlib-0.62.4]# cd /usr/local/courier-authlib/etc/authlib

[root@mail authlib]# cp authdaemonrc authdaemonrc.bak

[root@mail authlib]# vim authdaemonrc

27 authmodulelist="authmysql"

34 authmodulelistorig="authmysql"

[root@mail authlib]# chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/

2.4、 修改authmysqlrc 文件

[root@mail authlib]# cd /usr/local/courier-authlib/etc/authlib

[root@mail authlib]# cp authmysqlrc authmysqlrc.bak

[root@mail authlib]# vim authmysqlrc

26 MYSQL_SERVER localhost

27 MYSQL_USERNAME extmail

28 MYSQL_PASSWORD extmail

49 MYSQL_SOCKET /tmp/mysql.sock

56 MYSQL_PORT 3306

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

2.5、 复制courier-authlib脚本,并启动courier-authlib服务。

[root@mail authlib]# cd /usr/local/src/courier-authlib-0.62.4/

[root@mail courier-authlib-0.62.4]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib

[root@mail courier-authlib-0.62.4]# cd

[root@mail ~]# chmod 755 /etc/init.d/courier-authlib

[root@mail ~]# chkconfig --add courier-authlib

[root@mail ~]# chkconfig --level 2345 courier-authlib on

[root@mail ~]# chkconfig --list courier-authlib

courier-authlib   0:off  1:off  2:on   3:on   4:on   5:on   6:off

[root@mail ~]# service courier-authlib start

Starting Courier authentication services: authdaemond

[root@mail ~]# ps -aux |grep courier-authlib

三、修改Cyrus sasl 设置

3.1、添加如下文件

[root@mail ~]# vim /usr/lib/sasl2/smtpd.conf

pwcheck_method: authdaemond

mech_list:PLAIN LOGIN

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socke

四、修改Dovecot配置

4.1、修改Dovecot

[root@mail ~]# vim /etc/dovecot.conf

208 mail_location = maildir:/mailbox/%d/%n/Maildir

790 auth default {

795 mechanisms = plain

828 # passdb pam {

857 # }

899 passdb sql {

901 args = /etc/dovecot-mysql.conf

902 }

962 userdb sql {

964 args = /etc/dovecot-mysql.conf

965 }

4.2、打开一行,postfix的配置文件也要该(可能已经改过)

[root@mail ~]# vim /etc/postfix/main.cf

415 home_mailbox = Maildir/

10.2 建立数据查询配置文件,手动产生/etc/dovecot-mysql.conf文件:

[root@mail ~]# vim /etc/dovecot-mysql.conf

1 ver = mysql

2 connect = host=localhost dbname=extmail user=extmail password=extmail

3 default_pass_scheme = CRYPT

4 password_query = SELECT username AS user,password AS password FROM m ailbox WHERE username = %u

5 user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FRO M mailbox WHERE username = %u

五、建立虚拟用户

5.1、建立邮箱目录并调整权限

[root@mail ~]# mkdir -p /mailbox/extmail.org/postmaster/Maildir

[root@mail ~]# cd /mailbox/extmail.org/postmaster/Maildir/

[root@mail Maildir]# chown -R postfix:postfix /mailbox/

5.2、启动服务

[root@mail Maildir]# dovecot

Fatal: Dovecot is already running with PID 29275 (read from /usr/local/var/run/dovecot/master.pid)

[root@mail Maildir]# /usr/local/sbin/dovecot -c /etc/dovecot.conf

Fatal: Dovecot is already running with PID 29275 (read from /usr/local/var/run/dovecot/master.pid)

5.3、虚拟用户测试

确认authlib服务

[root@mail Maildir]# /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)

 

你可能感兴趣的:(smtp,postfix,Dovecot,sasl,cyrus)