在RHEL5.3上安装基于postfix的extmail邮件系统

extmail官方网站上的安装指南是针对4.x系统的,网上找了一个5.x的安装。
参考在centos/redhat 5.x 上安装邮件系统postfix+extmail+courier-imap

安装步骤.

1.系统准备

使用默认方式安装系统后,从RHEL安装盘上拷贝一些下面安装步骤需要的rpm包先安装上。

  1. rpm -ivh postgresql-devel-8.1.11-1.el5_1.1.i386.rpm
  2. rpm -ivh expect-5.43.0-5.1.i386.rpm
  3. rpm -ivh libtool-ltdl-devel-1.5.22-6.1.i386.rpm
  4.  
  5. rpm -ivh mysql-devel-5.0.45-7.el5.i386.rpm
  6. rpm -ivh openldap-servers-2.3.43-3.el5.i386.rpm
  7. rpm -ivh openldap-servers-sql-2.3.43-3.el5.i386.rpm
  8.  
  9. rpm -ivh pcre-6.6-2.el5_1.7.i386.rpm
  10. rpm -ivh pcre-devel-6.6-2.el5_1.7.i386.rpm

再从 www.extmail.org 网站上下载最新的 extmail 相关包

extmail-1.1.0.tar.gz
extman-1.0.0.tar.gz
slockd-0.99.tar.gz

2.导入extman后台数据库数据

  1. tar -xzvf extman-1.0.0.tar.gz
  2. cd extman-1.0.0/docs
  3. mysql -u root -p
  4. mysql> source extmail.sql
  5. mysql> source init.sql
  6. mysql> exit

3.准备rpm环境变量

按照参考文档,采用rpm方式安装,首先设置环境变量,方便后面操作的目录切换。

  1. export rpms=/usr/src/redhat/RPMS
  2. export source=/usr/src/redhat/SOURCES
  3. export spec=/usr/src/redhat/SPECS

4.安装authlib

a.下载源码包

  1. wget http://prdownloads.sourceforge.net/courier/courier-authlib-0.61.0.tar.bz2
  2. tar -xjf courier-authlib-0.61.0.tar.gz2
  3. cd courier-authlib-0.61.0
  4. cp courier-authlib.spc $spec
  5. cd ..
  6. cp courier-authlib-0.61.0.tar.gz2 $source
  7. cd $spec
  8. rpmbuild -bb courier-authlib.spec

b.安装生成的rpm

  1. cd $rpms/i386
  2. rpm -ivh courier-authlib-0.61.0-1.i386.rpm
  3. rpm -ivh courier-authlib-devel-0.61.0-1.i386.rpm
  4. rpm -ivh courier-authlib-mysql-0.61.0-1.i386.rpm

c.配置authlibdaemon

  1. cd /etc/authlib
  2. mv authdaemonrc authdaemonrc.bak
  3. vi authdaemonrc

输入以下内容

authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
authdaemonvar=/var/spool/authdaemon
debug_login=2
defaultoptions="wbnodsn=1"
loggeropts=""

d.配置authmysqlrc

  1. mv authmysqlrc authmysqlrc.bak
  2. vi authmysqlrc

输入以下内容

MYSQL_SERVER            localhost
MYSQL_USERNAME          extmail
MYSQL_PASSWORD          extmail
MYSQL_SOCKET            /var/lib/mysql/mysql.sock
MYSQL_PORT              3306
MYSQL_OPT               0
MYSQL_DATABASE          extmail
MYSQL_USER_TABLE        mailbox
MYSQL_CRYPT_PWFIELD     password
MYSQL_UID_FIELD         uidnumber
MYSQL_GID_FIELD         gidnumber
MYSQL_LOGIN_FIELD       username
MYSQL_HOME_FIELD        homedir
MYSQL_NAME_FIELD        name
MYSQL_MAILDIR_FIELD     maildir
MYSQL_QUOTA_FIELD       quota
MYSQL_SELECT_CLAUSE     SELECT username,password,"",uidnumber,gidnumber,\
                        CONCAT('/var/maildata/domains/',homedir),               \
                        CONCAT('/var/maildata/domains/',maildir),               \
                        quota,                                          \
                        name                                            \
                        FROM mailbox                                    \
                        WHERE username = '$(local_part)@$(domain)'

