Chinaunix首页 | 论坛 | 博客
  • 博客访问: 217142
  • 博文数量: 35
  • 博客积分: 2566
  • 博客等级: 少校
  • 技术积分: 375
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 13:09
文章分类

全部博文(35)

文章存档

2011年(1)

2010年(3)

2009年(11)

2008年(20)

我的朋友

分类: LINUX

2008-03-31 22:46:58

RedHat AS4.0 轻松搭建Postfix 邮件服务器系统

RedHat AS4.0 轻松搭建Postfix 邮件服务器系统
 
作者:liheng
Email:liheng_2006@hotmail.com
序言:
一直都非常想自己做一个邮件服务器玩玩,有这个想法很久了,但却一直都没有做,总结的原因是:太忙了,没时间。嘿嘿~~~~究竟忙的什么,我就不透露了。上个月,终于痛下决心,一定要弄出个邮件服务器出来玩玩不可,也正因为此,才有了本文的诞生。
之前用了一个月时间看了 postfix 的经典之作---《postfix 权威指南》,首先要大致摸个底嘛。但看完一遍以后,总体上的感觉是,书是写得很好,但自己就是有很多不明白,看不懂的地方。看来还是得亲自做出来,熟悉一下大致的框架才行,这样看的话,有点盲人摸象的感觉。既然已经决定,那就马上行动吧, Let’s go!
本文的配置参照了互联网上不少前辈的文章,在这里我要向他们致敬,没有他们无私的奉献,我想依靠我一个人无法做得出来这么庞大的邮件系统。
我在配置邮件服务器的过程中,遇到了不少问题,smtp 验证我弄了一个星期, chdir Maildir failed这个问题弄了半个月。多得了互联网上不少热心朋友的指点,才使得最终我的邮件服务器得以成功,在这里要非常谢谢他们。

安装 postfix 邮件服务器所需的软件列表:
1、        RedHat as 4.0
RedHat 高级服务器操作系统
2、Postfix
这一个是自然少不了的,邮件服务器系统的 smtp 服务器,在邮件服务器系统中充当MTA 角色。软件版本:postfix-2.4.5
下载地址:
3、mysql
最优秀的开源数据库之一,用于存储虚拟域、虚拟账户信息。使用的版本: mysql-5.0.45
下载地址:http://dev.mysql.com/downloads/mysql/5.0.html
4、apache
最优秀的 web 服务器软件之一,用于 extman 的后台管理,extmail 的 web 邮件收发。
软件版本:httpd-2.2.4
下载地址:
5、php
Extman & extmail 需要使用 php.作用版本:php-5.2.3
下载地址:
6、cyrus-sasl
用于实现身份验证的smtp 服务器,使用版本:cyrus-sasl-2.1.22
下载地址:
7、courier-authlib
实现带验证的 pop3 服务器,使用版本:courier-authlib-0.58
下载地址:
8、courier-imap
用于实现 pop3、imap 收邮件功能,使用版本: courier-imap-4.1.0
下载地址:
9、openssl
提供安全的邮件服务器连接,使用版本:openssl-0.9.8e
下载地址:
10、extman
用于邮件服务器的后台管理,使用版本:extman-0[1].2.2
下载地址:
11、extmail
用于实现 webmail.使用版本:extmail-1[1].0.2
下载地址:
12、DBD-Mysql
用于解决依赖关系,extmail 将会用到,使用版本:DBD-Mysql-3.0002_4
下载地址:
13、Unix-Syslog
用于解决依赖关系,extmail 将会用到,使用版本:Unix-Syslog-0.100
下载地址:
14、BerkeleyDB
使用版本:BerkeleyDB-4.5.20
下载地址:
15、pcre
安装 maildrop 时需要,使用版本:pcre-7.4
下载地址:
16、maildrop
用来代替postfix 自带的 MDA,是一个带有过滤功能的 MDA,使用版本:maildrop-2.02
下载地址:

邮件服务器系统的安装
本文约定:默认情况下,本文中的所有软件的压缩安装文件都放在 /root 目录下,除非特别说明的情况下。
禁用 selinux
[root @test root]# vi /etc/selinux/conifg
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
将 SELINUX=enforcing
改成
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted
Selinux 是 linux 系统中一个强制性的安全机制,但也带来了不少麻烦,为了避免不必要的麻烦,还是先关了吧。我之前在 Fedora cora 5 上安装邮件服务器时就因为没有关掉 selinux ,而苦恼了一段时间。
1、 安装 mysql
添加虚帐户mysql 并同时产生一个 mysql 组。注:如果系统中已有就不必添加了。
[root @test root]# groupadd  mysql
[root @test root]# useradd -g mysql mysql
解压缩mysql 安装文件
[root @test root]# cp mysql-5.0.45-linux-i686.tar.gz /usr/local
[root @test root]# cd /usr/local
[root @test local]#tar xvzf mysql-5.0.45-linux-i686.tar.gz
[root @test local]#ln -s mysql-5.0.45-linux-i686 mysql
将mysql-5.0.45-linux-i686 链接到当前目录下,并命名为 mysql
[root @test local]# mkdir -p /var/lib/mysql
[root @test local]# chown -R mysql:mysql /var/lib/mysql
初始化 mysql 数据库
[root @test local]# cd mysql
[root @test mysql]#./script/mysql_install_db  —user=mysql &
修改目录所有权限为mysql 所有
[root @test mysql]#chown -R root .
[root @test mysql]#chown -R mysql:mysql data
[root @test mysql]#chgrp -R mysql .
启动测试mysql
[root @test local]#/usr/local/mysql/bin/safe_mysqld —user= mysql &
[root @test local]#ln -s /var/lib/mysql/mysql.sock /tmp/
注:将/var/lib/mysql/mysql.sock 链接到 /tmp 目录下,并保持名称不变,如果不这样做的话,有时候可能mysql 启动时会报错,如 ERROR 200:Can’t connect to local MYSQL server throuht socket /tmp/mysql.sock.

复制一个编译目录的脚本,以使 mysql 每次启动时都能自动运行
[root @test local]#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root @test local]#chmod 700 /etc/init.d/mysqld
[root @test local]#chkconfig —add mysqld
[root @test local]#chkconfig —level 35 mysqld on
[root @ test local] # echo “/usr/local/mysql/lib/mysql” >> /etc/ld.so.conf
[root @ test local] # ldconfig
说明:在用 /usr/local/mysql/bin/mysqld_safe —user=mysql & 命令启动测试 mysql 时,总是无法启动mysql ,自然也无法进入 mysql ,开始还以为是自己操作失误,然后又重新解压mysql安装文件,重新安装,依然如此,甚是郁闷,最后查看日志 /var/log/mysqld.log,显示:
070829  9:04:08 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file'/var/run/mysqld/mysqld.pid' (Errcode: 13)
070829  9:04:08 [ERROR] Can't start server: can't create PID file: Permission denied
070829 09:04:08  mysqld ended
根据日志提示,查看 /var/run/mysqld 目录,发现该目录下并没有mysqld.pid 文件,查看该目录的文件权限,发现用户所有者即不属于root ,也不属于mysql ,文件所有者显示为27。据此推断,可能是mysql 启动时会向此文件夹内写一些东西,但 mysql 的进程用户mysql 却没有权限写,导致mysql 无法启动,用touch /var/run/mysqld/mysqld.pid 命令创建mysql 所需要文件,chown -R mysql:mysql/var/run/mysqld将/var/run/mysqld 的目录权限转给 mysql。再次用/usr/local/mysql/bin/mysqld_safe —user=mysql & 启动mysql ,没有再报错,用netatst -tlnup 命令,查看mysql 的端口号3306是否启动,已经可以看到3306端口处于监听状态,mysql 启动成功,用/usr/lcoal/mysql/bin/mysql 进入mysql 数据库,没问题。至此 mysql 安装成功。此问题只在 Fedora cora 5 中发现,我在 redhat AS4 中安装 mysql 没有发现这个问题。

