本文接着上文的环境,进行postfix邮件发信端和dovecot邮件收信端的部署,之后部署基于浏览器的extmail图形管理端,使管理员可以通过网页对邮件虚拟用户进行管理,对邮件服务器进行管控

1.postfix邮件发信端部署

1.1.清理会引起冲突的软件sendmail,如果是关闭相关软件设计操作过多,不推荐

  1. rpm -qa postfix sendmail
  2. rpm -e --nodeps postfix sendmail

# 清除之前的邮件账号信息

  1. userdel postfix
  2. groupdel postdrop
  3. cat /etc/passwd|grep post*
  4. cat /etc/gshadow|grep post*

1.2.创建postfix邮件用户和组

  1. groupadd -g postfix
  2. useradd -g postfix -u -s /sbin/nologin -M postfix
  3. groupadd -g postdrop
  4. useradd -g postdrop -u -s /sbin/nologin -M postdrop
  5.  
  6. cat /etc/passwd|grep post*
  7. cat /etc/gshadow|grep post*

# 新建虚拟用户邮箱目录,并将其权限赋予postfix用户:

  1. mkdir -p /var/mailbox
  2. chown -R postfix /var/mailbox

1.3.源码编译安装postfix-3.2.3

  1. cd /server/tools
  2. wget ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/official/postfix-3.2.3.tar.gz
  3. tar -zxf postfix-3.2..tar.gz
  4. cd postfix-3.2.

# 配置参数

  1. make makefiles \
  2. 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS -I/usr/include/openssl' \
  3. 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'

# 编译安装

  1. make
  2. make install

# 执行完之后会进入设置相关目录的交互界面,基本按照默认配置即可。

  1. install_root: [/]
  2. tempdir: [/server/tools/postfix-3.2.]
  3. config_directory: [/etc/postfix]
  4. command_directory: [/usr/sbin]
  5. daemon_directory: [/usr/libexec/postfix]
  6. data_directory: [/var/lib/postfix]
  7. html_directory: [no] /usr/local/postfix/html
  8. mail_owner: [postfix]
  9. mailq_path: [/usr/bin/mailq]
  10. manpage_directory: [/usr/local/man]
  11. newaliases_path: [/usr/bin/newaliases]
  12. queue_directory: [/var/spool/postfix]
  13. readme_directory: [no] /usr/local/postfix/readme
  14. sendmail_path: [/usr/sbin/sendmail]
  15. setgid_group: [postdrop]
  16. shlib_directory: [no] /usr/local/postfix/share-library
  17. meta_directory: [/etc/postfix]

1.4.更新别名数据文件/etc/aliases.db,这个步骤如果忽略,会造成postfix效率极低

  1. /usr/bin/newaliases
  2. ll /etc/aliases.db

# 注意:

1).安装过程如果报错,需要删除目录重新安装
2).本文采用yum安装Mysql和sasl2,如果使用源码安装这两个软件,需要修改编译时CCARGS和AUXLIBS选项。

使用源码安装的mysql和cyrus-sasl,使用以下编译参数:

  1. make makefiles \
  2. 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/sasl2/include/sasl -DUSE_TLS -I/usr/include/openssl' \
  3. 'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lrt -lm -L/usr/local/sasl2/lib -lsasl2 -lssl -lcrypto'

3).在执行make install的时有如下的提示:
/usr/libexec/ld-elf.so.1: Shared object "libmysqlclient.so.12" not found
是因为mysql的lib库没找到,需要告诉postfix应该到哪里去找libmysqlclient.so.12。
使用ldconfig可以解决,例如:

  1. echo /usr/local/mysql/lib/mysql >> /etc/ld.so.conf
  2. ldconfig

4).make install的交互配置最好使用默认,如果修改根目录则目录结构会乱掉
5).如果/etc/aliases文件不存在,可以用如下命令创建:

  1. echo postfix: root >> /etc/aliases

1.5.修改相关目录的权限否则,postfix无法正常运行(必须使用以下顺序授权)

  1. cd /server/tools
  2. chown -R postfix.postfix /var/lib/postfix/
  3. chown -R postfix.postfix /var/spool/postfix/private
  4. chown -R postfix.postfix /var/spool/postfix/public
  5. chown -R root /var/spool/postfix/pid/
  6. chgrp -R postdrop /var/spool/postfix/public
  7. chgrp -R postdrop /var/spool/postfix/maildrop/
  8. chown root /var/spool/postfix