e.启动authlib

  1. service courier-authlib start
  2. chmod 777 /var/spool/authdaemon/

5.安装courier-imap

不能使用root身份生成rpm,需要建立一个新的普通账号。

  1. useradd tmpusr

软件包依赖需要openldap-server,我们在前面已经准备好(rpm创建好后可以删除)
建立需要的目录和设置环境变量

  1. su – tmpusr
  2. mkdir -p rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
  3. vi ~/.rpmmacros

输入如下内容

%_topdir /home/tmpusr/rpm

获取源码包

  1. wget http://prdownloads.sourceforge.net/courier/courier-imap-4.4.1.tar.bz2
  2. cp courier-imap-4.4.1.tar.bz2 rpm/SOURCES/
  3. tar -xjf courier-imap-4.4.1.tar.bz2
  4. cd courier-imap-4.4.1
  5. cp courier-imap.spec ../rpm/SPECS/
  6. cd ../rpm/SPECS/

编辑courier-imap.spec文件,将下面内容作修改

%if %suse_version
BuildPreReq: rpm >= 3.0.5 /usr/bin/sed openldap2 openldap2-devel %([ %{suse_version} -gt 819 ]
&& echo /usr/include/fam.h)
%else
BuildPreReq: rpm >= 4.0.2 sed /usr/include/fam.h openldap-devel openldap-servers
%endif

修改为

%if %suse_version
BuildPreReq: rpm >= 3.0.5 /usr/bin/sed openldap2 openldap2-devel
%else
BuildPreReq: rpm >= 4.0.2 sed openldap-devel openldap-servers
%endif

创建rpm,并使用exit退出当前用户

  1. rpmbuild -bb courier-imap.spec
  2. exit

安装生成好的rpm,并运行服务

  1. rpm -ivh /home/tmpusr/rpm/RPMS/i386/courier-imap-4.4.1-1.i386.rpm
  2. service courier-imap start

6.安装cyrus-sasl

a.安装srpm

  1. wget ftp://194.199.20.114/linux/fedora/updates/8/SRPMS/cyrus-sasl-2.1.22-8.fc8.src.rpm
  2. rpm -ivh cyrus-sasl-2.1.22-8.fc8.src.rpm
  3. cd $spec

编辑cyrus-sasl.spec 将下面:

# bundling copy of berkeley db, for sasldb support.
topdir=`pwd`
pushd db-%{db_version}/build_unix
../dist/configure \r
        --with-mutex=unix/fcntl --disable-shared --enable-static --with-pic \
        --with-uniquename=_cyrus_sasl_sasldb_rh \
        --prefix=${topdir}/db-instroot \
        --includedir=${topdir}/db-instroot/include \
        --libdir=${topdir}/db-instroot/lib

改为:

# bundling copy of berkeley db, for sasldb support.
topdir=`pwd`
pushd db-%{db_version}/build_unix
../dist/configure \r
        --with-mutex=unix/fcntl --disable-shared --enable-static --with-pic \
        --with-uniquename=_cyrus_sasl_sasldb_rh \
        --prefix=${topdir}/db-instroot \
        --includedir=${topdir}/db-instroot/include \
        --libdir=${topdir}/db-instroot/lib \
        --with-authdaemond=/var/spool/authdaemon

b、生成rpm并做安装

  1. rpmbuild -bb cyrus-sasl.spec
  2. cd $rpms/i386
  3. rpm -e –nodeps cyrus-sasl-devel cyrus-sasl-plain cyrus-sasl cyrus-sasl-lib (如果这些包存在,先卸载)
  4. rpm -ihv cyrus-sasl-lib-2.1.22-8.i386.rpm
  5. rpm -ihv cyrus-sasl-2.1.22-8.i386.rpm
  6. rpm -ihv cyrus-sasl-plain-2.1.22-8.i386.rpm

