|
8.2. 编译与安装
编译Cyrus-IMAP,并取消kerberos支持(在Redhat中,kerberos库有问题,很难编译通过,Mandrake则可以 通过;此外,我们也不需要kerberos的支持;如果通不过,就指定kerberos的位置--with-krb=/usr/kerberos)和 snmp的支持:
[root@mail src]# tar -zxf cyrus-imapd-2.1.15.tar.gz
[root@mail src]# cd cyrus-imapd-2.1.15
[root@mail cyrus-imapd-2.1.15]# ./configure --with-cyrus-prefix=/usr/cyrus \
> --with-sasl=/usr/local/lib/sasl2 --with-auth=unix \
> --without-ucdsnmp --with-krb=/usr/kerberos
[root@mail cyrus-imapd-2.1.15]# make depend
[root@mail cyrus-imapd-2.1.15]# make all CFLAGS=-O
[root@mail cyrus-imapd-2.1.15]# make install
如果编译时提示没有找到com_err.h,请复制当前目录的et目录下面的com_err.h到/usr/include:
[root@mail cyrus-imapd-2.1.15]# cp et/com_err.h /usr/include
Cyrus-IMAP的安装脚本有问题,cyradm(现在使用的是Perl版本,原来的TCL版本不再支持)所需要的perl模块被安装到一些不在Perl的@INC的目录里,需要手工安装。
[root@mail cyrus-imapd-2.1.15]# cd perl/imap
[root@mail imap]# perl Makefile.PL
[root@mail imap]# make install
8.3. 配置
创建主配置文件/etc/cyrus.conf:
[root@mail imap]# cd ../..
[root@mail cyrus-imapd-2.1.15]# cp master/conf/small.conf /etc/cyrus.conf
添加cyrus-imap的管理账号cyrus,并设置密码为“cyrus”(实际应用总可以使用更加复杂的密码),但是没有指定有效的SHELL,以防止使用它来登录:
[root@mail cyrus-imapd-2.1.15]# useradd -g mail -M -s/no/shell cyrus
[root@mail cyrus-imapd-2.1.15]# passwd cyrus
Changing password for user cyrus
New password: cyrus
BAD PASSWORD: it it too short
Retype new password: cyrus
passwd: all authentocation tokens updated successfully
创建IMAP配置文件/etc/imapd.conf,管理员是cyrus:
[root@mail cyrus-imapd-2.1.15]# vi /etc/imapd.conf
configdirectory: /var/imap
partition-default: /var/spool/imap
admins: cyrus
sasl_pwcheck_method: saslauthd
sasl_mech_list: PLAIN
unixhierarchysep: yes
altnamespace: yes
在/etc/imapd.conf中使用了unixhierarchysep: yes的配置可以创建带“.”的邮箱。关于imapd.conf可以参阅Cyrus-IMAP的文档来配置其他可用的参数。
建立Cyrus-IMAP服务器的目录结构:
[root@mail cyrus-imapd-2.1.15]# mkdir -p /var/imap/sieve
[root@mail cyrus-imapd-2.1.15]# mkdir /var/spool/imap
[root@mail cyrus-imapd-2.1.15]# chown -R cyrus:mail /var/imap
[root@mail cyrus-imapd-2.1.15]# chown -R cyrus:mail /var/spool/imap
[root@mail cyrus-imapd-2.1.15]# su -s/bin/bash cyrus
bash-2.05$ tools/mkimap
bash-2.05$ exit
这里tools/mkimap这个实用程序在cyrus-imap的源程序目录里面。
创建日志:
[root@mail cyrus-imapd-2.1.15]# echo local6.debug /var/log/imapd.log >> /etc/syslog.conf
[root@mail cyrus-imapd-2.1.15]# echo auth.debug /var/log/auth.log >> /etc/syslog.conf
[root@mail cyrus-imapd-2.1.15]# /etc/rc.d/init.d/syslog restart
设置邮件限额:
[root@mail cyrus-imapd-2.1.15]# chattr -R +S /var/imap/user
[root@mail cyrus-imapd-2.1.15]# chattr -R +S /var/imap/quota
[root@mail cyrus-imapd-2.1.15]# chattr -R +S /var/spool/imap
由于Cyrus-IMAP的主控进程和Postfix的主控进程名字一样,容易混淆而且不方便控制,所以将Cyrus-IMAP服务器的主控进程做个别名连接:cyrusd。
[root@mail cyrus-imapd-2.1.15]# cd /usr/cyrus/bin
[root@mail bin]# ln -s master cyrusd
8.4. 运行
启动命令如下:
[root@mail bin]# /usr/cyrus/bin/cyrusd&
8.5. 测试Cyrus-IMAP
启动Cyrus-IMAP后,首先检查日志/var/log/messages、/var/log/imapd.log和/var/log/auth.log有无错误信息,然后检查进程,应该有如下进程存在:
[root@mail bin]# pstree |grep cyrusd
|-cyrusd
接着检查端口,应该有如下端口打开:
[root@mail bin]# netstat -an |grep LISTEN
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN
现在创建邮箱。
使用cyradm来创建和删除邮箱,它是Cyrus-IMAP自己带的交互式管理界面,现在的版本是用Perl写的。你也可以直接调用 Cyrus::IMAP::Admin模块创建自己的CGI或脚本来做邮箱管理,可以参考Cyrus::IMAP::Shell模块的程序。
为了支持虚拟域,我们采用了特定的用户邮箱名,用户的邮箱名与其邮件地址的全称很类似,只是将其中的“@”换成了“~”。这是由于,为了将虚拟 域用户区别开来,我们希望使用用户的邮件全称来做它的邮箱名(其POP3/IMAP的登录名和邮箱名是一样的),但是虽然Cyrus-IMAP允许你创建 带有“@”的邮箱,不过Postfix/smtpd却不支持邮件的本地部分含有@,它会在递交到Cyrus-IMAP的邮箱时,将“@”后面的部分作为域 来处理,以至于不能正常递交。
作为一个变通的方法,我们创建一个将用户邮件地址中的“@”换成“~”的邮箱,并使Postfix/smtpd通过FORWARD重写来递交到 这里。首先在cyradm中创建两个信箱,分别是用“@”和“~”分隔的信箱名;然后在文件系统中删除分隔符为“@”的那个信箱目录,并给分隔符为“~” 的信箱做个分隔符为“@”的符号链接。(之所以先在cyradm中创建分隔符为“@”的信箱然后在文件系统中删除,是为了让cyrus-imap知道有这 样一个信箱。另外请注意,信箱名称中的点实际是用“^”代表的)
[root@mail bin]# cyradm --user cyrus localhost
IMAP Password:
mail.cngnu.org> cm user/cyrus
mail.cngnu.org> sq user/cyrus STORAGE 10240000
mail.cngnu.org> cm user/tester~cngnu.org
mail.cngnu.org> cm user/tester@cngnu.org
mail.cngnu.org> sq user/tester~cngnu.org STORAGE 10240000
mail.cngnu.org> lm
user/cyrus (HasNoChildren) user/tester~cngnu.org (HasNoChildren)
user/tester@cngnu.org (HasNoChildren)
mail.cngnu.org> quit
[root@mail bin]# cd /var/spool/imap/user
[root@mail user]# ls
cyrus tester~cngnu^org tester@cngnu^org
[root@mail user]# rm -rf tester@cngnu^org
[root@mail user]# ln -s tester~cngnu^org tester@cngnu^org
[root@mail user]# cd -
如果要删除一个IMAP邮箱,需要先给管理员cyrus授予C(Create)和D(Delete)的权限才可以删除。
[root@mail bin]# cyradm --user cyrus localhost
IMAP Password:
mail.cngnu.org> cm user/testdel
mail.cngnu.org> lm
user/cyrus (HasNoChildren) user/tester~cngnu.org (HasNoChildren)
user/tester@cngnu.org (HasNoChildren) user/testdel (HasNoChildren)
mail.cngnu.org> sam user/testdel cyrus cd
mail.cngnu.org> dm user/testdel
mail.cngnu.org> lm
user/cyrus (HasNoChildren) user/tester~cngnu.org (HasNoChildren)
user/tester@cngnu.org (HasNoChildren)
mail.cngnu.org> quit
[root@mail bin]# rm -rf /var/spool/imap/user/testdel
再检测POP3和IMAP服务:
[root@mail bin]# telnet localhost 110
+OK mail.cngnu.org Cyrus POP3 v2.1.15 server ready
USER tester@cngnu.org
+OK Name is a valid mailbox
PASS testpw
+OK Maildrop locked and ready
QUIT
+OK
[root@mail bin]# imtest -m login -a tester@cngnu.org localhost
C: C01 CAPABILITY
S: * OK mail.cngnu.org Cyrus IMAP4 v2.1.12 server ready
S: * CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ NAMESPACE UIDPLUS ID NO_ATOMIC_RENAME UNSELECT MULTIAPPEND SORT THREAD=ORDEREDSUBJECT THREAD=REFERENCES IDLE
S: C01 OK Completed
Password:
C: L01 LOGIN tester@cngnu.org {6}
+ go ahead
C: <omitted>
L01 OK User logged in
Authenticated.
Security strength factor: 0
. logout
* BYE LOGOUT received
. OK Completed
9. 安装IMP
9.1. 下载
http://www.php.net/get_download.php?df=php-4.3.2.tar.gz
http://www.horde.org/horde/
http://www.horde.org/imp/3.2.1/
http://www.horde.org/turba/
[root@mail bin]# cd /usr/src
[root@mail src]# wget http://www.php.net/distributions/php-4.3.2.tar.gz
[root@mail src]# wget ftp://ftp.horde.org/pub/horde/horde-2.2.1.tar.gz
[root@mail src]# wget ftp://ftp.horde.org/pub/pear/pear-1.0.1.tar.gz
[root@mail src]# wget ftp://ftp.horde.org/pub/imp/imp-3.2.1.tar.gz
[root@mail src]# wget ftp://ftp.horde.org/pub/turba/turba-1.2.tar.gz
9.2. 配置Apache与PHP
IMP对PHP的环境要求较高。所以通常需要升级PHP包,并安装由Horde定制后的PEAR包。编译新的PHP包前请确认系统中存在Apache(这里使用了Apache 2)以及其它相关的软件包。
RedHat的httpd-devel包中没有apache 2用来安装dso模块的脚本:instdso.sh,请自行从apache 2.x的发行包中取得,并放入/usr/lib/httpd/build中。
[root@mail src]# tar zxf php-4.3.2.tar.gz
[root@mail src]# cd php-4.3.2
[root@mail php-4.3.2]# ./configure --prefix=/usr --with-config-file-path=/etc \
> --with-mysql --with-apxs2 \
> --enable-ftp --enable-magic_quotes --with-xml \
> --with-gettext --with-imap \
> --with-imap-ssl --with-kerberos=/usr/kerberos
[root@mail php-4.3.2]# make
[root@mail php-4.3.2]# make install
[root@mail php-4.3.2]# [ -f /etc/php.ini ] && mv /etc/php.ini /etc/php.ini.orig
[root@mail php-4.3.2]# cp php.ini-dist /etc/php.ini
修改/etc/php.ini,将register_globals功能打开。
register_globals = On
安装PEAR包:
[root@mail php-4.3.2]# cd /usr/lib
[root@mail lib]# [-d php ] && mv php php.orig
[root@mail lib]# tar zxf /usr/src/pear-1.0.1.tar.gz
[root@mail lib]# mv pear php
最后重新启动Apache:
[root@mail lib]# /etc/rc.d/init.d/httpd restart
9.3. 配置Horde
安装Horde:
[root@mail lib]# cd /var/www/html
[root@mail html]# tar zxf /usr/src/horde-2.2.1.tar.gz
[root@mail html]# mv horde-2.2.1 horde
[root@mail html]# cd horde/scripts/db
[root@mail db]# mysql < mysql_create.sql
[root@mail db]# cd ../../config
[root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done
然后修改config目录下面的horde.php。
[root@mail config]# vi horde.php
修改148行:
$conf['prefs']['driver'] = 'none';
为:
$conf['prefs']['driver'] = 'sql';
修改157行至162行,将其注释去掉并写入horde数据库的口令:
// $conf['prefs']['params']['phptype'] = 'mysql';
// $conf['prefs']['params']['hostspec'] = 'localhost';
// $conf['prefs']['params']['username'] = 'horde';
// $conf['prefs']['params']['password'] = '*****';
// $conf['prefs']['params']['database'] = 'horde';
// $conf['prefs']['params']['table'] = 'horde_prefs';
为:
$conf['prefs']['params']['phptype'] = 'mysql';
$conf['prefs']['params']['hostspec'] = 'localhost';
$conf['prefs']['params']['username'] = 'horde';
$conf['prefs']['params']['password'] = 'horde';
$conf['prefs']['params']['database'] = 'horde';
$conf['prefs']['params']['table'] = 'horde_prefs';
这里我们没有修改horde数据库的默认的数据库设置,如果在实际使用中,至少应该取一个比较复杂的密码。
再来修改config目录下面的registry.php。
[root@mail config]# vi registry.php
修改23行至24行,将其注释去掉:
// $this->registry['auth']['login'] = 'imp';
// $this->registry['auth']['logout'] = 'imp';
为:
$this->registry['auth']['login'] = 'imp';
$this->registry['auth']['logout'] = 'imp';
然后修改109、118行激活IMP和Turba:
'status' => 'inactive'
为:
'status' => 'active'
最后在浏览器中访问如下URL测试Horde需要的环境是否满足:
http://你的IMP服务器的IP/horde/test.php
如果发现有红色的提示,可能需要修改你的PHP的安装和配置(参见上一节),然后再重新测试。
9.4. 配置IMP
安装IMP:
[root@mail config]# cd ..
[root@mail horde]# tar zxf /usr/src/imp-3.2.1.tar.gz
[root@mail horde]# mv imp-3.2.1 imp
[root@mail horde]# cd imp/config
[root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done
然后修改config目录里面的conf.php:
[root@mail config]# vi conf.php
修改37行:
$conf['menu']['apps'] = array();
为:
$conf['menu']['apps'] = array('turba');
修改57行:
$conf['user']['allow_resume_all'] = false;
为:
$conf['user']['allow_resume_all'] = true;
修改63行:
$conf['user']['allow_resume_all_in_drafts'] = false;
为:
$conf['user']['allow_resume_all_in_drafts'] = true;
然后修改prefs.php:
[root@mail config]# vi prefs.php
将自动维护功能关闭,修改426、427行:
'value' => 1,
'locked' => false,
为:
'value' => 0,
'locked' => true,
再注释773行:
'value' => '',
为:
//'value' => '',
取消注释774行:
// 'value' => 'localsql',
为:
'value' => 'localsql',
最后修改servers.php:
[root@mail config]# vi servers.php
注释除“cyrus”服务器外的所有服务器配置,然后修改“cyrus”服务器的配置为:
$servers['cyrus'] = array(
'name' => 'Cyrus IMAP Server',
'server' => 'localhost',
'protocol' => 'imap/notls',
'port' => 143,
'folders' => '',
'namespace' => 'INBOX.',
'maildomain' => 'cngnu.org',
'realm' => 'cngnu.org',
'preferred' => ''
);
9.5. 配置Turba
安装Turba:
[root@mail config]# cd ../..
[root@mail horde]# tar zxf /usr/src/turba-1.2.tar.gz
[root@mail horde]# mv turba-1.2 turba
[root@mail horde]# cd turba/config
[root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done
然后修改config目录里面的conf.php:
[root@mail config]# vi conf.php
修改32行:
$conf['menu']['apps'] = array();
为:
$conf['menu']['apps'] = array('imp');
然后修改config目录里面的sources.php:
[root@mail config]# vi sources.php
修改140行:
'password' => '*****';
为:
'password' => 'horde';
最后,添加turba数据库表:
[root@mail config]# cd ../scripts/drivers
[root@mail config]# mysql -u horde -phorde <turba.sql
9.6. 测试IMP
最后在浏览器中访问如下URL:
http://你的IMP服务器的IP/horde/
输入用户名tester@cngnu.org和密码testpw登录。
10. 其他
10.1. 启动脚本
可以编写一个启动脚本mailsys来启动这些进程,这样就不需要单独启动postfix和cyrusd了:
#!/bin/bash## mailsys This shell script takes care of starting and stopping# Postfix and Cyrus-IMAP.# author : xingyu.wang <wxy@cngnu.org> 2003/2/5## chkconfig: 2345 80 30# description: Postfix is a Mail Transport Agent, which is the program# that moves mail from one machine to another.Cyrus-IMAP is a Mail # Deliver Agent, which provide POP3 and IMAP4 services for user and # deliver mail to local mailbox.## processname: mailsys# pidfile: /var/run/mailsys.pid# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -f /usr/sbin/postfix ] || exit 0[ -f /usr/cyrus/bin/cyrusd ] || exit 0RETVAL=0prog="Mail System"start() { # Start daemons. echo -n $"Starting $prog: " echo -n $"SASL " /usr/local/sbin/saslauthd -a pam echo -n $"SMTP " /usr/sbin/postfix start > /dev/null 2>&1 & echo -n $"POP3 IMAP4 " /usr/cyrus/bin/cyrusd > /dev/null 2>&1 & RETVAL=$? if [ $RETVAL -eq 0 ]; then touch /var/lock/subsys/mailsys success $"$prog start" else failure $"$prog start failure" fi echo return $RETVAL}stop() { # Stop daemons. echo -n $"Shutting down $prog: " echo -n $"SMTP " /usr/sbin/postfix stop > /dev/null 2>&1 & echo -n $"POP3 IMAP4 " killproc cyrusd echo -n $"SASL " killproc saslauthd RETVAL=$? if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/mailsys success $"$prog stop" else failure $"$prog stop failure" fi echo return $RETVAL}# See how we were called.case "$1" in start) start ;; stop) stop ;; restart|reload) stop start RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1esacexit $RETVAL
[root@mail root]# chmod 755 /etc/rc.d/init.d/mailsys
[root@mail root]# cd /etc/rc3.d
[root@mail rc3.d]# ln -s ../init.d/mailsys S80mailsys
[root@mail rc3.d]# rm -rf S80sendmail
10.2. 整体测试
创建邮箱后,测试发信功能:
[root@mail root]# mail tester@cngnu.org
Subject: test by me
this is a test.
.
CC:
[root@mail root]# mailq
Mail queue is empty
[root@mail root]# tail /var/log/mail/*
使用mailq来查看邮件队列是否有错误,并查看/var/log/mail/*是否有错误信息。如果一切正常,说明信件已经发送到tester了。
测试收信,先测试POP3:
[root@mail root]# telnet localhost 110
+OK mail.cngnu.org Cyrus POP3 v2.1.15 server ready
USER tester@cngnu.org
+OK Name is a valid mailbox
PASS testpw
+OK Maildrop locked and ready
LIST
1 400
TOP 1 10
Return-Path: <root@cngnu.org>
X-Sieve: cmu-sieve 2.0
Return-Path: <root@cngnu.org>
Received: by mail. (Postfix, from userid 0)
id 5F1EF90005; Mon, 20 May 2002 18:03:43 +0800 (CST)
To: tester@cngnu.org
Subject: test by me
Message-Id: <20020520100343.5F1EF90005@mail00.cngnu.org>
Date: Mon, 20 May 2002 18:03:43 +0800 (CST)
From: root@cngnu.org (root)
this is a test.
.
QUIT
+OK
再测试IMAP:
[root@mail root]# imtest -m login -a tester@cngnu.org localhost
C: C01 CAPABILITY
S: * OK mail.cngnu.org Cyrus IMAP4 v2.1.15 server ready
S: * CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ NAMESPACE UIDPLUS ID NO_ATOMIC_RENAME UNSELECT MULTIAPPEND SORT THREAD=ORDEREDSUBJECT THREAD=REFERENCES IDLE
S: C01 OK Completed
Password:
C: L01 LOGIN tester {6}
+ go ahead
C: <omitted>
L01 OK User logged in
Authenticated.
Security strength factor: 0
. select inbox
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)]
* 1 EXISTS
* 1 RECENT
* OK [UIDVALIDITY 1021736432]
* OK [UIDNEXT 3]
. OK [READ-WRITE] Completed
. fetch 1:1 (FLAGS BODY[HEADER.FIELDS (DATE FROM)])
* 1 FETCH (FLAGS (\Seen) BODY[HEADER.FIELDS (DATE FROM)] {68}
Date: Mon, 20 May 2002 09:26:09 +0800 (CST)
From: wxy@cngnu.org
)
. OK Completed
. logout
* BYE LOGOUT received
. OK Completed
最后测试IMP,在浏览器中访问如下URL:
http://你的IMP服务器的IP/horde/
输入用户名tester@cngnu.org和密码testpw登录。
你也可以使用任何其它的邮件客户端程序来测试,如kmail、Outlook Express等等。 |
|