2、安装 openssl
[root @ test root] # tar zxvf openssl-0.9.8e.tar.gz
[root @ test root] # cd openssl-0.9.8e
[root @ test openssl-0.9.8e] # ./config shared zlib
[root @ test openssl-0.9.8e] # make
[root @ test openssl-0.9.8e] # make test
[root @ test openssl-0.9.8e] # make install
[root @ test openssl-0.9.8e] # mv /usr/bin/openssl /usr/bin/openssl.OFF
[root @ test openssl-0.9.8e] # mv /usr/include/openssl /usr/include/openssl.OFF
[root @ test openssl-0.9.8e] # rm /usr/lib/libssl.so
[root @ test openssl-0.9.8e] # ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
[root @ test openssl-0.9.8e] #ln -s /usr/local/ssl/include/openssl /usr/include/openssl
[root @ test openssl-0.9.8e] # ln -sv /usr/local/ssl/lib/libssl.so.0.9.8  /usr/lib/libssl.so

配置库文件搜索路径
[root @ test openssl-0.9.8e] #echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
[root @ test openssl-0.9.8e] # ldconfig
检查是否安装 openssl
[root @ test openssl-0.9.8e] # openssl version
OpenSSL 0.9.8e 23 Feb 2007
3、安装 cyrus-sasl
[root @ test root] # tar xzvf cyrus-sasl-2.1.22.tar.gz
[root @ test root] # cd cyrus-sasl-2.1.22
[root @ test cyrus-sasl-2.1.22] #./configure --prefix=/usr/local/sasl2            --disable-gssapi --disable-anon --disable-sample --disable-digest
--enable-plain --enable-login --enable-sql --with-mysql=/usr/local/mysql
--with-mysql-includes=/usr/local/mysql/include/mysql --with-mysql-libs=/usr/local/mysql/lib/mysql  —with-authdaemond=/usr/local/courier-authlib/var/spool/authdaemon/socket
[root @ test cyrus-sasl-2.1.22] # make
[root @ test cyrus-sasl-2.1.22] # make install
关闭原有的 sasl
[root @ test cyrus-sasl-2.1.22] # mv /usr/lib/libsasl2.a  /usr/lib/libsasl2.a.OFF
[root @ test cyrus-sasl-2.1.22] # mv /usr/lib/libsasl2.la  /usr/lib/libsasl2.la.OFF
[root @ test cyrus-sasl-2.1.22] # mv /usr/lib/libsasl2.so.2.0.19  /usr/lib/libsasl2.so.2.0.19.OFF
[root @ test cyrus-sasl-2.1.22] # mv /usr/lib/sasl2  /usr/lib/sasl2.OFF
[root @ test cyrus-sasl-2.1.22] # rm /usr/lib/libsasl2.so
[root @ test cyrus-sasl-2.1.22] # rm /usr/lib/libsasl2.so.2
[root @ test cyrus-sasl-2.1.22] # ln -s /usr/local/sasl2/lib/*  /usr/lib
postfix 2.3以后的版本会分别在/usr/local/lib和/usr/local/include中搜索sasl库文件及头文件,故还须将其链接至此目录中:
[root @ test cyrus-sasl-2.1.22] # ln -sv /usr/local/sasl2/lib/*  /usr/local/lib
[root @ test cyrus-sasl-2.1.22] # ln -sv /usr/local/sasl2/include/sasl/*  /usr/local/include
创建运行时需要的目录并调试启动
[root @ test cyrus-sasl-2.1.22] # mkdir -pv /var/state/saslauthd      
[root @ test cyrus-sasl-2.1.22] # /usr/local/sasl2/sbin/saslauthd  -a  shadow  pam  -d

启动并测试
[root @ test cyrus-sasl-2.1.22] # /usr/local/sasl2/sbin/saslauthd -a shadow pam
[root @ test cyrus-sasl-2.1.22] #
配置库文件搜索路径
[root @ test cyrus-sasl-2.1.22] # echo "/usr/local/sasl2/lib" >> /etc/ld.so.conf
[root @ test cyrus-sasl-2.1.22] # echo "/usr/local/sasl2/lib/sasl2" >> /etc/ld.so.conf
[root @ test cyrus-sasl-2.1.22] # ldconfig

开机自动启动
[root @ test cyrus-sasl-2.1.22] # echo "/usr/local/sasl2/sbin/saslauthd -a shadow pam">>/etc/rc.local
4、安装 Berkeley-DB
[root @ test root] # tar zxvf db-4.5.20.tar.gz
[root @ test root] # cd db-4.5.20/build_unix
[root @ test build_unix] #../dist/configure —prefix=/usr/local/BerkeleyDB
[root @ test build_unix] #make
[root @ test build_unix] #make install

修改相应的头文件指向
[root @ test build_unix] # mv  /usr/inculde/db4  /usr/inculde/db4.OFF
[root @ test build_unix] # rm  /usr/inculde/db_cxx.h
[root @ test build_unix] # rm  /usr/inculde/db.h
[root @ test build_unix] # rm  /usr/inculde/db_185.h
[root @ test build_unix] # ln -sv /usr/local/BerkeleyDB/include  /usr/include/db4
[root @ test build_unix] # ln -sv /usr/local/BerkeleyDB/include/db.h  /usr/include/db.h
[root @ test build_unix] # ln -sv /usr/local/BerkeleyDB/include/db_cxx.h  /usr/include/db_cxx.h

配置库文件搜索路径
[root @ test build_unix] # echo "/usr/local/BerkeleyDB/lib" >> /etc/ld.so.conf
[root @ test build_unix] # ldconfig

5、安装httpd-2.2.4
[root @ test root] # tar jxvf httpd-2.2.4.tar.bz2
[root @ test root] # cd httpd-2.2.4
[root @ test httpd-2.2.4] #./configure
--prefix=/usr/local/apache --enable-so --enable-ssl
--with-ssl=/usr/local/ssl --enable-track-vars --enable-rewrite --with-zlib
--enable-mods-shared=most  --enable-suexec                  —with-suexec-caller=daemon  
[root @ test httpd-2.2.4] # make
[root @ test httpd-2.2.4] # make install
[root @ test httpd-2.2.4] # echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.local(系统启动时服务自动启动)

6、安装php-5.2.3

[root @ test root] # tar -zvxf php-5.2.3.tar.gz
[root @ test root] # mkdir -p /usr/local/php
[root @ test root] # cd php-5.2.3
[root @ test php-5.2.3] # ./configure —prefix=/usr/local/php              
  —with-apxs2=/usr/local/apache/bin/apxs   —with-mysql=/usr/local/mysql
  —with-mysqli=/usr/local/mysql/bin/mysql_config   —with-xml   —with-png
  —with-jpeg   —with-zlib   —with-freetype   —with-gd    —enable-track-vars    —enable-mbstring=all
[root @ test php-5.2.3] # make
[root @ test php-5.2.3] # make install
[root @ test php-5.2.3] # cp php.ini-dist  /usr/local/php/lib/php.ini

注:编辑apache配置文件httpd.conf,以apache支持php
[root @ test php-5.2.3] # vi /usr/local/apache/conf/httpd.conf
# 添加如下二行
  AddType application/x-httpd-php  .php
  AddType application/x-httpd-php-source  .phps

# 定位至DirectoryIndex index.html
  修改为:
   DirectoryIndex  index.php  index.html