c、配置sasl2

创建/usr/lib/sasl2/smtpd.conf 文件,输入下面的内容:

pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/var/spool/authdaemon/socket

7.安装postfix

a、下载软件包

  1. cd ~
  2. wget http://ftp.wl0.org/official/2.5/SRPMS/postfix-2.5.4-2.src.rpm
  3. rpm -ivh postfix-2.5.4-2.src.rpm
  4. cd $spec

编辑postfix.spec 修改下面的选项

%define distribution rhel-5.0
%define with_mysql_redhat 1
%define with_sasl         2
%define with_vda          1

b、创建rpm并做安装

  1. rpmbuild -bb postfix.spec
  2. cd $rpms/i386
  3. rpm -ivh postfix-2.5.4-2.rhel4.i386.rpm

c、切换mta

  1. alternatives –config mta (选择2,postfix)
  2. rpm -e sendmail
  3. cd /usr/sbin/
  4. mv sendmail sendmail.bak
  5. newaliases
  6. ln -s sendmail.postfix sendmail

d、配置postfix

cd /etc/postfix/
mv main.cf main.cf.bak
vi main.cf

输入下面的内容:

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
unknown_local_recipient_reject_code = 550
debug_peer_level = 2
debugger_command =
         path=/bin:/usr/bin:/usr/local/bin:/usr/x11r6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = /usr/share/doc/postfix-2.5.2-documentation/html
manpage_directory = /usr/share/man
sample_directory = /etc/postfix
readme_directory = /usr/share/doc/postfix-2.5.2-documentation/readme
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
myhostname = mail.mymailserver.org
mydomain = mymailserver.org
mydestination = $myhostname
smtpd_banner = mymailserver.org esmtp mail system

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_base = /var/maildata/domains
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf
virtual_transport = maildrop:
maildrop_destination_recipient_limit = 1

#sasl
smtpd_sasl_auth_enable = yes
smtpd_sasl2_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes

# smtpd related config
smtpd_recipient_restrictions =
    permit_mynetworks,
	permit_sasl_authenticated,
	reject_non_fqdn_hostname,
	reject_non_fqdn_sender,
	reject_non_fqdn_recipient,
	reject_unauth_destination,
	reject_unauth_pipelining,
	reject_invalid_hostname

可以将如上最后一段替换成如下:对邮件收发进-不控制:

---------------------------------------------------
#setting by king
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

复制extman/docs 目录的mysql_virtual_*.cf 文件到/etc/postfix

  1. cp /root/ExtSuite/extman-1.0.0/docs/mysql_virtual_* .

因为配置文件的用户、密码与数据库时1样,所以不用修改.

  1. service postfix start

8.安装maildrop

a.下载生成rpm

  1. cd ~
  2. wget http://prdownloads.sourceforge.net/courier/maildrop-2.0.4.tar.bz2
  3. cp maildrop-2.0.4.tar.bz2 $source
  4. tar xjf maildrop-2.0.4.tar.bz2
  5. cd maildrop-2.0.4
  6. cp maildrop.spec $spec
  7. cd $spec

编辑maildrop.spec 把下面:

BuildRequires: /usr/include/fam.h gdbm-devel pcre-devel

改为:

BuildRequires:  gdbm-devel pcre-devel

把下面:

%configure --with-devel --enable-userdb --enable-maildirquota  \
--enable-syslog=1 --enable-trusted-users='root mail daemon postmaster qmaild mmdf' \
--enable-restrict-trusted=0 \r
--enable-sendmail=/usr/sbin/sendmail

改为:

%configure --with-devel --enable-userdb --enable-maildirquota \
--enable-syslog=1 --enable-trusted-users='root mail daemon postmaster qmaild mmdf' \
--enable-restrict-trusted=0 --enable-sendmail=/usr/sbin/sendmail \
--enable-authlib

说明:如果tail -f /var/log/maillog 提示“maildrop: maildir over quota”,可以将