# 查看修改完的结果:

  1. ll /var/lib/postfix/ -d
  2. ll /var/lib/postfix/
  3. ll /var/spool/postfix/ -d
  4. ll /var/spool/postfix/

# 查看postfix相关程序文件

  1. ll /usr/sbin/post*
  2. ll /usr/libexec/postfix/
  3. ll /var/spool/postfix/
  4. ll /var/spool/postfix/private/
  5. ll /var/spool/postfix/incoming/

1.6.修改配置文件,启动postfix

  1. vim /etc/postfix/main.cf

# 修改并确认以下配置,改成自己对应的就好

  1. myhostname = mail.zuiyoujie.com
  2. mydomain = zuiyoujie.com
  3. myorigin = $mydomain
  4. inet_interfaces = 127.0.0.1, (外网地址)(或着写all
  5. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
  6. mynetworks = 127.0.0.0/

# 参数说明:

myhostname    指定运行postfix邮件系统的主机的主机名(用 FQDN 的方式来写),默认情况下,其值被设定为本地机器名;
mydomain          指定您的域名,默认情况下,postfix将myhostname的第一部分删除而作为mydomain的值;
myorigin             指明发件人所在的域名;邮件标头上面的 mail from 的那个地址
inet_interfaces   指定系统监听的网络接口;
mydestination    指定接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
mynetworks       指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;

# 注意:

1)在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2)任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;
3)每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;
4)如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;

# 为postfix提供SysV服务管理脚本/etc/rc.d/init.d/postfix

  1. vim /etc/init.d/postfix

# 以下是管理脚本具体内容:

  1. #!/bin/bash
  2. # postfix Postfix Mail Transfer Agent
  3. # chkconfig:
  4. # description: Postfix is a Mail Transport Agent, which is the program \
  5. # that moves mail from one machine to another.
  6. # processname: master
  7. # pidfile: /var/spool/postfix/pid/master.pid
  8. # main-config: /etc/postfix/main.cf
  9. # master-config: /etc/postfix/master.cf
  10. # Source function library.
  11. . /etc/rc.d/init.d/functions
  12. # Source networking configuration.
  13. . /etc/sysconfig/network
  14. # Check that networking is up.
  15. [ $NETWORKING = "no" ] && exit
  16. [ -x /usr/sbin/postfix ] || exit
  17. [ -d /etc/postfix ] || exit
  18. [ -d /var/spool/postfix ] || exit
  19.  
  20. RETVAL=
  21. prog="postfix"
  22. # Start daemons.
  23. start() {
  24. echo -n $"Starting postfix: "
  25. /usr/bin/newaliases >/dev/null >&
  26. /usr/sbin/postfix start >/dev/null >& && success || failure $"$prog start"
  27. RETVAL=$?
  28. [ $RETVAL -eq ] && touch /var/lock/subsys/postfix
  29. echo
  30. return $RETVAL
  31. }
  32. # Stop daemons.
  33. stop() {
  34. echo -n $"Shutting down postfix: "
  35. /usr/sbin/postfix stop >/dev/null >& && success || failure $"$prog stop"
  36. RETVAL=$?
  37. [ $RETVAL -eq ] && rm -f /var/lock/subsys/postfix
  38. echo
  39. return $RETVAL
  40. }
  41. reload() {
  42. echo -n $"Reloading postfix: "
  43. /usr/sbin/postfix reload >/dev/null >& && success || failure $"$prog reload"
  44. RETVAL=$?
  45. echo
  46. return $RETVAL
  47. }
  48. restart() {
  49. stop
  50. start
  51. }
  52. abort() {
  53. /usr/sbin/postfix abort >/dev/null >& && success || failure $"$prog abort"
  54. return $?
  55. }
  56. flush() {
  57. /usr/sbin/postfix flush >/dev/null >& && success || failure $"$prog flush"
  58. return $?
  59. }
  60. check() {
  61. /usr/sbin/postfix check >/dev/null >& && success || failure $"$prog check"
  62. return $?
  63. }
  64. case "$1" in
  65. start)
  66. start
  67. ;;
  68. stop)
  69. stop
  70. ;;
  71. restart)
  72. stop
  73. start
  74. ;;
  75. reload)
  76. reload
  77. ;;
  78. abort)
  79. abort
  80. ;;
  81. flush)
  82. flush
  83. ;;
  84. check)
  85. check
  86. ;;
  87. status)
  88. status master
  89. ;;
  90. condrestart)
  91. [ -f /var/lock/subsys/postfix ] && restart || :
  92. ;;
  93. *)
  94. echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
  95. exit
  96. esac
  97. exit $?