# 这里将网站根目录指定到/var/www:
找到DocumentRoot “/usr/local/apache/htdocs”
修改为:DocumentRoot “/var/www”(后文中我们还会注释掉此行,以启用虚拟主机)

找到
修改为:


7、安装 postfix
[root @ test root] # groupadd -g 2525 postfix
[root @ test root] # useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
[root @ test root] # groupadd -g 2526 postdrop
[root @ test root] # useradd -g postdrop -u 2526 -s /bin/false -M postdrop
[root @ test root] # service sendmail stop
[root @ test root] # mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
[root @ test root] # mv /usr/bin/mailq /usr/bin/mailq.OFF
[root @ test root] # mv /usr/bin/newaliases /usr/bin/newaliases.OFF
[root @ test root] # tar zxvf postfix-2.4.5.tar.gz
[root @ test root] #cd postfix-2.4.5
[root @ test postfix-2.4.5] # make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/sasl2/include/sasl -I/usr/local/BerkeleyDB/include  -DUSE_TLS -I/usr/local/ssl/include/openssl ' 'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/local/sasl2/lib -lsasl2 -L/usr/local/BerkeleyDB/lib -L/usr/local/ssl/lib -lssl -lcrypto'
[root @ test postfix-2.4.5] # make
[root @ test postfix-2.4.5] # make install
Install_root: [/]
tempdir: [/usr/local/src/ postfix-2.4.5]
config_directory: [/etc/postfix]
daemon_directory: [/usr/libexec/postfix]
command_directory: [/usr/sbin]
queue_directory: [/var/spool/postfix]
sendmail_path: [/usr/sbin/sendmail]
newaliases_path: [/usr/bin/newaliases]
mailq_path: [/usr/bin/mailq]
mail_owner: [postfix]
setgid_group: [postdrop]   
html_directory: [no]
manpages: [/usr/local/man]   
readme_directory: [no]
上面的选项全部保持默认,直接回车即可。
生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低:
[root @ test postfix-2.4.5] #  newaliases
配置 postfix
[root @ test postfix-2.4.5] # vi /etc/postfix/main.cf
myhostname = mail.test.com
mydomain = test.com
myorigin = $mydomain
inet_interfaces = all
mynetworks = 192.168.98.0/24, 127.0.0.0/8
#================Virtual Setting ====================
virtual_mailbox_base = /var/mailbox/
virtual_mailbox_maps= mysql:/etc/postfix/mysql/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains=mysql:/etc/postfix/mysql/mysql_virtual_domains_maps.cf
virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:2525
virtual_gid_maps = static:2525
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
#=================Quota Setting ====================
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql/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
#=================== Cyrus-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
smtpd_sasl_application_name = smtpd
smtpd_banner = Welcome to our $myhostname ESMTP, Warning:Version not Available!
[root @ test postfix-2.4.5] # mkdir -p /etc/postfix/mysql
[root @ test postfix-2.4.5] # cd /etc/postfix/mysql
[root @ test mysql] # vi mysql_virtual_alias_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = alias
select_field = goto
where_field = address
[root @ test mysql] #   vi mysql_virtual_mailbox_limit_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = mailbox
select_field = quota
where_field = username
[root @ test mysql] # vi mysql_virtual_domains_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = domain
select_field = description
where_field = domain
[root @ test mysql] # vi mysql_virtual_mailbox_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = mailbox
select_field = maildir
where_field = username

8、安装 courier-authlib
[root @ test root] #  tar jxvf courier-authlib-0.58.tar.bz2
[root @ test root] #  cd courier-authlib-0.58
[root @ test courier-authlib-0.58] # ./configure     --prefix=/usr/local/courier-authlib         --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/inculde/mysql —with-redhat
CFLAGS="-march=i686 -O2 -fexpensive-optimizations"  \
  CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations"
[root @ test courier-authlib-0.58] # make
[root @ test courier-authlib-0.58] # make install

[root @ test courier-authlib-0.58] # chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
[root @ test courier-authlib-0.58] # cp /usr/local/courier-authlib/etc/authdaemonrc.dist  /usr/localcourier-authlib/etc/authdaemonrc
# cp /usr/local/courier-authlib/etc/authmysqlrc.dist  /usr/local/courier-authlib/etc/authmysqlrc

修改/etc/authdaemonrc 文件
[root @ test courier-authlib-0.58] # vi /usr/local/courier-authlib/etc/authlib/authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10

编辑/etc/authmysqlrc 为以下内容,其中2525,2525 为postfix 用户的UID和GID。
[root @ test courier-authlib-0.58] # vi /usr/local/courier-authlib/etc/authlib/authdaemonrc
MYSQL_SERVER localhost
MYSQL_PORT 3306                   (指定你的mysql监听的端口,这里使用默认的3306)
MYSQL_USERNAME  extmail      (这时为后文要用的数据库的所有者的用户名)
MYSQL_PASSWORD extmail        (密码)
MYSQL_SOCKET  /tmp/mysql.sock
MYSQL_DATABASE  extmail
MYSQL_USER_TABLE  mailbox
MYSQL_CRYPT_PWFIELD  password
MYSQL_UID_FIELD  '2525'
MYSQL_GID_FIELD  '2525'
MYSQL_LOGIN_FIELD  username
MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)
MYSQL_NAME_FIELD  name
MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)
注:这个文件中不能出现空格,或者会出现 FAQ 中的示例4 中的错误。
设置 courier-authlib 自启动
[root @ test courier-authlib-0.58] # cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root @ test courier-authlib-0.58] # chmod 755 /etc/init.d/courier-authlib
[root @ test courier-authlib-0.58] # chkconfig —add courier-authlib
[root @ test courier-authlib-0.58] # chkconfig —level 2345 courier-authlib on
[root @ test courier-authlib-0.58] #echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf
[root @ test courier-authlib-0.58] # ldconfig
[root @ test courier-authlib-0.58] # service courier-authlib start   (启动服务)

9、安装Courier-IMAP

[root @ test root] # tar jxvf courier-imap-4.1.3.tar.bz2
[root @ test root] # cd courier-imap-4.1.3
[root @ test courier-imap-4.1.3] #./configure   —prefix=/usr/local/imap   —with-redhat   —enable-unicode   —disable-root-check   —with-trashquota   CPPFLAGS='-I/usr/local/ssl/include/openssl  -I/usr/local/courier-authlib/include'   
  LDFLAGS='-L/usr/local/courier-authlib/lib/courier-authlib'  
  COURIERAUTHCONFIG='/usr/local/courier-authlib/bin/courierauthconfig'
[root @ test courier-imap-4.1.3] # make
[root @ test courier-imap-4.1.3] # make install
[root @ test courier-imap-4.1.3] # cp /usr/local/imap/etc/imapd.dist /usr/local/imap/etc/imapd
[root @ test courier-imap-4.1.3] # cp /usr/local/imap/etc/imapd-ssl.dist /usr/local/imap/etc/imapd-ssl
[root @ test courier-imap-4.1.3] # cp /usr/local/imap/etc/pop3d.dist /usr/local/imap/etc/pop3d
[root @ test courier-imap-4.1.3] # cp /usr/local/imap/etc/pop3d-ssl.dist /usr/local/map/etc/pop3d-ssl
配置Courier-IMAP,为用户提供pop3服务:
[root @ test courier-imap-4.1.3]  # vi /usr/local/imap/etc/pop3d
POP3DSTART=YES

注:如果你想为用户提供IMAP服务,则需在"/usr/local/courier-imap/etc/imapd"文件中设置"IMAPDSTART=yes";其它类同;

新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
[root @ test courier-imap-4.1.3]  # mkdir –p /var/mailbox
[root @ test courier-imap-4.1.3]  #chown –R postfix /var/mailbox