“--enable-maildirquota ”配置选项清除,既可以解决maildrp 误报“maildir over quota”错误.

b.创建maildrop rpm并安装

  1. rpmbuild -bb maildrop.spec
  2. cd $rpms/i386
  3. rpm -ivh maildrop-2.0.4-1.i386.rpm
  4. rpm -ivh maildrop-devel-2.0.4-1.i386.rpm

c.添加虚似用户及创建目录

  1. cd ~
  2. groupadd -g 1000 vgroup
  3. useradd -g 1000 -u 1000 -s /sbin/nologin -d /dev/null vuser

编辑/etc/postfix/master.cf ,加入下面的内容:

maildrop unix -     n     n     -     -     pipe
 flags=DRhu user=vuser argv=/usr/bin/maildrop -d ${user}@${nexthop} ${recipient} ${user} ${extension} ${nexthop}

或者:

---------------------------------------
maildrop   unix        -       n        n        -        -        pipe
    flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user}
${extension} {nexthop}

或者:

------------------------------------------------
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vuser argv=/usr/bin/maildrop -d ${recipient}

或者:

-------------------------------------------------
#maildrop unix -     n     n     -     -     pipe
# flags=DRhu user=vuser argv=/usr/bin/maildrop -d ${user}@${nexthop} ${recipient}
${user} ${extension} ${nexthop}

d.创建邮件存储目录

  1. mkdir -p /var/maildata/domains/extmail.org/postmaster
  2. maildirmake /var/maildata/domains/extmail.org/postmaster/Maildir
  3. chown -R vuser:vgroup /var/maildata/domains/

e.测试maildrop

  1. echo "test" | maildrop -v 10 -d postmaster@extmail.org

显示出

maildrop: authlib: groupid=1000
maildrop: authlib: userid=1000
maildrop: authlib: logname=postmaster@extmail.org, home=/var/maildata/domains/extmail.org/postmaster, mail=/var/maildata/domains/extmail.org/postmaster/maildir/
maildrop: changing to /var/maildata/domains/extmail.org/postmaster
message start at 0 bytes, envelope sender=postmaster@extmail.org
maildrop: attempting .mailfilter
maildrop: delivery complete.
出现上以信息说明authlib,maildrop 工作正常

f.测试pop3

  1. [root@localhost ~]# telnet localhost 110
显示出如下信息作操作
trying 127.0.0.1...
connected to localhost.localdomain (127.0.0.1).
escape character is '^]'.
+ok hello there.
user postmaster@extmail.org
+ok password required.
pass extmail
+ok logged in.
list
+ok pop3 clients that break here, they violate std53.
1 6
.
retr 1
+ok 6 octets follow.
test
.
quit
+ok bye-bye.
connection closed by foreign host.

g.测试postfix

  1. [root@localhost ~]# perl -e 'use MIME::Base64; print encode_base64("postmaster\@extmail.org")'
  2. cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
  3. [root@localhost ~]# perl -e 'use MIME::Base64; print encode_base64("extmail")'              
  4. ZXh0bWFpbA==
  5. [root@localhost ~]# service postfix restart (重启1下)
  6. [root@localhost ~]# telnet localhost 25
  7. trying 127.0.0.1...
  8. connected to localhost.localdomain (127.0.0.1).
  9. escape character is '^]'.
  10. 220 mymailserver.org esmtp mail system
  11. ehlo test.com
  12. 250-mail.mymailserver.org
  13. 250-PIPELINING
  14. 250-SIZE 10240000
  15. 250-VRFY
  16. 250-ETRN
  17. 250-AUTH LOGIN PLAIN
  18. 250-AUTH=LOGIN PLAIN
  19. 250-ENHANCEDSTATUSCODES
  20. 250-8BITMIME
  21. 250 DSN
  22. auth login
  23. 334 VXNlcm5hbWU6
  24. cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
  25. 334 UGFzc3dvcmQ6
  26. ZXh0bWFpbA==
  27. 235 2.0.0 Authentication successful
  28. quit
  29. 221 2.0.0 Bye
  30. Connection closed by foreign host.