# 添加为系统服务,并设置开机自启动

  1. chmod /etc/init.d/postfix
  2. chkconfig --add postfix
  3. chkconfig postfix on
  4. chkconfig --list postfix

# postfix启动管理脚本测试

  1. service postfix start
  2. service postfix stop

# postfix常用的管理命令

  1. /usr/sbin/postfix start
  2. /usr/sbin/postfix reload
  3. /usr/sbin/postfix check

1.7.测试postfix是否可以正常发送邮件

  1. yum install telnet -y
    telnet 127.0.0.1 25

# 实例如下:

  1. [root@mail tools]# telnet 127.0.0.1
  2. Trying 127.0.0.1...
  3. Connected to 127.0.0.1.
  4. Escape character is '^]'.
  5. Welcome to our mail.zuiyoujie.com ESMTP!
  6. helo mail.zuiyoujie.com
  7. mail.zuiyoujie.com
  8. mail from:root@zuiyoujie.com
  9. 2.1. Ok
  10. rcpt to:zhaoshuai@zuiyoujie.com
  11. 2.1. Ok
  12. data
  13. End data with <CR><LF>.<CR><LF>
  14. from: root testmail <root@zuiyoujie.com>
  15. to:zhaoshuai@zuiyoujie.com
  16. subject:first test mail
  17. This is a test mail from root.
  18. .
  19. 2.0. Ok: queued as 329F5180712
  20. quit
  21. 2.0. Bye
  22. Connection closed by foreign host.
  23. [root@mail tools]# mailq
  24. -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
  25. 329F5180712* Mon Oct :: root@zuiyoujie.com
  26. zhaoshuai@zuiyoujie.com
  27.  
  28. -- Kbytes in Request.

# 使用以下命令可以查看邮件内容

  1. postcat -q [Queue ID]

# 实例如下:

  1. [root@mail ~]# postcat -q 329F5180712
  2. *** ENVELOPE RECORDS deferred//329F5180712 ***
  3. message_size:
  4. message_arrival_time: Mon Oct ::
  5. create_time: Mon Oct ::
  6. named_attribute: log_ident=329F5180712
  7. named_attribute: rewrite_context=local
  8. sender: root@zuiyoujie.com
  9. named_attribute: log_client_name=localhost
  10. named_attribute: log_client_address=127.0.0.1
  11. named_attribute: log_client_port=
  12. named_attribute: log_message_origin=localhost[127.0.0.1]
  13. named_attribute: log_helo_name=mail.zuiyoujie.com
  14. named_attribute: log_protocol_name=SMTP
  15. named_attribute: client_name=localhost
  16. named_attribute: reverse_client_name=localhost
  17. named_attribute: client_address=127.0.0.1
  18. named_attribute: client_port=
  19. named_attribute: server_address=127.0.0.1
  20. named_attribute: server_port=
  21. named_attribute: helo_name=mail.zuiyoujie.com
  22. named_attribute: protocol_name=SMTP
  23. named_attribute: client_address_type=
  24. named_attribute: dsn_orig_rcpt=rfc822;zhaoshuai@zuiyoujie.com
  25. original_recipient: zhaoshuai@zuiyoujie.com
  26. recipient: zhaoshuai@zuiyoujie.com
  27. *** MESSAGE CONTENTS deferred//329F5180712 ***
  28. Received: from mail.zuiyoujie.com (localhost [127.0.0.1])
  29. by mail.zuiyoujie.com (Postfix) with SMTP id 329F5180712
  30. for <zhaoshuai@zuiyoujie.com>; Mon, Oct :: + (CST)
  31. from: root testmail <root@zuiyoujie.com>
  32. to:zhaoshuai@zuiyoujie.com
  33. Message-Id: <.329F5180712@mail.zuiyoujie.com>
  34. Date: Mon, Oct :: + (CST)
  35. *** HEADER EXTRACTED deferred//329F5180712 ***
  36. *** MESSAGE FILE END deferred//329F5180712 ***

