本文将详细介绍如何使用postfix,extman,extmail等一系列开源软件构建适合企业应用的邮件系统,测试服务器平台为RHEL5.4 32位操作系统,在开始之前,请部署好LAMP环境,这方面的介绍可以参考我的另一篇文章:http://ylw6006.blog.51cto.com/470441/657907,如果要做到收发邮件均没有问题,需要DNS的邮件交换记录(MX)支持,这方面的设置不在本文中介绍…
一:安装courier-authlib
- 1:使用该验证库,可以使用mysql验证邮件账户
- [root@orcl ~]# cd /usr/local/src/tarbag
- [root@orcl tarbag]# wget http://sourceforge.net/projects/courier/files/authlib/0.63.0/courier-authlib-0.63.0.tar.bz2/download
- [root@orcl tarbag]# tar -jxvf courier-authlib-0.63.0.tar.bz2 -C ../software/
- [root@orcl tarbag]# cd ../software/courier-authlib-0.63.0/
- [root@orcl courier-authlib-0.63.0]# groupadd postfix -g 1000
- [root@orcl courier-authlib-0.63.0]# groupadd vmail -g 1001
- [root@orcl courier-authlib-0.63.0]# groupadd postdrop -g 1002
- [root@orcl courier-authlib-0.63.0]# useradd -u 1001 -g 1000 vmail
- [root@orcl courier-authlib-0.63.0]# useradd -u 1000 -g 1000 postfix
- [root@orcl courier-authlib-0.63.0]# id vmail
- uid=1001(vmail) gid=1000(postfix) groups=1000(postfix)
- [root@orcl courier-authlib-0.63.0]# id postfix
- uid=1000(postfix) gid=1000(postfix) groups=1000(postfix)
- [root@orcl courier-authlib-0.63.0]# ./configure --prefix=/usr/local/courier-authlib --with-mailuser=vmail --with-mailgroup=vmail --sysconfdir=/etc --without-authpam --without-authldap --without-authpwd --without-authshadow --without-authvchkpw --without-authpgsql --with-authmysql --with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-includes=/usr/local/mysql/include/mysql --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc CFLAGS="-march=i686 -O2 -fexpensive-optimizations" CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations"
- [root@orcl courier-authlib-0.63.0]# make && make install
- [root@orcl courier-authlib-0.63.0]# ls /usr/local/courier-authlib/
- bin include lib libexec sbin share var
- [root@orcl courier-authlib-0.63.0]# echo '/usr/local/courier-authlib/lib/courier-authlib/' >> /etc/ld.so.conf
- [root@orcl courier-authlib-0.63.0]# ldconfig
- 备注:如果是64位系统,需要将i686修改位x86-64,各编译选项的含义可以使用./configrue --help来获取
- 2:修改authlib库相关配置文件
- [root@orcl ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
- [root@orcl ~]# grep -v '^#' /etc/authdaemonrc |grep -v '^$'
- authmodulelist="authmysql"
- authmodulelistorig="authmysql"
- daemons=5
- authdaemonvar=/usr/local/courier-authlib/var/spool/authdaemon
- DEBUG_LOGIN=0
- DEFAULTOPTIONS=""
- LOGGEROPTS=""
- [root@orcl ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
- [root@orcl ~]# grep -v '^#' /etc/authmysqlrc |grep -v '^$'
- MYSQL_SERVER 127.0.0.1
- MYSQL_USERNAME extmail
- MYSQL_PASSWORD 123456
- MYSQL_SOCKET /tmp/mysql.sock
- MYSQL_PORT 3306
- MYSQL_OPT 0
- MYSQL_DATABASE extmail
- MYSQL_USER_TABLE mailbox
- MYSQL_CRYPT_PWFIELD password
- MYSQL_UID_FIELD 1001
- MYSQL_GID_FIELD 1001
- MYSQL_LOGIN_FIELD username
- MYSQL_HOME_FIELD concat('/email/mailbox/',homedir)
- MYSQL_NAME_FIELD name
- MYSQL_MAILDIR_FIELD concat('/email/mailbox/',maildir)
- 3:启动authlib服务
- [root@orcl ~]# /usr/local/courier-authlib/sbin/authdaemond start
- [root@orcl ~]# ps -ef |grep courier
- root 31874 1 0 11:35 ? 00:00:00 /usr/local/courier-authlib/sbin/courierlogger -pid=/usr/local/courier-authlib/var/spool/authdaemon/pid -start /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
- root 31875 31874 0 11:35 ? 00:00:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
- root 31876 31875 0 11:35 ? 00:00:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
- root 31877 31875 0 11:35 ? 00:00:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
- root 31878 31875 0 11:35 ? 00:00:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
- root 31879 31875 0 11:35 ? 00:00:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
- root 31880 31875 0 11:35 ? 00:00:00 /usr/local/courier-authlib/libexec/courier-authlib/authdaemond
- [root@orcl ~]# echo '/usr/local/courier-authlib/sbin/authdaemond start' > /etc/rc.local
二:安装 cyrus-sasl,SASL (Simple Authentication Security Layer)简单认证安全层,功能主要是用于SMTP认证;而 Cyrus SASL是SASL的一个实现
- 1:卸载系统自带的sasl rpm包,使用--nodeps选项强制卸载
- [root@orcl ~]# rpm -qa |grep sasl
- cyrus-sasl-2.1.22-5.el5
- cyrus-sasl-devel-2.1.22-5.el5
- cyrus-sasl-lib-2.1.22-5.el5
- cyrus-sasl-plain-2.1.22-5.el5
- [root@orcl ~]# rpm -e $(rpm -qa |grep cyrus-sasl) --nodeps
- [root@orcl ~]# rpm -qa |grep sasl |wc -l
- 0
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# wget ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.22.tar.gz
- [root@orcl tarbag]# tar -zxvf cyrus-sasl-2.1.22.tar.gz -C ../software/
- [root@orcl tarbag]# cd ../software/cyrus-sasl-2.1.22/
- [root@orcl cyrus-sasl-2.1.22]# ./configure --prefix=/usr/local/sasl2 --with-mysql=/usr/local/mysql --disable-sample --disable-saslauthd --disable-pwcheck --disable-cram --disable-digest --disable-krb4 --disable-gssapi --disable-anon --enable-plain --enable-login --enable-sql --disable-ntlm --disable-otp --disable-srp --disable-srp-setpass --with-authdaemond=/usr/local/courier-authlib/var/spool/authdaemon/socket --with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/mysql
- [root@orcl cyrus-sasl-2.1.22]# make && make install
- [root@orcl cyrus-sasl-2.1.22]# ls /usr/local/sasl2/
- include lib man sbin
- [root@orcl cyrus-sasl-2.1.22]# rm -rf /usr/lib/sasl2/
- [root@orcl cyrus-sasl-2.1.22]# ln -s /usr/local/sasl2/lib/sasl2/ /usr/lib
- [root@orcl ~]# tail -2 /etc/ld.so.conf
- /usr/local/sasl2/lib/sasl2
- /usr/local/sasl2/lib
- [root@orcl ~]# ldconfig
- 2:编辑smtpd认证配置文件,该文件默认不存在
- [root@orcl ~]# cat /usr/local/sasl2/lib/sasl2/smtpd.conf
- pwcheck_method: authdaemond
- log_level: 3
- mech_list: PLAIN LOGIN
- authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
- 3:创建相关目录并启动测试
- [root@orcl ~]# mkdir -p /var/state/saslauthd
- [root@orcl ~]# /usr/local/sasl2/sbin/saslauthd -a shadow pam -d
- saslauthd[10252] :main : num_procs : 5
- saslauthd[10252] :main : mech_option: NULL
- saslauthd[10252] :main : run_path : /var/state/saslauthd
- saslauthd[10252] :main : auth_mech : shadow
- saslauthd[10252] :ipc_init : using accept lock file: /var/state/saslauthd/mux.accept
- saslauthd[10252] :detach_tty : master pid is: 0
- saslauthd[10252] :ipc_init : listening on socket: /var/state/saslauthd/mux
- saslauthd[10252] :main : using process model
- saslauthd[10253] :get_accept_lock : acquired accept lock
- saslauthd[10252] :have_baby : forked child: 10253
- saslauthd[10252] :have_baby : forked child: 10254
- saslauthd[10252] :have_baby : forked child: 10255
- saslauthd[10252] :have_baby : forked child: 10256
- saslauthd[10256] :server_exit : child exited: 10256
- saslauthd[10255] :server_exit : child exited: 10255
- saslauthd[10254] :server_exit : child exited: 10254
- saslauthd[10253] :server_exit : child exited: 10253
- saslauthd[10252] :handle_sigchld : child exited: 10253
- saslauthd[10252] :handle_sigchld : child exited: 10254
- saslauthd[10252] :handle_sigchld : child exited: 10255
- saslauthd[10252] :handle_sigchld : child exited: 10256
- 此处按"ctrl+C"
- saslauthd[10252] :server_exit : pid file lock removed: /var/state/saslauthd/saslauthd.pid.lock
- saslauthd[10252] :ipc_cleanup : accept lock file removed: /var/state/saslauthd/mux.accept
- saslauthd[10252] :ipc_cleanup : socket removed: /var/state/saslauthd/mux
- saslauthd[10252] :server_exit : master exited: 0
- [root@orcl ~]# /usr/local/sasl2/sbin/saslauthd -a shadow pam -d &
- [1] 30341
- [root@orcl ~]# exit
- logout
- [root@orcl ~]# ps -ef |grep sasl
- root 30341 1 0 11:19 ? 00:00:00 /usr/local/sasl2/sbin/saslauthd -a shadow pam -d
- root 30342 30341 0 11:19 ? 00:00:00 /usr/local/sasl2/sbin/saslauthd -a shadow pam -d
- root 30343 30341 0 11:19 ? 00:00:00 /usr/local/sasl2/sbin/saslauthd -a shadow pam -d
- root 30344 30341 0 11:19 ? 00:00:00 /usr/local/sasl2/sbin/saslauthd -a shadow pam -d
- root 30345 30341 0 11:19 ? 00:00:00 /usr/local/sasl2/sbin/saslauthd -a shadow pam -d
- [root@orcl ~]# echo '/usr/local/sasl2/sbin/saslauthd -a shadow pam -d' >> /etc/rc.local
三:安装BerkeleyDB
- 1:卸载系统自带的db4 rpm包,使用--nodeps选项强制卸载
- [root@orcl ~]# rpm -qa |grep db4
- db4-4.3.29-10.el5
- db4-devel-4.3.29-10.el5
- [root@orcl ~]# rpm -e $(rpm -qa |grep db4) --nodeps
- [root@orcl ~]# rpm -qa |grep db4 |wc -l
- 0
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# wget http://download.oracle.com/berkeley-db/db-4.8.26.tar.gz
- [root@orcl tarbag]# tar -zxvf db-4.8.26.tar.gz -C ../software/
- [root@orcl tarbag]# cd ../software/db-4.8.26/build_unix/
- [root@orcl build_unix]# ../dist/configure --prefix=/usr/local/BerkeleyDB
- [root@orcl build_unix]# make && make install
- [root@orcl build_unix]# ls /usr/local/BerkeleyDB/
- bin docs include lib
- [root@orcl ~]# ln -s /usr/local/BerkeleyDB/include /usr/include/db4
- [root@orcl ~]# ln -s /usr/local/BerkeleyDB/include/db.h /usr/include/
- [root@orcl ~]# ln -s /usr/local/BerkeleyDB/include/db_cxx.h /usr/include/
- [root@orcl ~]# echo '/usr/local/BerkeleyDB/lib' >> /etc/ld.so.conf
- [root@orcl ~]# ldconfig
四:安装postfix
- 1:关闭sendmail
- [root@orcl ~]# service sendmail stop
- Shutting down sm-client: [ OK ]
- Shutting down sendmail: [ OK ]
- [root@orcl ~]# chkconfig sendmail off
- 2:下载postfix源码包并编译安装
- [root@orcl ~]# echo '/usr/local/mysql/lib/mysql/' >> /etc/ld.so.conf
- [root@orcl ~]# ldconfig
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# wget ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/official/postfix-2.8.0.tar.gz
- [root@orcl tarbag]# wget http://vda.sourceforge.net/VDA/postfix-vda-2.8.0.patch //支持磁盘配额的补丁
- [root@orcl tarbag]# tar -zxvf postfix-2.8.0.tar.gz -C ../software/
- [root@orcl tarbag]# mv postfix-vda-2.8.0.patch ../software/postfix-2.8.0/
- [root@orcl tarbag]# cd ../software/postfix-2.8.0/
- [root@orcl postfix-2.8.0]# make clean
- [root@orcl postfix-2.8.0]# make tidy
- [root@orcl postfix-2.8.0]# patch -p1 < postfix-vda-2.8.0.patch
- patching file README_FILES/VDA_README
- patching file src/global/mail_params.h
- patching file src/util/file_limit.c
- patching file src/virtual/mailbox.c
- patching file src/virtual/maildir.c
- patching file src/virtual/virtual.c
- patching file src/virtual/virtual.h
- [root@orcl postfix-2.8.0]# make -f Makefile.init Makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/sasl2/include/sasl' 'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/local/sasl2/lib -lsasl2 -L/usr/local/BerkeleyDB/lib'
- [root@orcl postfix-2.8.0]# make && make install
- Please specify the prefix for installed file names. Specify this ONLY
- if you are building ready-to-install packages for distribution to other
- machines.
- install_root: [/]
- Please specify a directory for scratch files while installing Postfix. You
- must have write permission in this directory.
- tempdir: [/usr/local/src/software/postfix-2.8.0]
- Please specify the final destination directory for installed Postfix
- configuration files.
- config_directory: [/etc/postfix] /usr/local/postfix/etc
- Please specify the final destination directory for installed Postfix
- administrative commands. This directory should be in the command search
- path of adminstrative users.
- command_directory: [/usr/sbin] /usr/local/postfix/sbin
- Please specify the final destination directory for installed Postfix
- daemon programs. This directory should not be in the command search path
- of any users.
- daemon_directory: [/usr/libexec/postfix] /usr/local/postfix/libexec
- Please specify the final destination directory for Postfix-writable
- data files such as caches or random numbers. This directory should not
- be shared with non-Postfix software.
- data_directory: [/var/lib/postfix] /usr/local/postfix/var/lib
- Please specify the destination directory for the Postfix HTML
- files. Specify "no" if you do not want to install these files.
- html_directory: [no]
- Please specify the owner of the Postfix queue. Specify an account with
- numerical user ID and group ID values that are not used by any other
- accounts on the system.
- mail_owner: [postfix]
- Please specify the final destination pathname for the installed Postfix
- mailq command. This is the Sendmail-compatible mail queue listing command.
- mailq_path: [/usr/bin/mailq]
- Please specify the destination directory for the Postfix on-line manual
- pages. You can no longer specify "no" here.
- manpage_directory: [/usr/local/man] /usr/local/postfix/man
- Please specify the final destination pathname for the installed Postfix
- newaliases command. This is the Sendmail-compatible command to build
- alias databases for the Postfix local delivery agent.
- newaliases_path: [/usr/bin/newaliases]
- Please specify the final destination directory for Postfix queues.
- queue_directory: [/var/spool/postfix] /usr/local/postfix/var/spool
- Please specify the destination directory for the Postfix README
- files. Specify "no" if you do not want to install these files.
- readme_directory: [no]
- Please specify the final destination pathname for the installed Postfix
- sendmail command. This is the Sendmail-compatible mail posting interface.
- sendmail_path: [/usr/sbin/sendmail]
- Please specify the group for mail submission and for queue management
- commands. Specify a group name with a numerical group ID that is
- not shared with other accounts, not even with the Postfix mail_owner
- account. You can no longer specify "no" here.
- setgid_group: [postdrop]
- 编译最后报错如下,找不到/etc/postfix/main.cf,后面通过软链接解决,这里直接无视!
- postfix: fatal: open /etc/postfix/main.cf: No such file or directory
- make: *** [install] Error 1
- 3:验证postfix是否支持sasl和mysql
- [root@orcl postfix-2.8.0]# ls /usr/local/postfix/
- etc libexec man sbin var
- [root@orcl postfix-2.8.0]# ls /usr/local/postfix/etc/
- access canonical LICENSE makedefs.out TLS_LICENSE
- aliases generic main.cf master.cf transport
- bounce.cf.default header_checks main.cf.default relocated virtual
- [root@orcl ~]# mv /etc/aliases /tmp/aliases.old
- [root@orcl ~]# ln -s /usr/local/postfix/etc/aliases /etc/
- [root@orcl ~]# /usr/bin/newaliases
- newaliases: fatal: open /etc/postfix/main.cf: No such file or directory
- [root@orcl ~]# ln -s /usr/local/postfix/etc/main.cf /etc/po
- [root@orcl ~]# mkdir /etc/postfix
- [root@orcl ~]# ln -s /usr/local/postfix/etc/main.cf /etc/postfix/
- [root@orcl ~]# /usr/bin/newaliases
- [root@orcl ~]# /usr/local/postfix/sbin/postconf -a
- cyrus
- dovecot
- [root@orcl ~]# /usr/local/postfix/sbin/postconf -m |grep mysql
- mysql
- 4.配置并启动postfix
- [root@orcl ~]# cp /usr/local/postfix/etc/main.cf /usr/local/postfix/etc/main.cf.orig
- [root@orcl ~]# cat /etc/postfix/main.cf
- ##====================MAIN========================
- myhostname = mail.yang.com
- mydomain = yang.com
- myorigin = $mydomain
- mydestination =
- inet_interfaces = all
- mynetworks = 192.168.227.0/24,192.168.123.0/24,127.0.0.0/8
- alias_maps = hash:/etc/aliases
- alias_database = hash:/etc/aliases
- queue_directory = /usr/local/postfix/var/spool
- command_directory = /usr/local/postfix/sbin
- daemon_directory = /usr/local/postfix/libexec
- sendmail_path = /usr/sbin/sendmail
- newaliases_path = /usr/bin/newaliases
- mailq_path = /usr/bin/mailq
- setgid_group = postdrop
- html_directory = no
- manpage_directory = /usr/local/postfix/man
- sample_directory = /usr/local/postfix/etc/
- readme_directory = no
- unknown_local_recipient_reject_code = 550
- ##====================SASL========================
- broken_sasl_auth_clients = yes
- smtpd_recipient_restrictions = permit_mynetworks,
- permit_sasl_authenticated,
- reject_invalid_hostname,
- reject_non_fqdn_hostname,
- reject_unknown_sender_domain,
- reject_non_fqdn_sender,
- reject_non_fqdn_recipient,
- reject_unknown_recipient_domain,
- reject_unauth_pipelining,
- reject_unauth_destination,
- permit
- smtpd_sasl_auth_enable = yes
- smtpd_sasl_local_domain = $myhostname
- smtpd_sasl_security_options = noanonymous
- smtpdsmtpd_sasl_application_name = smtpd
- smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
- ##================ Virtual Mailbox Settings =====================#
- virtual_mailbox_base = /email/mailbox
- virtual_mailbox_maps = mysql:/usr/local/postfix/etc/mysql_virtual_mailbox_maps.cf
- virtual_mailbox_domains = mysql:/usr/local/postfix/etc/mysql_virtual_domains_maps.cf
- virtual_alias_domains = virtual_alias_maps = mysql:/usr/local/postfix/etc/mysql_virtual_alias_maps.cf
- virtual_uid_maps = static:1001
- virtual_gid_maps = static:1001
- virtual_transport = maildrop
- maildrop_destination_recipient_limit = 1
- maildrop_destination_concurrency_limit = 1
- message_size_limit = 14336000
- virtual_mailbox_limit = 20971520
- virtual_create_maildirsize = yes
- virtual_mailbox_extended = yes
- virtual_mailbox_limit_maps = mysql:/usr/local/postfix/etc/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
- [root@orcl ~]# cat /usr/local/postfix/etc/mysql_virtual_domains_maps.cf
- user = extmail
- password = 123456
- hosts = localhost
- dbname = extmail
- table = domain
- select_field = description
- where_field = domain
- additional_conditions = AND active = '1'
- [root@orcl ~]# cat /usr/local/postfix/etc/mysql_virtual_mailbox_maps.cf
- user = extmail
- password = 123456
- hosts = localhost
- dbname = extmail
- table = mailbox
- select_field = maildir
- where_field = username
- additional_conditions = AND active = '1'
- [root@orcl ~]# cat /usr/local/postfix/etc/mysql_virtual_alias_maps.cf
- user = extmail
- password = 123456
- hosts = localhost
- dbname = extmail
- table = alias
- select_field = goto
- where_field = address
- additional_conditions = AND active = '1'
- [root@orcl ~]# cat /usr/local/postfix/etc/mysql_virtual_limit_maps.cf
- user = extmail
- password = 123456
- hosts = localhost
- dbname = extmail
- table = mailbox
- select_field = quota
- where_field = username
- additional_conditions = AND active = '1'
- [root@orcl ~]# /usr/local/postfix/sbin/postfix start
- postfix/postfix-script: fatal: no /etc/postfix/master.cf file found
- postfix/postfix-script: fatal: Postfix integrity check failed!
- [root@orcl ~]# ll /etc/postfix/main.cf
- [root@orcl ~]# ln -s /usr/local/postfix/etc/master.cf /etc/postfix/
- [root@orcl ~]# /usr/local/postfix/sbin/postfix start
- postfix/postfix-script: starting the Postfix mail system
- [root@orcl ~]# netstat -ntpl |grep :25
- tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 22089/master
五.安装Courier-IMAP
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# wget http://sourceforge.net/projects/courier/files/imap/4.9.3/courier-imap-4.9.3.tar.bz2/download
- [root@orcl tarbag]# tar -jxvf courier-imap-4.9.3.tar.bz2 -C ../software/
- [root@orcl tarbag]# cd ../software/courier-imap-4.9.3/
- [root@orcl courier-imap-4.9.3]# ./configure --prefix=/usr/local/courier-imap --with-redhat --enable-unicode --disable-root-check --with-trashquota --without-ipv6 CPPFLAGS='-I/usr/local/courier-authlib/include' COURIERAUTHCONFIG='/usr/local/courier-authlib/bin/courierauthconfig'
- [root@orcl courier-imap-4.9.3]# make && make install
- [root@orcl courier-imap-4.9.3]# cd /usr/local/courier-imap/etc
- [root@orcl etc]# cp imapd.dist imapd
- [root@orcl etc]# cp pop3d.dist pop3d
- [root@orcl etc]# cp imapd-ssl.dist imapd-ssl
- [root@orcl etc]# cp pop3d-ssl.dist pop3d-ssl
- [root@orcl etc]# egrep -i 'path|start' pop3d |grep -v '^#'
- POP3DSTART=YES
- MAILDIRPATH=/opt/mailbox
- [root@orcl etc]# egrep -i 'path|start' imapd |grep -v '^#'
- IMAPDSTART=YES
- MAILDIRPATH=/opt/mailbox
- [root@orcl etc]# cp /usr/local/src/software/courier-imap-4.9.3/courier-imap.sysvinit /etc/init.d/imapd
- [root@orcl etc]# chmod +x /etc/init.d/imapd
- [root@orcl etc]# chkconfig --add imapd
- [root@orcl etc]# service imapd start
- Starting Courier-IMAP server: imap pop3
- [root@orcl etc]# netstat -ntpl |egrep '110|143'
- tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 14416/couriertcpd
- tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 14410/couriertcpd
六: 安装maildrop
- [root@orcl etc]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# wget http://nchc.dl.sourceforge.net/project/courier/maildrop/2.5.4/maildrop-2.5.4.tar.bz2
- [root@orcl tarbag]# yum -y install pcre-devel
- [root@orcl tarbag]# tar -jxvf maildrop-2.5.4.tar.bz2 -C ../software/
- [root@orcl maildrop-2.5.4]# ./configure --enable-sendmail=/usr/sbin/sendmail --enable-trusted-users='root vmail' --enable-syslog=1 --enable-maildirquota --enable-maildrop-uid=1001 --enable-maildrop-gid=1001 --with-trashquota --with-dirsync
- [root@orcl maildrop-2.5.4]# make && make install
- [root@orcl maildrop-2.5.4]# maildrop -v
- maildrop 2.5.4 Copyright 1998-2005 Double Precision, Inc.
- GDBM/DB extensions enabled.
- Maildir quota extension are now always enabled.
- This program is distributed under the terms of the GNU General Public
- License. See COPYING for additional information.
- [root@orcl maildrop-2.5.4]# cat /etc/maildroprc //该文件默认不存在
- logfile "/var/log/maildrop.log"
- [root@orcl maildrop-2.5.4]# touch /var/log/maildrop.log
- [root@orcl maildrop-2.5.4]# chown vmail.vmail /var/log/maildrop.log
- 配置postfix支持maildrop
- [root@orcl ~]# grep -2 -i 'maildrop' /etc/postfix/master.cf |grep -v '^#'
- maildrop unix - n n - - pipe
- flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
- [root@orcl ~]# egrep '1001|maildrop' /etc/postfix/main.cf
- virtual_transport = maildrop
- virtual_uid_maps = static:1001
- virtual_gid_maps = static:1001
七:配置extman和extmail等
- 1:配置extman
- [root@orcl ~]# mkdir -p /email/mailbox
- [root@orcl ~]# chown -R vmail.vmail /email/mailbox/
- [root@orcl ~]# chown -R vmail.vmail /email/mailbox/
- [root@orcl tarbag]# tar -zxvf extman-1.1.tar.gz -C ../software/
- [root@orcl tarbag]# mv ../software/extman-1.1/ /www/extman
- [root@orcl tarbag]# mv /www/extman/webman.cf.default /opt/extman/webman.cf
- [root@orcl ~]# grep -v '^#' /www/extman/webman.cf |grep -v '^$'
- SYS_CONFIG = /www/extman/
- SYS_LANGDIR = /www/extman/lang
- SYS_TEMPLDIR = /www/extman/html
- SYS_MAILDIR_BASE = /email/mailbox
- SYS_SHOW_WARN = 0
- SYS_SESS_DIR = /tmp/extman/
- SYS_APP_TYPE = ExtMan
- SYS_TEMPLATE_NAME = default
- SYS_DEFAULT_EXPIRE = 1y
- SYS_GROUPMAIL_SENDER = postmaster@extmail.org
- SYS_DEFAULT_SERVICES = webmail,smtpd,smtp,pop3,netdisk
- SYS_BACKEND_TYPE = mysql
- SYS_CRYPT_TYPE = md5crypt
- SYS_MYSQL_USER = extmail
- SYS_MYSQL_PASS = 123456
- SYS_MYSQL_DB = extmail
- SYS_MYSQL_HOST = localhost
- SYS_MYSQL_SOCKET = /tmp/mysql.sock
- SYS_MYSQL_TABLE = manager
- SYS_MYSQL_ATTR_USERNAME = username
- SYS_MYSQL_ATTR_PASSWD = password
- SYS_LDAP_BASE = dc=extmail.org
- SYS_LDAP_RDN = cn=Manager,dc=extmail.org
- SYS_LDAP_PASS = secret
- SYS_LDAP_HOST = localhost
- SYS_LDAP_ATTR_USERNAME = mail
- SYS_LDAP_ATTR_PASSWD = userPassword
- [root@orcl tarbag]# mkdir /tmp/extman
- [root@orcl tarbag]# chown vmail.vmail /www/extman/
- [root@orcl tarbag]# chown vmail.vmail /tmp/extman/
- 2:配置extmail
- [root@orcl tarbag]# tar -zxvf extmail-1.2.tar.gz -C /www/
- [root@orcl tarbag]# mv /www/extmail-1.2/ /www/extmail
- [root@orcl ~]# cp /www/extmail/webmail.cf.default /www/extmail/webmail.cf
- [root@orcl ~]# grep -v '^#' /www/extmail/webmail.cf |grep -v '^$'
- SYS_CONFIG = /www/extmail/
- SYS_LANGDIR = /www/extmail/lang
- SYS_TEMPLDIR = /www/extmail/html
- SYS_HTTP_CACHE = 0
- SYS_SMTP_HOST = 127.0.0.1
- SYS_SMTP_PORT = 25
- SYS_LOG_FILE = /var/log/extmail.log
- SYS_SESS_TIMEOUT = 0
- SYS_SESS_COOKIE_ONLY = 1
- SYS_USER_PSIZE = 10
- SYS_USER_SCREEN = auto
- SYS_USER_LANG = en_US
- SYS_APP_TYPE = WebMail
- SYS_USER_TEMPLATE = default
- SYS_USER_CHARSET = utf-8
- SYS_AUTH_TYPE = mysql
- SYS_MAILDIR_BASE = /email/mailbox
- SYS_AUTH_SCHEMA = virtual
- SYS_CRYPT_TYPE = md5crypt
- SYS_MYSQL_USER = extmail
- SYS_MYSQL_PASS = 123456
- SYS_MYSQL_DB = extmail
- SYS_MYSQL_HOST = localhost
- SYS_MYSQL_SOCKET = /tmp/mysql.sock
- SYS_MYSQL_TABLE = mailbox
- SYS_MYSQL_ATTR_USERNAME = username
- SYS_MYSQL_ATTR_DOMAIN = domain
- SYS_MYSQL_ATTR_PASSWD = password
- SYS_MYSQL_ATTR_CLEARPW = clearpwd
- [root@orcl ~]# chown -R vmail.vmail /www/extmail/
- 3:导入数据库文件:
- [root@orcl ~]# cd /www/extman/docs/
- [root@orcl docs]# /usr/local/mysql/bin/mysql -u root -p < extmail.sql
- Enter password:
- [root@orcl docs]# /usr/local/mysql/bin/mysql -u root -p < init.sql
- Enter password:
- root@orcl docs]# /usr/local/mysql/bin/mysql
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 4
- Server version: 5.1.36-log Source distribution
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | aclocal |
- | extmail |
- | mysql |
- | test |
- +--------------------+
- 5 rows in set (0.04 sec)
- mysql> use extmail;
- Database changed
- mysql> show tables;
- +-------------------+
- | Tables_in_extmail |
- +-------------------+
- | alias |
- | domain |
- | domain_manager |
- | mailbox |
- | manager |
- +-------------------+
- 5 rows in set (0.01 sec)
- mysql> grant all privileges on extmail.* to extmail@'localhost' identified by '123456';
- Query OK, 0 rows affected (0.00 sec)
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
- 4:配置slockd
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# tar -zxvf slockd-0.99.tar.gz -C /usr/local/
- [root@orcl tarbag]# /usr/local/slockd/slockd-init start
- Starting spam locker daemon: slockd
- [root@orcl tarbag]# echo '/usr/local/slockd/slockd-init start' >> /etc/rc.local
- [root@orcl tarbag]# cd /var/run/
- [root@orcl run]# mkdir extmail
- [root@orcl run]# /www/extman/daemon/cmdserver -v -d
- loaded ok
- [root@orcl run]# echo '/www/extman/daemon/cmdserver -v -d' >> /etc/rc.local
八:配置apache
- [root@orcl ~]# grep 'vmail' /usr/local/apache2.2.16/conf/httpd.conf
- User vmail
- Group vmail
- <VirtualHost *:80>
- ServerName mail.yang.com
- DocumentRoot /www/extmail/html
- ScriptAlias /extmail/cgi /www/extmail/cgi
- Alias /extmail /www/extmail/html
- ScriptAlias /extman/cgi /www/extman/cgi
- Alias /extman /www/extman/html
- <Directory /www>
- Authtype basic
- Options execcgi
- Options Indexes FollowSymLinks
- AllowOverride None
- Order allow,deny
- Allow from all
- </Directory>
- </VirtualHost>
- [root@orcl ~]# /usr/local/apache2.2.16/bin/apachectl -t
- Syntax OK
- [root@orcl ~]# /usr/local/apache2.2.16/bin/apachectl -k restart
九:测试和排错, extman默认管理帐号为:[email protected] 密码为:extmail*123*
- 1:安装GD,若未安装,则会出现验证码无法正常显示
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# tar -zxvf GD-2.35.tar.gz -C ../software/
- [root@orcl tarbag]# cd ../software/GD-2.35/
- [root@orcl GD-2.35]# perl Makefile.PL
- [root@orcl GD-2.35]# make && make install
2:出现下图中的情况,需要重新安装前面卸载掉的db4和db4-devel
[root@orcl ~]# yum -y install db4 db4-devel
3:出现下图中的情况,需要安装UNix-syslog
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# gzip -d Unix-Syslog-1.1.tar.gz
- [root@orcl tarbag]# tar -xvf Unix-Syslog-1.1.tar -C ../software/
- [root@orcl tarbag]# cd ../software/Unix-Syslog-1.1/
- [root@orcl Unix-Syslog-1.1]# ls
- Artistic Changes Makefile.PL MANIFEST META.yml README Syslog.pm Syslog.xs test.pl
- [root@orcl Unix-Syslog-1.1]# perl Makefile.PL
- Checking if your kit is complete...
- Looks good
- Writing Makefile for Unix::Syslog
- [root@orcl Unix-Syslog-1.1]# make && make install
4:新建邮件域,登陆出错
安装perl-DBD-MySQL后重新登陆
[root@orcl ~]# yum -y install perl-DBD-MySQL
5: 发信测试
- [root@orcl ~]# tail -f /var/log/maillog
- Sep 5 16:05:31 orcl extmail[12523]: user=<admin@yang.com>, client=192.168.227.1, module=login, status=loginok
- Sep 5 16:06:29 orcl postfix/smtpd[12555]: connect from localhost.localdomain[127.0.0.1]
- Sep 5 16:06:29 orcl postfix/smtpd[12555]: B842123EFB4: client=localhost.localdomain[127.0.0.1]
- Sep 5 16:06:29 orcl postfix/cleanup[12560]: B842123EFB4: message-id=<20110905080629.B842123EFB4@mail.yang.com>
- Sep 5 16:06:29 orcl postfix/smtpd[12555]: disconnect from localhost.localdomain[127.0.0.1]
- Sep 5 16:06:29 orcl postfix/qmgr[12286]: B842123EFB4: from=<admin@yang.com>, size=615, nrcpt=1 (queue active)
- Sep 5 16:06:31 orcl postfix/smtp[12561]: B842123EFB4: to=<ylw6006@163.com>, relay=163mx03.mxmail.netease.com[123.125.50.140]:25, delay=2.2, delays=0.07/0/1.2/0.94, dsn=2.0.0, status=sent (250 Mail OK queued as mx47,XcCowGBps0bRgmROKP+GAw--.907S2 1315209938)
- Sep 5 16:06:32 orcl postfix/qmgr[12286]: B842123EFB4: removed
6:extman日志分析
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.5.tar.gz
- [root@orcl tarbag]# tar -zxvf rrdtool-1.4.5.tar.gz -C ../software/
- [root@orcl tarbag]# cd ../software/rrdtool-1.4.5/
- [root@orcl rrdtool-1.4.5]# ./configure --prefix=/usr/local/rrdtool
- [root@orcl rrdtool-1.4.5]# make && make install
- [root@orcl ~]# ln -s /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/auto/RRDs/RRDs.so /usr/lib/perl5/5.8.8/i386-linux-thread-multi/
- [root@orcl ~]# ln -s /usr/local/rrdtool/lib/perl/5.8.8/RRDp.pm /usr/lib/perl5/5.8.8/
- [root@orcl ~]# ln -s /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/RRDs.pm /usr/lib/perl5/5.8.8/
- [root@orcl ~]# cp -r /www/extman/addon/mailgraph_ext/ /usr/local/
- [root@orcl ~]# /usr/local/mailgraph_ext/mailgraph-init start
- Starting mail statistics grapher: mailgraph_ext
- Can't locate File/Tail.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/mailgraph_ext/mailgraph_ext.pl line 296.
- BEGIN failed--compilation aborted at /usr/local/mailgraph_ext/mailgraph_ext.pl line 296.
- Starting queue statistics grapher: qmonitor
- [root@orcl ~]# cpan
- cpan> install File::Tail
- cpan>quit
- [root@orcl ~]# /usr/local/mailgraph_ext/mailgraph-init start
- Starting mail statistics grapher: mailgraph_ext
- Starting queue statistics grapher: qmonitor
- [root@orcl ~]# echo '/usr/local/mailgraph_ext/mailgraph-init start' >> /etc/rc.local
十:增加FCGI支持,主要是为了获得优异的web效能
1:安装mod_fastcgi模块
- [root@orcl ~]# cd /usr/local/src/tarbag/
- [root@orcl tarbag]# wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
- [root@orcl tarbag]# tar -zxvf mod_fastcgi-2.4.6.tar.gz -C ../software/
- [root@orcl tarbag]# cd ../software/mod_fastcgi-2.4.6/
- [root@orcl mod_fastcgi-2.4.6]# cp Makefile.AP2 Makefile
- [root@orcl mod_fastcgi-2.4.6]# make top_dir=/usr/local/apache2.2.16/ install
- [root@orcl mod_fastcgi-2.4.6]# ls /usr/local/apache2.2.16/modules/mod_fastcgi.so
- /usr/local/apache2.2.16/modules/mod_fastcgi.so
2:安装perl-FCGI模块,使extmail支持fastcgi
- [root@orcl ~]# rpm -ivh http://ftp.belnet.be/packages/dries.ulyssis.org/redhat/el5/en/i386/RPMS.dries/perl-FCGI-0.67-1.2.el5.rf.i386.rpm //32位系统
- [root@orcl ~]# rpm -ivh http://ftp.belnet.be/packages/dries.ulyssis.org/redhat/el5/en/x86_64/RPMS.dries/perl-FCGI-0.67-1.2.el5.rf.x86_64.rpm //64位系统
3:配置apache,extmail支持fastcgi
- [root@orcl ~]# egrep 'fast|9000' /usr/local/apache2.2.16/conf/httpd.conf
- LoadModule fastcgi_module modules/mod_fastcgi.so
- <Ifmodule mod_fastcgi.c>
- FastCgiExternalServer /var/www/extsuite/extmail/dispatch.fcgi -host 127.0.0.1:8888
- </Ifmodule>
- [root@orcl ~]# vi /usr/local/apache2.2.16/conf/extra/httpd-vhosts.conf
- <VirtualHost *:80>
- ServerName mail.yang.com
- DocumentRoot /www/extmail/html
- ScriptAlias /extmail/cgi /www/extmail/dispatch.fcgi
- Alias /extmail /www/extmail/html
- ScriptAlias /extman/cgi /www/extmail/dispatch.fcgi
- Alias /extman /www/extman/html
- <Location "/extman/cgi">
- SetHandler fastcgi-script
- </Location>
- <Directory /www>
- Authtype basic
- Options execcgi
- Options Indexes FollowSymLinks
- AllowOverride None
- Order allow,deny
- Allow from all
- </Directory>
- </VirtualHost>
- [root@orcl ~]# egrep 'vmail|www|9000' /www/extmail/dispatch-init
- PORT=9000
- SU_UID=vmail
- SU_GID=vmail
- BASE=/www/extmail
4:启动fastcgi server
- [root@orcl ~]# /www/extmail/dispatch-init start
- Starting extmail FCGI server...
- [root@orcl ~]# ps -ef |grep dispatch
- vmail 23661 1 0 09:43 ? 00:00:00 dispatch.fcgi (master)
- vmail 23662 23661 0 09:43 ? 00:00:00 dispatch.fcgi (idle)
- vmail 23663 23661 0 09:43 ? 00:00:00 dispatch.fcgi (idle)
- root 23680 12093 0 09:43 pts/3 00:00:00 grep dispatch
- [root@orcl ~]# netstat -ntpl |grep :9000
- tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 23811/dispatch.fcgi
- [root@orcl ~]# echo '/www/extmail/dispatch-init start' >> /etc/rc.local
5:重启apache
- [root@orcl ~]# /usr/local/apache2.2.16/bin/apachectl -t
- Syntax OK
- [root@orcl ~]# /usr/local/apache2.2.16/bin/apachectl -k restart
备注:本文的安装过程非常繁琐,需要用到的软件也很多,因而在本文中没有提供下载地址的软件将会统一打包放在附件中,后期会重点研究下垃圾邮件过滤和邮件病毒的查杀;另外,本文参考了胡双峰同学写的博文,在此深表感谢,双峰同学博客地址:http://blog.csdn.net/deccmtd/
本文出自 “斩月” 博客,谢绝转载!