[root @ test courier-imap-4.1.3]  # cp courier-imap.sysvinit /etc/rc.d/init.d/imapd
[root @ test courier-imap-4.1.3]  # chmod 755 /etc/rc.d/init.d/imapd
[root @ test courier-imap-4.1.3]  # chkconfig —add imapd
[root @ test courier-imap-4.1.3]  # chkconfig —level 2345 imapd on
[root @ test courier-imap-4.1.3]  # service imapd start

接下来重新配置SMTP 认证,编辑 /usr/local/lib/sasl2/smtpd.conf ,确保其为以下内容:
[root @ test courier-imap-4.1.3]  # vi /usr/local/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
log_level: 3
mech_list:PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
10、安装 extmail
[root @test root] # tar zxvf extmail-1.0.2.tar.gz
[root @test root] # mkdir -pv /var/www/extsuite
[root @test root] # mv extmail-1.0.2 /var/www/extsuite/extmail
[root @test root]# cp /var/www/extsuite/extmail/webmail.cf.default  /var/www/extsuite/extmail/webmail.cf
修改主配置文件
[root @test root] # vi /var/www/extsuite/extmail/webmail.cf

部分修改选项的说明:

SYS_MESSAGE_SIZE_LIMIT = 5242880
用户可以发送的最大邮件

SYS_USER_LANG = en_US
语言选项,可改作:
SYS_USER_LANG = zh_CN

SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox/

SYS_MYSQL_USER = db_user
SYS_MYSQL_PASS = db_pass
以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail

SYS_MYSQL_HOST = localhost
指明数据库服务器主机名,这里默认即可

SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
连接数据库的sock文件位置,这里修改为:
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_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
此句用来指明authdaemo socket文件的位置,这里修改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket


apache相关配置
[root @test root] # vi /usr/local/apache/confhttpd.conf
将 User daemon
Group daemon
改为
User postfix
Group postfix
将Include conf/extra/httpd-vhosts.conf
前的注释去掉,打开 apache 的虚拟主机功能。
# virtual hosts
Include conf/extra/httpd-vhosts.conf

编辑虚拟主机配置文件
[root @test root]# vi /usr/local/apache/conf/extra/vhosts-httpd.conf

ServerName mail.test.com
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html


依赖关系的解决

extmail将会用到perl的DBD::Mysql和Unix::syslogd功能,您可以去搜索下载原码包进行安装。
[root @ test root] # tar zxvf Unix-Syslog-0.100.tar.gz
[root @ test root] # cd Unix-Syslog-0.100
[root @ test Unix-Syslog-0.100] # perl Makefile.PL
[root @ test Unix-Syslog-0.100] # make
[root @ test Unix-Syslog-0.100] # make install

DBD-Mysql目前最新的版本为DBD-mysql-4.005,但它和系统中的perl结合使用时会造成extmail无法正常使用,因此我们采用3的版本:
[root @ test root] # tar zxvf DBD-mysql-3.0002_4.tar.gz  
[root @ test root] # cd DBD-mysql-3.0002_4
[root @ test DBD-mysql-3.0002_4] # perl Makefile.PL   (此步骤中如果出现类同Can't exec "mysql_config": No such file or directory at Makefile.PL line 76.的错误是因为您的mysql的bin目录没有输出至$PATH环境变量)
[root @ test DBD-mysql-3.0002_4] # make
[root @ test DBD-mysql-3.0002_4] # make install

好了,到此为止,您的Webmail已经可以使用了,可以在浏览器中输入指定的虚拟主机的名称进行访问,如下:

注:要在 DNS 服务器已经配置好,并运行正常的情况下才可以用域名访问,如果没有配置 DNS 服务,直接输入 IP 就行了
11、安装Extman-0.2.2
安装及基本配置

[root @ test root] #tar zxvf  extman-0.2.2.tar.gz
[root @ test root] # mv extman-0.2.2 /var/www/extsuite/extman

修改配置文件以符合本例的需要:
[root @test root] # vi /var/www/extsuite/extman/webman.cf

SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox/

SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
此处修改为:
SYS_MYSQL_SOCKET = /tmp/mysql.sock

使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库:

[root @test root] # cd /var/www/extsuite/extman/docs
[root @test docs ] # /usr/local/mysql/bin/mysql -u root  < extmail.sql
[root @test docs] # /usr/local/mysql/bin/mysql  -u root -p < init.sql

修改cgi目录的属主:
[root @test extman ] # chown -R postfix.postfix /var/www/extsuite/extman/cgi/

如果extman访问数据库权限不足的话,可采用以下命令将新生成的数据库赋予webman用户具有所有权限:
[root @test extman ] # /usr/local/mysql/bin/mysql
mysql> use extmail;
mysql> GRANT all privileges on extmail.* TO webman@localhost IDENTIFIED BY 'webman';
mysql> GRANT all privileges on extmail.* TO IDENTIFIED BY 'webman';

在apache的虚拟主机配置文件中Extmail的虚拟主机部分,添加如下两行:
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/html

启动所有服务:
[root @test root] # service mysqld start
[root @test root] # /usr/local/apache/bin/apachectl start
[root @test root] # service courier-authlib start
[root @test root] # service imapd start
[root @test root] # postfix start
在IE 浏览器中输入 ,进入邮件服务器的后台,添加域与添加用户邮箱。默认管理帐号为:  密码为:extmail*123*。我这里添加了一个 test.com 域和一个用户邮箱:test@test.com。至于开通邮件服务器自动注册邮箱服务,只需要编辑该域,将“允许自由注册邮箱”前面打上勾即可。

说明:
(1) 如果您安装后无法正常显示校验码,安装perl-GD模块会解决这个问题。如果想简单,您可以到以下地址下载适合您的平台的rpm包,安装即可:  
(2) extman-0.2.2自带了图形化显示日志的功能;此功能需要rrdtool的支持,您需要安装这些模块才可能正常显示图形日志。


接下来安装图形日志的运行所需要的软件包Time::HiRes、File::Tail和rrdtool,其中前两个包您可以去搜索并下载获得,后一个包您可以到 下载获得; 注意安装顺序不能改换。

12、安装Time::HiRes
[root @test root] # tar zxvf Time-HiRes-1.9707.tar.gz
[root @test root] # cd Time-HiRes-1.9707
[root @test Time-HiRes-1.9707] # perl Makefile.PL
[root @test Time-HiRes-1.9707] # make
[root @test Time-HiRes-1.9707] # make test
[root @test Time-HiRes-1.9707] # make install

13、安装File::Tail
[root @test root] # tar zxvf File-Tail-0.99.3.tar.gz
[root @test root] # cd File-Tail-0.99.3
[root @test File-Tail-0.99.3] # perl Makefile
[root @test File-Tail-0.99.3] # make
[root @test File-Tail-0.99.3] #make test
[root @test File-Tail-0.99.3] # make install
在安装 rrdtool 之前,就确定你的系统中是否已经安装 tcl、tcl-devel、libart、libart-devel,用下面的命令检查是否已经安装
[root @test File-Tail-0.99.3] # rpm -qa | grep tcl
[root @test File-Tail-0.99.3] # rpm -qa | grep libart
如果没有安装,将 RedHat AS 4.0 光碟放入光驱,挂载安装。注:相关的安装包在第3张碟和第4张碟中。
14、安装rrdtool-1.2.23
#tar zxvf rrdtool-1.2.23.tar.gz
#cd rrdtool-1.2.23
#./configure --prefix=/usr/local/rrdtool
#make
#make install