# 可以看出邮件服务器已经可以发送邮件,不过由于接收邮件的服务没有配好邮件还收不到,如果想看收发效果,可以将收件人改为自己的qq邮箱等进行测试。

# 接下来进行配置,启用smtp用户认证,使用courier-authlib通过数据库对虚拟用户进行管理

2.安装配置Courier authentication library 

# courier-authlib是Courier组件中的认证库,它是courier组件中一个独立的子项目,用于为Courier的其它组件提供认证服务,是由一位美籍俄罗斯人的杰作。其认证功能通常包括验正登录时的帐号和密码、获取一个帐号相关的家目录或邮件目录等信息、改变帐号的密码等。而其认证的实现方式也包括基于PAM对/etc/passwd和/etc/shadow进行认证,基于GDBM或DB进行认证,基于LDAP/MySQL/PostgreSQL进行认证等。因此,courier-authlib也常用来与courier之外的其它邮件组件(如postfix)整合为其提供认证服务。

  1. cd /server/tools
  2. wget http://jaist.dl.sourceforge.net/project/courier/authlib/0.66.1/courier-authlib-0.66.1.tar.bz2
  3. tar -xf courier-authlib-0.66..tar.bz2
  4. cd courier-authlib-0.66.

# 配置参数

  1. ./configure \
  2. --prefix=/usr/local/courier-authlib \
  3. --sysconfdir=/etc \
  4. --with-redhat \
  5. --with-mailuser=postfix \
  6. --with-mailgroup=postfix \
  7. --with-authmysql=yes \
  8. --with-authmysqlrc=/etc/authmysqlrc \
  9. --with-authdaemonrc=/etc/authdaemonrc \
  10. --with-mysql-libs=/usr/lib64/mysql \
  11. --with-mysql-includes=/usr/include/mysql \
  12. --without-authpam \
  13. --without-authpgsql \
  14. --without-authvchkpw \
  15. --without-authshadow

# 编译安装

  1. make
  2. make install
    make install-configure

# 创建认证配置文件

  1. chmod -R /usr/local/courier-authlib/var/spool/authdaemon
  2. cp /etc/authmysqlrc.dist /etc/authmysqlrc
  3. cp /etc/authdaemonrc.dist /etc/authdaemonrc
  4. ll /etc/authmysqlrc
  5. ll /etc/authdaemonrc

# 编辑/etc/authdaemonrc文件,确保使用mysql认证模块

  1. vim /etc/authdaemonrc

# 修改并确认以下配置

  1. authmodulelist="authpwd authmysql"
  2. authmodulelistorig="authpwd authmysql"
  3. daemons=

# 编辑/etc/authmysqlrc文件,让courier能够正确的读取MySQL中的认证信息

  1. vim /etc/authmysqlrc

# 修改并确认以下配置

  1. MYSQL_SERVER localhost
  2. MYSQL_USERNAME extmail # 数据库用户名
  3. MYSQL_PASSWORD extmail # 数据库密码
  4. MYSQL_SOCKET /var/lib/mysql/mysql.sock
  5. MYSQL_PORT # mysql监听的端口
  6. MYSQL_DATABASE extmail
  7. MYSQL_USER_TABLE mailbox
  8. MYSQL_CRYPT_PWFIELD password # 92行,crypt改为password
  9. DEFAULT_DOMAIN mail.zuiyoujie.com # 105行,默认邮件域
  10. MYSQL_UID_FIELD ''
  11. MYSQL_GID_FIELD ''
  12. MYSQL_LOGIN_FIELD username
  13. MYSQL_HOME_FIELD concat('/var/mailbox/',homedir) # 133行,home修改
  14. MYSQL_NAME_FIELD name
  15. MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir) # 150行,maildir修改

# 将courier-authlib配置为系统服务

  1. cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib
  2. chmod /etc/init.d/courier-authlib
  3. chkconfig --add courier-authlib
  4. chkconfig --list courier-authlib

# 将courier-authlib 的库目录添加到库搜索文件中

  1. echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
  2. ldconfig -v

# 启动 courier-authlib 服务

  1. service courier-authlib start