9.安装extmail

a.拷贝extmail目录

  1. [root@localhost ~]# mkdir /var/www/extsuite
  2. [root@localhost ~]# cp -r extmail-1.1.0 /var/www/extsuite/extmail
  3. [root@localhost ~]# cp -r extman-1.0.0 /var/www/extsuite/extman

b、配置extmail参数

  1. [root@localhost ~]# cd /var/www/extsuite/extmail/
  2. [root@localhost extmail]# cp webmail.cf.default webmail.cf

修改webmail.cf 下面的选项

  1. sys_sess_dir = /tmp/extmail
  2. sys_maildir_base = /var/maildata/domains
  3. sys_mysql_user = extmail
  4. sys_mysql_pass = extmail

c、配置extman参数

[root@localhost extmail]# cd /var/www/extsuite/extman/

修改webman.cf 下面的选项:

  1. sys_maildir_base = /var/maildata/domains

d、创建session 目录

  1. [root@localhost extman]# mkdir /tmp/{extman,extmail}
  2. [root@localhost extman]# chown vuser:vgroup /tmp/ext*

e、在nginx服务器上做虚拟机配置

修改nginx.conf 添加extmail的目录设置

     server
     {
             listen       80;
             server_name  mail.mymailserver.org
             index index.html index.htm index.cgi;
             root /var/www/extsuite/extmail/html/;

            location /extmail/cgi/ {
               fastcgi_param  SCRIPT_FILENAME   /var/www/extsuite$fastcgi_script_name;
               include               perl.conf;
            }

            location  /extmail/  {
               alias  /var/www/extsuite/extmail/html/;
            }

           location /extman/cgi/ {
             fastcgi_param  SCRIPT_FILENAME   /var/www/extsuite/$fastcgi_script_name;
             include            perl.conf;
           }
           location /extman/ {
             alias  /var/www/extsuite/extman/html/;
           }
   }

perl.conf内容

fastcgi_pass unix:/tmp/perl_fcgi.socket;
#fastcgi_pass 127.0.0.1:8888
fastcgi_index index.cgi;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_read_timeout 60;

perl的fastcgi配置参考前面写的为了Awstats给Nginx添加FastCGI方式的Perl支持 也可以使用extmail包中附带的 dispatch.fcgi

  1. /var/www/extsuite/extmail/dispatch.fcgi --port=8888 --child=4 --server \
  2.         --uid=vuser --gid=vgroup --pid=/var/run/dispatch.fcgi.pid \
  3.         --request=50 --timeout=120

f、访问extmail/extman

打开浏览器,输入http://your_ip_address/extmail 注意:your_ip_address 为你实际的ip
第1个测试用户为:postmaster 密码:extmail 域:extmail, 登陆以后修改密码做测试。

打开浏览器,输入http://your_ip_address/extman
extman的默认 root 用户为:root@extmail.org 密码为:extmail*123*
进入系统后首先修改密码,然后做系统的设置.

Popularity: 13% [?]

Related

Comments

2 Responses to “在RHEL5.3上安装基于postfix的extmail邮件系统”

  1. goovo on November 24th, 2009 7:55 pm

    [root@localhost init.d]# echo “test” | maildrop -v 10 -d postmaster@extmail.org
    maildrop 2.0.4 Copyright 1998-2005 Double Precision, Inc.
    GDBM extensions enabled.
    Courier Authentication Library extension enabled.
    Maildir quota extension enabled.
    This program is distributed under the terms of the GNU General Public
    License. See COPYING for additional information.
    -bash: echo: write error: 断开的管道

    我每次到这步都提示这个的错误。郁闷,找了好多资料都解决不了。兄台可否指导一下?谢谢!
    (我用的系统是 centos5.3)

    [Reply]

    dvd Reply:

    echo “test” | maildrop -V 10 -d postmaster@extmail.org
    引号改成英文格式的

    [Reply]