创建必要的符号链接(Extman会到这些路径下找相关的库文件)
#ln -sv /usr/local/rrdtool/lib/perl/5.8.5/i386-linux-thread-multi/auto/RRDs/RRDs.so   /usr/lib/perl5/5.8.5/i386-linux-thread-multi/
#ln -sv /usr/local/rrdtool/lib/perl/5.8.5/RRDp.pm   /usr/lib/perl5/5.8.5
#ln -sv /usr/local/rrdtool/lib/perl/5.8.5/i386-linux-thread-multi/RRDs.pm   /usr/lib/perl5/5.8.5

复制mailgraph_ext到/usr/local,并启动之
# cp -r /var/www/extsuite/extman/addon/mailgraph_ext  /usr/local  
# / usr/local/mailgraph_ext/mailgraph-init  start
# /usr/local/mailgraph_ext/qmonitor-init  start

添加到自动启动队列
echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.local
echo "/usr/local/mailgraph_ext/qmonitor-init start" >> /etc/rc.local

好了,接下来您就可以到extman的后台查看图表日志了。局部效果如下图:


测试 smtp
通过以下命令获得 的用户名和密码的BASE64        编码
获得用户名BASE64编码
[root @test root] # perl -e 'use MIME::Base64; print encode_base64("test\@test.com")'
dGVzdEB0ZXN0LmNvbQ==
获得密码BASE64编码
[root @test root] # perl -e 'use MIME::Base64; print encode_base64("test")'
dGVzdA==
[root @test root] # telnet localhost 25
3Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 Welcome to our mail.test.com ESMTP, Warning:Version not Available!
ehlo mail.test.com
250-mail.test.com
250-PIPELINING
250-SIZE 14336000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
dGVzdEB0ZXN0LmNvbQ==
334 UGFzc3dvcmQ6
dGVzdA==
235 2.0.0 Authentication successful
quit
221 2.0.0 Bye
Connection closed by foreign host.
测试 pop3
[root @test root] # telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Hello there.
user
+OK Password required.
pass test
+OK logged in.
quit
+OK Bye-bye.
Connection closed by foreign host.
注:以上蓝色部分是自己输入的命令。
测试 authlib
[root @test root] # /usr/local/courier-authlib/sbin/authtest -s login test
Authentication succeeded.

     Authenticated:   (uid 2525, gid 2525)
    Home Directory: /var/mailbox/test.com/test/Maildir/
           Maildir: /var/mailbox/test.com/test/Maildir/
             Quota: (none)
Encrypted Password: $1$OAWXcOO7$RrcGgF8UkY0MdjUaIYvdr.
Cleartext Password: test
           Options: (none)
启动所有服务:
[root @test root] # service mysqld start
[root @test root] # /usr/local/apache/bin/apachectl start
[root @test root] # service courier-authlib start
[root @test root] # service imapd start
[root @test root] # postfix start
至此,邮件系统算是基本成型,已经可以用邮件服务器收发邮件啦.
15、安装 maildorp
首先,将 courier-authlib 的头文件与库文件链接到 /usr 目录下,(编译 maildrop 时会此目录下寻找相关的文件)
[root @test root] # ln -s /usr/local/courier-authlib/bin/courierauthconfig /usr/bin
[root @test root] #  ln -s /usr/local/courier-authlib/include/* /usr/include
Maildrop 需要 pcre 的支持,接下来首先安装 pcre
[root @test root] # tar jxvf pcre-7.4.tar.bz2
[root @test root] # cd pcre-7.4
[root @test pcre-7.4] # ./configure
[root @test pcre-7.4] # make
[root @test pcre-7.4] # make install
开始安装 maildrop
[root @test pcre-7.4] # groupadd -g 1001 vmail
[root @test pcre-7.4] # useradd -g vmail -u 1001 -M -s /bin/nologin vmail
[root @test pcre-7.4] # cd
[root @test root] #  tar jxvf maildrop-2.0.2.tar.bz2
[root @test root] # cd maildrop-2.0.2
[root @test maildrop-2.0.2] #   ./configure --prefix=/usr/local/maildrop --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 @test maildrop-2.0.2] # make
[root @test maildrop-2.0.2] # make install
[root @test maildrop-2.0.2] # cp /usr/local/maildrop/bin/maildrop /usr/bin
运行 maildrop -v ,检查安装结果,请确保有“Courier Authentication Library extension enabled”这一句出现
[root @test maildrop-2.0.2] # maildrop -v
maildrop 2.0.2 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.
新建配置文件 /etc/maildroprc,首先指定 maildrop 的日志文件存放地点
[root @test maildrop-2.0.2] # vi /etc/maildroprc
添加:
logfile “/var/log/maildrop.log”
[root @test maildrop-2.0.2] # touch /var/log/maildrop.log
[root @test maildrop-2.0.2] # chown vmail.vmail /var/log/maildrop.log
配置 postfix,
编辑 /etc/postfix/master.cf
[root @test maildrop-2.0.2] # vi /etc/postfix/master.cf
启用下面这两行,将前面的注释符号去掉
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/local/maildrop/bin/maildrop -d ${recipient}
编辑 /etc/postfix/main.cf
[root @test maildrop-2.0.2] # vi /etc/postfix/main.cf

virtual_transport = virtual
修改为
virtual_transport = maildrop
编辑 authmysqlrc文件
[root @test maildrop-2.0.2] #  vi /usr/local/courier-authlib/etc/authlib/authmysqlrc

MYSQL_UID_FIELD         '2525'
MYSQL_GID_FIELD         '2525'
修改为
MYSQL_UID_FIELD         '1001’
MYSQL_GID_FIELD         '1001'
注意:如果没有修改此处,maildrop 可能会报“signal 0x06” 的错误报告
编辑 apache 的配置文件
[root @test maildrop-2.0.2] # vi /usr/local/apache/conf/httpd.conf

User postfix
Group postfix

修改成
User vmail
Group vmail
将用户邮件所在目录 /var/mailbox 和 extman 的临时目录 /tmp/extman 的属主和属组指定为 vmail
[root @test maildrop-2.0.2] # chown -R vmail.vmail /var/mailbox
[root @test maildrop-2.0.2] # chown -R vmail.vmail /tmp/extman
重新启动 apache 和 postfix
[root @test maildrop-2.0.2] # /usr/local/apache/bin/apachectl restart
如果没有重新启动 apache,将不能通过 web 收发邮件,提示如下错误:

[root @test maildrop-2.0.2] # postfix reload
安装 clamav
[root @test root] # groupadd clamav
[root @test root] # useradd -g clamav -s /sbin/nologin -M clamav
[root @test root] # groupadd amavis
[root @test root] # useradd -g amavis -s /sbin/nologin -M amavis
[root @test root] # tar xzvf clamav-0.91.2.tar.gz
[root @test root] #  cd clamav-0.91.2
[root @test clamav-0.91.2] # ./configure –prefix=/usr/local/clamav --disable-zlib-vcheck --disable-dns —disable-clamuko
[root @test clamav-0.91.2] # make
[root @test clamav-0.91.2] # make install
[root @test clamav-0.91.2] # vi /usr/local/clamav/etc/clamd.conf
# Example
LogFile /var/log/clamav/clamd.log
LogFileMaxSize 2M
LogTime yes
LogSyslog yes
LogVerbose yes
PidFile /var/run/clamd.pid
DatabaseDirectory /var/lib/clamav
LocalSocket /var/run/clamav/clamd.sock
MaxDirectoyRecursion 20
#=====================Executable Files==================
ScanPE yes
ScanELF yes
#=======================Documents=====================
ScanOLE2 yes
ScanPDF yes
#==================mail files====================
Scanmail yes
#=======================HTML========================
ScanHTML yes
#=======================Archives=======================
ScanArchive yes
ArchiveMaxFileSize 15M
ArchiveMaxRecursion 10
ArchiveMaxFiles 1500
ArchiveMaxCompressionRatio 300
[root @test clamav-0.91.2] # vi /usr/local/clamav/etc/freshclam.conf
/***这个要与 clamd.conf 里设置相同的目录
# Example
DatabaseDirectory /var/lib/clamav
UpdateLogFile /var/log/clamav/freshclam.log
LogVerbose yes
LogSyslog yes
PidFile /var/run/freshclam.pid
DatabaseMirror database.clamav.net
MaxAttempts 5
Check 24
HTTPProxyServer 192.168.98.8
HTTPProxyPort 80
ConnectTimeout 60
ReceiveTimeout 60
建立日志文件
[root @ test clamav-0.91.2] # mkdir –p /var/log/clamav
[root @ test clamav-0.91.2] # touch /var/log/clamav/clamd.log
[root @ test clamav-0.91.2] # touch /var/run/clamd.pid
[root @ test clamav-0.91.2] # touch /var/run/freshclam.pid
[root @ test clamav-0.91.2] # mkdir /var/lib/clamav
[root @ test clamav-0.91.2] # mkdir /var/run/clamav
[root @ test clamav-0.91.2] # chown –R amavis.amavis /var/log/clamav
[root @ test clamav-0.91.2] # chown –R clamav:clamav /var/run/clamd.pid /var/run/freshclam.pid
[root @ test clamav-0.91.2] # chown –R clamav:clamav /var/lib/clamav [root @ test clamav-0.91.2] #chown –R amavis.amavis /var/run/clamav
[root @ test clamav-0.91.2] # chmod -R 776 /var/run/clamav /var/lib/clamav
[root @ test clamav-0.91.2] # chmod –R 776 /var/log/clamd
[root @ test clamav-0.91.2] # chmod –R 776 /var/run/clamd.pid /var/run/freshclam.pid
[root @ test clamav-0.91.2] # crond -e
37 * * * * /usr/local/clamav/bin/freshclam
[root @ test clamav-0.91.2] # echo “/usr/local/clamav/lib” >> /etc/ld.so.conf
[root @ test clamav-0.91.2] # ldconfig
配置 clamav 开机自启动
[root @ test clamav-0.91.2] #  cp contrib/init/RedHat/clamd /etc/rc.d/init.d/clamd
[root @ test clamav-0.91.2] #  cp contrib/init/RedHat/clamav-milter /etc/rc.d/init.d/clamav-milter
[root @ test clamav-0.91.2] # chkconfig --add clamd
[root @ test clamav-0.91.2] #  chkconfig --add clamav-milter
[root @ test clamav-0.91.2] # chkconfig --level 345 clamd on
[root @ test clamav-0.91.2] # chkconfig —level 345 clamav-milter on
编辑 /etc/rc.d/init.d/clamd 文件,将服务进程的路径指向刚才安装 clamav 的目录
[root @ test clamav-0.91.2] # vi /etc/rc.d/init.d/clamd

progdir="/usr/local/sbin"
修改为
progdir="/usr/local/clamav/sbin"
[root @ test clamav-0.91.2] # service clamd start
安装 spamassassin
安装 spamassassin 需要很多 perl 模块的支持,
[root @ test clamav-0.91.2] # perl -MCPAN -e shell
/usr/lib/perl5/5.8.8/CPAN/Config.pm initialized.


CPAN is the world-wide archive of perl resources. It consists of about
100 sites that all replicate the same contents all around the globe.
Many countries have at least one CPAN site already. The resources
found on CPAN are easily accessible with the CPAN.pm module. If you
want to use CPAN.pm, you have to configure it properly.

If you do not want to enter a dialog now, you can answer 'no' to this
question and I'll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing 'o conf init' at the cpan prompt.)

Are you ready for manual configuration? [yes]
The following questions are intended to help you with the
configuration. The CPAN module needs a directory of its own to cache
important index files and maybe keep a temporary mirror of CPAN files.
This may be a site-wide directory or a personal directory.



First of all, I'd like to create this directory. Where?

CPAN build and cache directory? [/root/.cpan]
If you want, I can keep the source files after a build in the cpan
home directory. If you choose so then future builds will take the
files from there. If you don't want to keep them, answer 0 to the
next question.



How big should the disk cache be for keeping the build directories
with all the intermediate files?

Cache size for build directory (in MB)? [10]
By default, each time the CPAN module is started, cache scanning
is performed to keep the cache size in sync. To prevent from this,
disable the cache scanning with 'never'.

Perform cache scanning (atstart or never)? [atstart]
To considerably speed up the initial CPAN shell startup, it is
possible to use Storable to create a cache of metadata. If Storable
is not available, the normal index mechanism will be used.

Cache metadata (yes/no)? [yes]
The next option deals with the charset your terminal supports. In
general CPAN is English speaking territory, thus the charset does not
matter much, but some of the aliens out there who upload their
software to CPAN bear names that are outside the ASCII range. If your
terminal supports UTF-8, you say no to the next question, if it
supports ISO-8859-1 (also known as LATIN1) then you say yes, and if it
supports neither nor, your answer does not matter, you will not be
able to read the names of some authors anyway. If you answer no, names
will be output in UTF-8.

Your terminal expects ISO-8859-1 (yes/no)? [yes]
If you have one of the readline packages (Term::ReadLine::Perl,
Term::ReadLine::Gnu, possibly others) installed, the interactive CPAN
shell will have history support. The next two questions deal with the
filename of the history file and with its size. If you do not want to
set this variable, please hit SPACE RETURN to the following question.

File to save your history? [/root/.cpan/histfile]
Number of lines to save? [100]
The CPAN module can detect when a module that which you are trying to
build depends on prerequisites. If this happens, it can build the
prerequisites for you automatically ('follow'), ask you for
confirmation ('ask'), or just ignore them ('ignore'). Please set your
policy to one of the three values.

Policy on building prerequisites (follow, ask or ignore)? [ask]
The CPAN module will need a few external programs to work properly.
Please correct me, if I guess the wrong path for a program. Don't
panic if you do not have some of them, just press ENTER for those. To
disable the use of a download program, you can type a space followed
by ENTER.

Where is your gzip program? [/bin/gzip]
Where is your tar program? [/bin/tar]
Where is your unzip program? [/usr/bin/unzip]
Where is your make program? [/usr/bin/make]
Where is your links program? [/usr/bin/links]
Where is your wget program? [/usr/bin/wget]
Warning: ncftpget not found in PATH
Where is your ncftpget program? []
Warning: ncftp not found in PATH
Where is your ncftp program? []
Where is your ftp program? [/usr/kerberos/bin/ftp]
Where is your gpg program? [/usr/bin/gpg]
What is your favorite pager program? [/usr/bin/less]
What is your favorite shell? [/bin/bash]
Every Makefile.PL is run by perl in a separate process. Likewise we
run 'make' and 'make install' in processes. If you have any
parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass
to the calls, please specify them here.

If you don't understand this question, just press ENTER.

Parameters for the 'perl Makefile.PL' command?
Typical frequently used settings:

    PREFIX=~/perl       non-root users (please see manual for more hints)

Your choice:  []
Parameters for the 'make' command?
Typical frequently used setting:

    -j3              dual processor system

Your choice:  []
Parameters for the 'make install' command?
Typical frequently used setting:

    UNINST=1         to always uninstall potentially conflicting files

Your choice:  []
ometimes you may wish to leave the processes run by CPAN alone
without caring about them. As sometimes the Makefile.PL contains
question you're expected to answer, you can set a timer that will
kill a 'perl Makefile.PL' process after the specified time in seconds.

If you set this value to 0, these processes will wait forever. This is
the default and recommended setting.

Timeout for inactivity during Makefile.PL? [0]
If you're accessing the net via proxies, you can specify them in the
CPAN configuration or via environment variables. The variable in
the $CPAN::Config takes precedence.
Your ftp_proxy?  192.168.98.8
Your http_proxy?  192.168.98.8
Your no_proxy?
If your proxy is an authenticating proxy, you can store your username
permanently. If you do not want that, just press RETURN. You will then
be asked for your username in every future session.

Your proxy user id?
You have no /root/.cpan/sources/MIRRORED.BY
  I'm trying to fetch one
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
  
Fetching with LWP:
  
CPAN: Net::FTP loaded ok
Fetching with Net::FTP:
  
Fetching with Net::FTP:
  
Fetching with Net::FTP
  

Trying with "/usr/bin/links -source" to get
   
ELinks: 拒绝连接

Trying with "/usr/bin/links -source" to get
  
ELinks: 拒绝连接

Trying with "/usr/bin/wget -O -" to get
   
--18:39:55--  
           => `-'
Connecting to 192.168.98.8:80... 已连接。
已发出 Proxy 请求,正在等待回应... 200 OK
长度:144,241 (141K) [text/plain]
100%[====================================>] 144,241        6.81K/s    ETA 00:00

18:40:25 (6.74 KB/s) - `-' saved [144241/144241]



Now we need to know where your favorite CPAN sites are located. Push
a few sites onto the array (just in case the first on the array won't
work). If you are mirroring CPAN to your local workstation, specify a
file: URL.

First, pick a nearby continent and country (you can pick several of
each, separated by spaces, or none if you just want to keep your
existing selections). Then, you will be presented with a list of URLs
of CPAN mirrors in the countries you selected, along with previously
selected URLs. Select some of those URLs, or just keep the old list.
Finally, you will be prompted for any extra URLs -- file:, ftp:, or
http: -- that host a CPAN mirror.

(1) Africa
(2) Asia
(3) Central America
(4) Europe
(5) North America
(6) Oceania
(7) South America
Select your continent (or several nearby continents) []
Sorry! since you don't have any existing picks, you must make a
geographic selection.

(1)
(2)
(3)
Select as many URLs as you like (by number),
put them on one line, separated by blanks, e.g. '1 4 5' []
Enter another URL or RETURN to quit: []
New set of picks:

  


commit: wrote /usr/lib/perl5/5.8.8/CPAN/Config.pm
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support available (try 'install Bundle::CPAN')
cpan>














FAQ:
1、        查看 /var/log/maillog.出现authentication error: Input/output error错误的时候
Sep 17 22:06:45 redhat pop3d: authentication error: Input/output error
Sep 17 22:06:47 redhat pop3d: Connection, ip=[192.168.0.145]
Sep 17 22:06:47 redhat pop3d: LOGIN FAILED, user=test@test.com, ip=[192.168.0.145]
Sep 17 22:06:47 redhat pop3d: authentication error: Input/output error
Sep 17 22:06:47 redhat pop3d: Connection, ip=[192.168.0.145]
Sep 17 22:06:47 redhat pop3d: LOGIN FAILED, user=test@test.com, ip=[192.168.0.145]
Sep 17 22:06:47 redhat pop3d: authentication error: Input/output error
Sep 17 22:06:48 redhat pop3d: Connection, ip=[192.168.0.145]
Sep 17 22:06:48 redhat pop3d: LOGIN FAILED, user=test@yoyo.com, ip=[192.168.0.145]
Sep 17 22:06:48 redhat pop3d: authentication error: Input/output error
解决方法:估计是查询mysql时,authdaemond出错了。具体要打开authdaemonrc里的:

DEBUG_LOGIN=2    原来默认是0

然后看看/var/log/message或/var/log/maillog 在认证失败时有什么提示。根据提示去检查问题到底出在哪儿

2.warning: SASL authentication failure: cannot connect to Courier authdaemond: Permission denied
解决方法:检查 authdaemond的socket所在目录及其父目录的属性是否对smtpd可读。如果不可读则出现这个问题(permission的问题)。

3.warning: SASL authentication failure: cannot connect to Courier authdaemond: No such file or directory
解决方法:检查/usr/local/lib/sasl2/smtpd.conf,看看是否有多写一个空格,一般空格很难直观的发现.

4、查看 /var/log/maillog ,报如下错误:
Sep 17 16:04:56 redhat pop3d: chdir Maildir: No such file or directory
Sep 17 16:04:57 redhat pop3d: Connection, ip=[192.168.0.145]
Sep 17 16:04:57 redhat pop3d: chdir Maildir: No such file or directory
Sep 17 16:17:40 redhat postfix/smtpd[4481]: connect from unknown[192.168.0.145]
Sep 17 16:17:40 redhat postfix/smtpd[4481]: 434823F583: client=unknown[192.168.0.145], sasl_method=LOGIN, sasl_username=test@test.com
Sep 17 16:17:40 redhat postfix/cleanup[4488]: 434823F583: message-id=<007101c7f906$8135b890$9100a8c0@xp>
Sep 17 16:17:40 redhat postfix/qmgr[4275]: 434823F583: from=<>, size=1395, nrcpt=1 (queue active)
Sep 17 16:17:40 redhat postfix/smtpd[4481]: disconnect from unknown[192.168.0.145]
Sep 17 16:17:40 redhat postfix/virtual[4490]: 434823F583: to=<>, relay=virtual, delay=0.22, delays=0.15/0.05/0/0.02, dsn=2.0.0, status=sent (delivered to maildir)
Sep 17 16:17:40 redhat postfix/qmgr[4275]: 434823F583: removed

Sep 17 16:04:56 redhat pop3d: chdir Maildir: No such file or directory
Sep 17 16:04:57 redhat pop3d: Connection, ip=[192.168.0.145]
Sep 17 16:04:57 redhat pop3d: chdir Maildir: No such file or directory
解决方法:authmysqlrc 文件里 MYSQL_MAILDIR_FIELD 字段有空格。

5、错误提示如下
Sep 17 14:24:40 redhat postfix/trivial-rewrite[3378]: warning: do not list domain test.com in BOTH mydestination and virtual_mailbox_domains
解决方法:将 mydestination 设置为空即可,或完全注释也行

6、Oct  9 12:08:43 bv-diannao-004 postfix/postfix-script[12250]: warning: not set-g id or not owner+group+world executable: /usr/sbin/postdrop
解决方法:chmod g+s /usr/sbin/postdrop.其实这个没有多大影响,不设照样可以收发邮件,但总是看着不爽,还是解决了吧

7、Oct  9 13:29:50 bv-diannao-004 maildrop[13037]: Temporary authentication failure.
Oct  9 13:29:50 bv-diannao-004 postfix/pipe[13036]: 45DFE11CEE5: to=<>, relay=maildrop, delay=0.25, delays=0.1/0.05/0/0.1, dsn=4.3.0, status=deferred (temporary failure. Command output: ERR: authdaemon: s_connect() failed: Permission denied /usr/local/bin/maildrop: Temporary authentication failure.
解决方法:说明编译 authlib 时没有指定 maildrop 用户和组,加上 —with-mailuser 和 —with-mailgroup 参数指定用户和组后重新编译安装

8、Oct  9 16:07:26 bv-diannao-004 authdaemond: failed to connect to mysql server (server=localhost, userid=extmail..): Access denied for user 'extmail..'@'localhost' (using password: YES)
Oct  9 16:07:26 bv-diannao-004 authdaemond: authmysql: TEMPFAIL - no more modules will be tried
解决方法: authdaemond: failed to connect to mysql server (server=localhost, userid=extmail..): Access denied for user 'extmail..'@'localhost' (using password: YES)
检查 /usr/local/courier-authlib/etc/authlib/authmysqlrc 中的 MYSQL_USERNAME 参数中的值是否输入错误,出现 userid=extmail.. 可能原因是 extmail 后面存在空格,将空格删除,使用 service courier-authlib restart 命令重新启 动 authdaemond

10、
# 下面是一封邮件发送的过程日志,
Oct 10 09:59:16 bv-diannao-004 authdaemond: Authenticated: sysusername=, sysuserid=2525, sysgroupid=2525, homedir=/var/mailbox/test.com/test/Maildir/, address=test@test.com, fullname=test, maildir=/var/mailbox/test.com/test/Maildir/, quota=, options=
# 验证用户的地址,UID、GID、Maildir
Oct 10 09:59:16 bv-diannao-004 authdaemond: Authenticated: clearpasswd=test, passwd=$1$OAWXcOO7$RrcGgF8UkY0MdjUaIYvdr.
# 红色部分表示用户的密码
Oct 10 09:59:16 bv-diannao-004 postfix/smtpd[3938]: E5FD411CED0: client=unknown[192.168.101.224], sasl_method=LOGIN, sasl_username=test@test.com
# 进行 sasl 验证
Oct 10 09:59:16 bv-diannao-004 postfix/cleanup[3946]: E5FD411CED0: message-id=<001001c80ae0$c8143a20$e065a8c0@cftest>
# 给邮件在 postfix  队列里编号
Oct 10 09:59:17 bv-diannao-004 postfix/qmgr[1954]: E5FD411CED0: from=<>, size=1538, nrcpt=1 (queue active)
# 进入 postfix 的队列
Oct 10 09:59:17 bv-diannao-004 postfix/smtpd[3938]: disconnect from unknown[192.168.101.224]
Oct 10 09:59:17 bv-diannao-004 postfix/virtual[3948]: E5FD411CED0: to=<>, relay=virtual, delay=0.13, delays=0.09/0.02/0/0.02, dsn=2.0.0, status=sent (delivered to maildir)
Oct 10 09:59:17 bv-diannao-004 postfix/qmgr[1954]: E5FD411CED0: removed
# 红色部分表示中转的方式,这里采用的是 virtual
#  下面几行是用 pop 收邮件的过程日志,
Oct 10 09:59:22 bv-diannao-004 pop3d: Connection, ip=[192.168.101.224]
# 客户端连接 pop 服务器
Oct 10 09:59:22 bv-diannao-004 pop3d: LOGIN, user=test@test.com, ip=[192.168.101.224]
# 客户端登录到 pop 服务器
Oct 10 09:59:22 bv-diannao-004 authdaemond: received auth request, service=pop3, authtype=login
# pop 服务器收到用户的验证请求
Oct 10 09:59:22 bv-diannao-004 authdaemond: authmysql: trying this module
# pop 服务器启动验证模块
Oct 10 09:59:22 bv-diannao-004 authdaemond: SQL query: SELECT username, password, "", '2525', '2525', concat('/var/mailbox/',Maildir), concat('/var/mailbox/',Maildir), "", name, "" FROM mailbox WHERE username = "test@test.com"
# 查询 mysql 服务器,进行验证
Oct 10 09:59:22 bv-diannao-004 authdaemond: password matches successfully
# 密码验证成功

11、在编译完 postfix 时,安装 postfix 安装文件时,当进行到 :
config_directory: [/etc/postfix]
daemon_directory: [/usr/libexec/postfix]
command_directory: [/usr/sbin]
queue_directory: [/var/spool/postfix]
sendmail_path: [/usr/sbin/sendmail]
newaliases_path: [/usr/bin/newaliases]
mailq_path: [/usr/bin/mailq]
mail_owner: [postfix]
setgid_group: [postdrop]   
html_directory: [no]
manpages: [/usr/local/man]   
readme_directory: [no]
时,在默认选项 [] 中没有内容显示,手工添加也不行
解决方法:这是因为 postfix 找不到 mysql 的库文件所引起,解决步骤如下:
# mkdir /usr/local/mysql/lib/mysql
# ln -s /usr/local/mysql/lib/* /usr/local/mysql/lib/mysql
# echo “/usr/local/mysql/lib/mysql“ >> /etc/ld.so.conf

12、在编译 courier-authlib 时出现 configure: error: --with-authmysql specified but no mysqlclient.so
解决方法:将 redhat 4.0 第四张安装光盘挂载上去,安装 mysql-devel 即可:
rpm -ivh mysql-devel-4.1.10a-2.RHEL4.1.i386.rpm


附录:
DNS 服务器的配置
     DNS 服务器采用的是系统自带的,如果在安装系统的时候没有选中安装的话,现在可以将 RedHat AS4.0 的安装光碟拿出来(具体哪一张光碟我也不知道,我个人用的系统都是在安装的时候全选。),mount 上去,然后 rpm.安装过程这里就免了
首先修改 /etc/named.conf  文件
[root @ test root] # vi /etc/named.conf
其它的不用改,在文件中添加如下几行
zone "test.com" IN {
        type master;
        file "test.zone";
        allow-update { none; };
};

zone "98.168.192.in-addr.arpa" IN {
        type master;
        file "test.local";
        allow-update { none; };
};
然后保存退出
在  /var/named/chroot/var/named/ 目录下创建 test.zone & test.lcoal 文件,然后编辑,test.zone 文件内容如下:
$TTL    86400
@               IN SOA  bv-diannao-004.test.com.  root.test.com. (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum

                        IN NS           bv-diannao-004.test.com.
                        IN A            192.168.98.204
test.com.               IN MX                          10 mail.test.com.
bv-diannao-004          IN A                      192.168.98.204
mail                    IN A                      192.168.98.204
cf-test                         IN A                      192.168.101.224
www                     IN CNAME                  bv-diannao-004.test.com.

test.local  文件内容如下:
$TTL    86400
@               IN SOA  bv-diannao-004.test.com.  root.test.com. (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum

                        IN NS     bv-diannao-004.test.com.
204                            IN PTR    mail.test.com.
204                     IN PTR    bv-diannao-004.test.com.
224.101.168.192         IN PTR    cf-test.test.com.
注:具体的值可根据自己的实际情况进行更改,这里我就不一一介绍了。如果不明白的地方,大家可以参考相关的 DNS 的资料。
然后将这两个文件链接到 /var/named 目录下
[root @ test root] # ln -s /var/named/chroot/var/named/test.zone /var/named/test.zone
[root @ test root] # ln -s /var/named/chroot/var/named/test.local /var/named/test.local
启动 DNS 服务
[root @ test root] #  service named start
查看  DNS 端口是否处于监听状态,如果看到端口 53 处于监听状态,就表明 DNS 服务正常启动。
[root @ test root] # netstat -tlunp
用 nslookup 测试 DNS 服务是否正常
[root @ test root] # nslookup mail.test.com
Server:         192.168.98.204
Address:        192.168.98.204#53

Name:   mail.test.com
Address: 192.168.98.204
以上输出显示正常,mail.test.com 的 ip 地址就是 192.168.98.204
 
 
 
本人一直想自己做做试试,不过还是没付诸行动 !有时间自己一定试试,也对的起作者的一翻苦心!有什么问题大家可以去原载论坛查看,也有相应资料下载。
 
另有一篇不错的文章:基于 CentOS 4.6 下的邮件服务器安装
(本人也架设通过)
 
阅读(4682) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

dongyi05162008-05-07 16:03:59

呵呵,谢谢你的文章