# 由于是socket的方式,所以没有端口,可以验证进程是否启动

  1. ps -ef | grep courier
  2. pstree | grep authdaemond
  3. ll /usr/local/courier-authlib/var/spool/authdaemon/socket

# 查看postfix是否支持cyrus-sasl认证功能

  1. cd /server/tools/
  2. /usr/sbin/postconf -a

# 出现以下内容表示可以使用sasl认证

  1. [root@mail tools]# /usr/sbin/postconf -a
  2. cyrus
  3. dovecot

# 设置postfix使用的sasl配置文件smtpd,让sasl知道该怎么从MySQL中读取认证信息,该文件需要手工创建,sasl密码验证机制为authdaemond

# 新建smtp认证文件,添加以下4行内容:

  1. vim /etc/sasl2/smtpd.conf
  1. pwcheck_method: authdaemond
  2. log_level:
  3. mech_list:PLAIN LOGIN
  4. authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

# 关于sasl2的认证文件smtpd.conf的位置,可以有以下3个,需要注意

  1. /etc/sasl2/smtpd.conf
  2. /usr/lib64/sasl2/smtpd.conf
  3. /etc/postfix/sasl2/smtpd.conf

# 配置postfix支持sasl邮箱安全认证

  1. vim /etc/postfix/main.cf

# 添加以下内容

  1. ###### CYRUS-SASL ######
  2. broken_sasl_auth_clients = yes
  3. smtpd_sasl_auth_enable = yes
  4. smtpd_sasl_local_domain = $myhostname
  5. smtpd_sasl_path = /etc/sasl2
  6. smtpd_sasl_security_options = noanonymous
  7. smtpd_banner = Welcome to our $myhostname ESMTP!
  8. smtpd_sender_restrictions = permit_mynetworks,reject_sender_login_mismatch,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_invalid_hostname,reject_authenticated_sender_login_mismatch,reject_unauthenticated_sender_login_mismatch,check_sender_access hash:/etc/postfix/access
  9. smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_sender_domain,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
  10. smtpd_sender_login_maps = mysql:/etc/postfix/mysql_virtual_sender_maps.cf,mysql:/etc/postfix/mysql_virtual_alias_maps.cf
  1. /usr/sbin/postfix check
  2. /usr/sbin/postfix reload

3.安装配置dovecot

  1. yum install dovecot dovecot-mysql

# 修改dovecot主配置文件

  1. vim /etc/dovecot/dovecot.conf
  1. protocols = imap pop3 lmtp # 启用
  2. listen = *

# 修改auth认证配置文件

  1. vim /etc/dovecot/conf.d/-auth.conf
  1. disable_plaintext_auth = no
  2. auth_mechanisms = plain login
  3. !include auth-system.conf.ext

# 修改10-mail.conf配置文件

  1. vim /etc/dovecot/conf.d/-mail.conf
  1. mail_location = maildir:/var/mailbox/%d/%n/Maildir

# 配置数据库认证相关文件

  1. cd /etc/dovecot/conf.d/
  2. cp auth-sql.conf.ext auth-sql.conf
  3. vim /etc/dovecot/conf.d/auth-sql.conf

# 第9行和第21行改为以下内容(去掉passdb和userdb的ext后缀)

  1. args = /etc/dovecot/dovecot-sql.conf

# 手工创建dovecot-sql.conf文件

  1. vim /etc/dovecot/dovecot-sql.conf
  1. driver = 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 mailbox WHERE username = '%u'
  5. user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'

# 启动dovecot邮件接收端

  1. chkconfig dovecot on
  2. chkconfig --list dovecot
  3. service dovecot start

4.安装extmail

  1. cd /server/tools
  2. tar -xf extmail-1.2.tar.gz
  3. mkdir -p /var/www/extsuite
  4. mv extmail-1.2 /var/www/extsuite/extmail
  5. chown -R postfix.postfix /var/www/extsuite/extmail
  6. ll /var/www/extsuite/extmail

# 修改配置文件

  1. cd /var/www/extsuite/extmail/
  2. cp webmail.cf.default webmail.cf
  3. vim /var/www/extsuite/extmail/webmail.cf
  1. SYS_USER_LANG = zh_CN # 77行,语言选项
  2. SYS_MESSAGE_SIZE_LIMIT = # 105行,用户可以发送的邮件大小默认5M
  3. SYS_MIN_PASS_LEN = # 107行,最短密码长度
  4. SYS_MAILDIR_BASE = /var/mailbox # 127行,前文所设置的用户邮件的存放目录
  5. SYS_MYSQL_USER = extmail # 140行,连接数据库服务器所使用用户名
  6. SYS_MYSQL_PASS = extmail # 141行,密码和邮件服务器用到的数据库
  7. SYS_MYSQL_HOST = localhost # 143行,数据库服务器主机名
  8. SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
  9. SYS_MYSQL_TABLE = mailbox
  10. # 147行,以下配置用来指定验证用户登录所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称,默认即可
  11. SYS_MYSQL_ATTR_USERNAME = username
  12. SYS_MYSQL_ATTR_DOMAIN = domain
  13. SYS_MYSQL_ATTR_PASSWD = password
  14. # 198行,指定之前安装的authdaemo socket文件的位置
  15. SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket

# 创建extmail临时目录

  1. mkdir -p /tmp/extmail/upload
  2. chown -R postfix.postfix /tmp/extmail/
  3. ll /tmp
  4. ll /tmp/extmail/

5.安装extman

  1. cd /server/tools/
  2. tar -xf extman-1.1.tar.gz
  3. mv extman-1.1 /var/www/extsuite/extman
  4. chown -R postfix.postfix /var/www/extsuite/extman
  5. ll /var/www/extsuite/extman

# 修改配置文件

  1. cd /var/www/extsuite/extman/
  2. cp webman.cf.default webman.cf
  3. vim /var/www/extsuite/extman/webman.cf
  1. SYS_MAILDIR_BASE = /var/mailbox # 12行,设置的用户邮件的存放目录
  2. SYS_SESS_DIR = /tmp/extman/
  3. # 此两处后面设定的ID号需更改为前而创建的postfix用户和postfix组的id号,本文使用的
  4. SYS_DEFAULT_UID = # 98行
  5. SYS_DEFAULT_GID = # 101行
  6. SYS_MYSQL_USER = extmail # 127行
  7. SYS_MYSQL_PASS = extmail # 128行
  8. SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock # 132行
  9. # 132行,指定验证管理员登录所用到的表,及相关参数,默认即可
  10. SYS_MYSQL_TABLE = manager
  11. SYS_MYSQL_ATTR_USERNAME = username
  12. SYS_MYSQL_ATTR_PASSWD = password

# 创建extman临时目录,用于session等数据文件

  1. mkdir /tmp/extman
  2. chown -R postfix.postfix /tmp/extman/
  3. ll /tmp

# 修改cgi目录的属主,便于网页访问

  1. chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
  2. chown -R postfix.postfix /var/www/extsuite/extman/cgi/
  3. ll /var/www/extsuite/extmail/cgi/
  4. ll /var/www/extsuite/extman/cgi/

# 复制5个虚拟用户数据库配置文件到postfix目录

  1. cd /var/www/extsuite/extman/docs/
  2. cp mysql_virtual_* /etc/postfix/
  3. ll /etc/postfix/mysql_virtual_*

# 初始化extmail数据库(空密码)

  1. mysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql
  2. mysql -u root -p < /var/www/extsuite/extman/docs/init.sql

# 据库授权

  1. mysql -uroot -p
  1. grant all privileges on extmail.* to extmail@localhost identified by 'extmail';
  2. grant all privileges on extmail.* to extmail@127.0.0.1 identified by 'extmail';
  3. flush privileges;
  4. delete from mysql.user where user=' ';
  5. delete from mysql.user where host='mail.zuiyoujie.com';
  6. select user,host from mysql.user;

# 编辑/etc/postfix/main.cf,让postfix支持虚拟域和虚拟用户

  1. vim /etc/postfix/main.cf
  1. ####### Virtual Mailbox Settings #######
  2. virtual_uid_maps = static:
  3. virtual_gid_maps = static:
  4. virtual_transport = virtual
  5. message_size_limit =
  6. virtual_mailbox_base = /var/mailbox
  7. virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
  8. virtual_mailbox_limit = mysql:/etc/postfix/mysql_virtual_limit_maps.cf
  9. virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
  10. virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
  11. virtual_alias_domains =
  12. smtpd_client_connection_count_limit =
  13. smtpd_client_connection_rate_limit =

# 重新载入配置文件

  1. /usr/sbin/postfix check
  2. /usr/sbin/postfix reload

6.配置Mailgraph_ext,使用Extman的图形日志

# 配置启动图形工具

  1. cp -r /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext/
  2. /usr/local/mailgraph_ext/mailgraph-init start
  3. /var/www/extsuite/extman/daemon/cmdserver -daemon

# 配置开机自启动

  1. echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.d/rc.local
  2. echo "/var/www/extsuite/extman/daemon/cmdserver -v -d" >> /etc/rc.d/rc.local

7.配置Apache,使用浏览器进行虚拟用户管理

  1. vim /etc/httpd/conf/httpd.conf

# 修改并确认以下配置

  1. LoadModule suexec_module modules/mod_suexec.so # 198行,将suexec插件注释掉,否则配置比较麻烦
  2. User postfix         # 242行,修改http运行用户postfix
  3. Group postfix   # 243行,修改http运行组为postfix
  4. ServerName mail.zuiyoujie.com # 276行,修改监听域名
  5. # DocumentRoot "/var/www/html" # 292行,将之注释掉,启用虚拟主机

# 配置虚拟主机

  1. vim /etc/httpd/conf.d/extmail.conf
  1. <VirtualHost *:>
  2. ServerName mail.zuiyoujie.com
  3. DocumentRoot /var/www/extsuite/extmail/html/
  4. ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
  5. Alias /extmail /var/www/extsuite/extmail/html
  6. ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
  7. Alias /extman /var/www/extsuite/extman/html
  8. </VirtualHost>

# 启动Apache

  1. service httpd start
  2. chkconfig httpd on
  3. chkconfig --list httpd

# 接下来就可以登录http://mail.zuiyoujie.com,选择管理即可登入extman进行后台管理了

# 默认的管理员用户密码

  1. root@extmail.org
  2. extmail**

至此postfix邮箱服务器的收发件,用户安全认证就已经配置完成,可以集中管理邮件虚拟用户

8.常用邮件日志分析

# 动态跟踪日志变化

  1. tail -f /var/log/maillog

# 取指定类型的日志

  1. egrep '(reject|warning|error|fatal|panic):' /var/log/maillog

# 查看postfix成功接收到邮件:(交货到邮件目录)

  1. cat /var/log/maillog |grep "delivered to maildir"
  2. cat /var/log/maillog |grep "delivered to maildir" | egrep -o "(\w+)([@]{1}\w+[.]{1,})(\w+)"

# 取指定日期,指定类型日志:

  1. cat /var/log/maillog | grep "^Oct\ 17" | egrep "reject|warning|error|fatal|panic" | less

# 取指定日期,指定类型日志:

  1. cat /var/log/maillog | grep "^Oct\ 17" | egrep "reject|warning|error|fatal|panic" | less

9.postfix中的命令行工具

mailq 对邮件队列文件进行列表。表中的每一个条目包含有以下信息:队列文件ID、邮件的大小、到达的时间、发件人、收件人和投递延迟的原因(如果投递有延迟的话)。该命令主要是与showq后台程序通信来获取队列文件的相关信息。该命令无参数。
newaliases 该工具进行别名数据库的初始化。如果没有指定数据库的类型,则使用系统默认的数据库类型(在linux下为hash)。该命令可以不带参数执行。
postcat 打印邮件队列文件的内容。后面接要显示的队列文件名,可以带一个-v的参数进行冗余显示。
postmap 建立postfix查询数据库。在linux下可以直接跟上原始文件而不带任何参数来建立该数据库。
postconf -d 打印配置参数的缺省值。
postconf -m 列出所有支持的查询表类型。
postconf -n 查看postfix生效的配置

完毕,呵呵呵

postfix邮件服务器搭建02-安装篇的更多相关文章

  1. postfix邮件服务器搭建03-webmail安装篇

    本文接着上文的安装进行,介绍另一个WebMail功能更加人性化的roundcube.当然也可以对已有的postfix邮件系统进行功能完善 1.下载安装roundcube cd /server/tool ...

  2. postfix邮件服务器搭建01-准备篇

    本系列文章主要介绍linux下主流的开源邮件系统postfix的搭建过程,构建一个通过postfix虚拟用户管理的完整的邮件系统, 该系统包括以下组件: 邮件收发端postfix,dovecot, 邮 ...

  3. postfix邮件服务器搭建04-终结篇

    本来是计划对postfix做一个全系列的安装文档的,不过在查某个知识点的时候,偶然找到一个已经写好的postfix全系列文章,在全部看完之后惊为天人,我认为:总体上会比我要写的要好,所以我准备借用一下 ...

  4. 烂泥:Postfix邮件服务器搭建之虚拟用户配置

    virtual_gid_maps = static: virtual_transport = dovecot dovecot_destination_recipient_limit = 1 注意:po ...

  5. 烂泥:Postfix邮件服务器搭建之软件安装与配置

    本文由ilanniweb提供友情赞助,首发于烂泥行天下 想要获得更多的文章,可以关注我的微信ilanniweb Postfix邮件服务器的搭建需要使用到几个软件,分别是cyrus-sasl.postf ...

  6. 烂泥:Postfix邮件服务器搭建之准备工作

    说实话,Postfix邮件服务器的搭建是一件很麻烦的事情,需要各种软件之间的配置和调试.在写这篇文章之前,我也是搭建测试了不下于10次才算把整个流程给走通,今天刚好有时间把整个搭建过程记录下来. 在正 ...

  7. Postfix 邮件服务器搭建

    搭建服务环境: Centos 6 配置域名hosts: mail.demonC6.com 1.清理系统自带的邮件软件 # rpm -qa | grep sendmail* # rpm -e sendm ...

  8. Postfix邮件服务器搭建及配置

    一.邮件服务器(Mail Server)的传输协议 1.简单邮件传输协议(SMTP):Simple Mail Transger Protocol 2.扩展的简单邮件传输协议(ESMTP):Extend ...

  9. CentOS6.4下邮件服务器搭建

    CentOS6.4下邮件服务器搭建   linux下邮件服务器的搭建大致分为三个步骤 准备工作(真实的生产环境下需要) 发送服务器安装及配置 (Postfix) 接收服务器安装及配置(dovecot) ...

随机推荐

  1. webservice的cxf和spring整合客户端开发

    1.新建一个java项目 2.导入cxf相关的jar包,并部署到项目中 3.用命令生成客户端使用说明文档 wsdl2java -p com.xiaostudy -d . http://127.0.0. ...

  2. Ice Cream Tower

    2017-08-18 21:53:38 writer:pprp 题意如下: Problem D. Ice Cream Tower Input file: Standard Input Output f ...

  3. No input file specified. nginx服务器报错解决

    配置虚拟域名的时候报No input file specified. 仔细观察一圈也没有发现任何错误,最终,我把注意力放到 \ 上.才发现问题. 以前我都是直接copy文件路径过去 文件里面 都是使用 ...

  4. java自带的MD5

    前言:        MD5可生成16.32.64位数的签名. // MD5加码,32位 public static String toMD5(String plainText) { String r ...

  5. 设计模式——适配器(Adapter)模式

    概述 什么是适配器?在我们生活中的适配器比如插头转换器(中标转美标).USB接口转换器(type-c转苹果),电脑电源适配器(交流电转低电压直流)等.像这种将两者有差异的东西通过适配器使他们成为相互适 ...

  6. jQuery 中$.ajax()方法参数详解

    $.ajax({ url:'test.do', data:{id:,name:'xiaoming'}, type:'post', dataType:'json', success:function(d ...

  7. HighCharts常用设置

    1. X轴文字斜着放,在xAxis里设置 xAxis: { labels: { rotation: -90 //竖直放 rotation: -45 //45度倾斜 } } 2. 柱形图柱形的宽度和边框 ...

  8. 解决boot空间不足问题

    uname -a :查看现在系统信息,内核版本 dpkg --get-selections |grep linux-image : 查看内核列表 sudo apt-get remove linux-i ...

  9. (2) iOS开发之UI处理-UILabel篇

    我们经常要根据内容去动态计算控件的高度,比如一个UILabel控件,常常要显示多行内容,并且计算出总高度,如果每个UILabel要多行显示,都要写这么一段代码是非常痛苦的,看代码如下:     我想大 ...

  10. yii控制布局方式

    1:在控制器内成员变量设置 public $layout = false; //不使用布局 public $layout = “main”; //设置使用的布局文件 2:在控制器成员方法内设置 $th ...