当前位置: 首页 > 工具软件 > Courier-MTA > 使用案例 >

RedHat Enterprise 5.4 搭建完整Postfix 邮件服务器(courier-imap,courier-authlib,extmail,extman)

季阳朔
2023-12-01

导师让搭建一个邮件服务器,上网搜了一些教程,但是都有错误,在我三天半的努力下终于搭建完毕,向写那些教程的前辈表示感谢,以下是我的总结。

 !!!!!!!!!!!!!!!!!!!!!!(authmysql.so和athlib连接mysql的配置文件中用户名之后的空格千万注意,害我不浅阿)

一.安装 postfix 邮件服务器所需的软件列表:(一下软件用新点版本也行)
RedHat as 4.0
RedHat 高级服务器操作系统
2、Postfix
这一个是自然少不了的,邮件服务器系统的 smtp 服务器,在邮件服务器系统中充当MTA角色。软件版本:postfix-2.4.5
下载地址:
http://www.postfix.org/download.html
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
下载地址:
http://www.apache.org
5、php
Extman & extmail 需要使用 php.作用版本:php-5.2.3
下载地址:
http://www.php.net
6、cyrus-sasl
用于实现身份验证的smtp 服务器,使用版本:cyrus-sasl-2.1.22
下载地址:
http://download.chinaunix.net/download/0001000/71.shtml
7、courier-authlib
实现带验证的 pop3 服务器,使用版本:courier-authlib-0.58
下载地址:
http://download.chinaunix.net/download/0002000/1788.shtml
8、courier-imap
用于实现 pop3、imap 收邮件功能,使用版本: courier-imap-4.1.0
下载地址:
http://download.chinaunix.net/do ...6&Resourceid=77
9、openssl
提供安全的邮件服务器连接,使用版本:openssl-0.9.8e
下载地址:
http://www.openssl.org/source
10、extman
用于邮件服务器的后台管理,使用版本:extman-0[1].2.2
下载地址:
http://www.extmail.org
11、extmail
用于实现 webmail.使用版本:extmail-1[1].0.2
下载地址:
http://www.extmail.org
12、DBD-Mysql
用于解决依赖关系,extmail 将会用到,使用版本:DBD-Mysql-3.0002_4
下载地址:
http://search.cpan.org
13、Unix-Syslog
用于解决依赖关系,extmail 将会用到,使用版本:Unix-Syslog-0.100
下载地址:
http://search.cpan.org
14、BerkeleyDB
使用版本:BerkeleyDB-4.5.20
下载地址:
http://www.oracle.com/technology ...keley-db/index.html

 

二.邮件服务器系统的安装
本文约定:默认情况下,本文中的所有软件的压缩安装文件都放在 /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 isenforced.
    permissive - SELinux prints warnings instead ofenforcing.
    disabled - SELinux is fully disabled.
将 SELINUX=enforcing
改成
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
    targeted - Only targeted network daemons areprotected.
    strict - Full SELinux protection.
SELINUXTYPE=targeted
Selinux 是 linux 系统中一个强制性的安全机制,但也带来了不少麻烦,为了避免不必要的麻烦,还是先关了吧。我之前在Fedora cora 5 上安装邮件服务器时就因为没有关掉 selinux ,而苦恼了一段时间。

 

1.安装 mysql服务器(这才是真正的数据库)

下载一个MySQL-server-community-5.1.44-1.rhel5.i386.rpm
[root @test root]#rpm -vihMySQL-server-community-5.1.44-1.rhel5.i386.rpm

 

安装 mysql客户端(提供mysql等命令和库文件的)
添加虚帐户mysql 并同时产生一个 mysql 组。注:如果系统中已有就不必添加了。
[root @test root]#groupadd  mysql
[root @test root]# useradd -g mysql mysql
解压缩mysql 安装文件
[root @test local]#tar xvzf mysql-5.0.45-linux-i686.tar.gz
[root @test local]#cd mysql-5.0.45
[root @test local]# ./configure --prefix=/usr/local/mysql

[root @test local]# make

[root @test local]# make install

[root @test local]# chown -R mysql:mysql /var/lib/mysql
初始化 mysql 数据库
[root @testlocal]#./script/mysql_install_db  —user=mysql&
修改目录所有权限为mysql 所有
[root @test local]#chown -R root .
[root @test local]#chown -R mysql:mysql data
[root @test local]#chgrp -R mysql .
       注:将/var/lib/mysql/mysql.sock链接到 /tmp 目录下,并保持名称不变,如果不这样做的话,有时候可能mysql 启动时会报错,如 ERROR 200:Can’tconnect to local MYSQL server throuht socket /tmp/mysql.sock.
[root @test local]#ln -s /var/lib/mysql/mysql.sock /tmp/
启动测试mysql
[root @test local]#/usr/local/mysql/bin/safe_mysqld —user= mysql&
复制一个编译目录的脚本,以使 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/ls.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 tofile'/var/run/mysqld/mysqld.pid' (Errcode: 13)
070829  9:04:08 [ERROR] Can'tstart server: can't create PID file: Permission denied
070829 09:04:08  mysqldended
       根据日志提示,查看/var/run/mysqld 目录,发现该目录下并没有mysqld.pid文件,查看该目录的文件权限,发现用户所有者即不属于root ,也不属于mysql ,文件所有者显示为27。据此推断,可能是mysql启动时会向此文件夹内写一些东西,但 mysql 的进程用户mysql 却没有权限写,导致mysql 无法启动,用touch/var/run/mysqld/mysqld.pid 命令创建mysql 所需要文件,chown -Rmysql: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 中发现,我在 RHEL5.4 中安装 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] # lconfig
检查是否安装 openssl
[root @ test openssl-0.9.8e] # openssl version
OpenSSL 0.9.8e 23 Feb 2007

 

3、安装 cyrus-sasl
[root @ test root] # tar 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
postfix2.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 shadowpam">>/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--sysconfdir=/etc/httpd --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] # echo "/usr/local/apache/bin/apachectlstart" >>/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] # cpphp.ini-dist  /usr/local/php/lib/php.ini
注:编辑apache配置文件httpd.conf,以apache支持php
[root @ test php-5.2.3] # vi /etc/httpd/httpd.conf
# 添加如下二行
  AddTypeapplication/x-httpd-php  .php
  AddTypeapplication/x-httpd-php-source  .phps
# 定位至DirectoryIndex index.html
  修改为:
  DirectoryIndex  index.php  index.html

 

7、安装 postfix
[root @ test root] # groupadd -g 2525 postfix
[root @ test root] # useradd -g postfix -u 2525 -s /sbin/nologin -Mpostfix
[root @ test root] # groupadd -g 2526 postdrop
[root @ test root] # useradd -g postdrop -u 2526 -s /bin/false -Mpostdrop
[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]

上面的选项全部保持默认,直接回车即可。

 

注:以上几步可能会说找不到libmysqlclient.so.15,只要在postfix目录下搜索libmysqlclient.so.15,把libmysqlclient.so.15拷一个放/usr/lib或者把libmysqlclient.so.15的路径加到ld.so.conf里ldconfig下就OK生成别名二进制文件,这个步骤如果忽略,会造成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 = 59.64.0.0/16, 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 hasoverdrawn his diskspace quota,please Tidy your mailbox and tryagain 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:Versionnot 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] #   vimysql_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 jxvfcourier-authlib-0.58.tar.bz2
[root @ test root] #  cdcourier-authlib-0.58
[root @ test courier-authlib-0.58]#./configure    --prefix=/usr/local/courier-authlib    --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/inculde/mysql --with-redhatCFLAGS="-march=i686 -O2 -fexpensive-optimizations"CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations"--with-authmysql=/usr/local/mysql/lib/mysql

[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/localcourier-authlib/etc/authdaemonrc.dist  /usr/localcourier-authlib/etc/authdaemonrc
# cp/usr/localcourier-authlib/etc/authmysqlrc.dist  /usr/localcourier-authlib/etc/authmysqlrc
修改/etc/authdaemonrc 文件
[root @ test courier-authlib-0.58] # vi/usr/localcourier-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/localcourier-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 —addcourier-authlib
[root @ test courier-authlib-0.58] # chkconfig —level 2345courier-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-authlibstart   (启动服务)

 

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-uthlib/include'  LDFLAGS='-L/usr/local/courier-authlib/lib/courier-authlib' COURIERAUTHCONFIG='/usr/local/courier-authlib/bin/courierauthconfig'CFLAGS='-I/usr/local/courier-authlib/include'

[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 @ testcourier-imap-4.1.3]  # vi/usr/local/imap/etc/pop3d
POP3DSTART=YES
注:如果你想为用户提供IMAP服务,则需在"/usr/local/imap/etc/imapd"文件中设置"IMAPDSTART=yes";其它类同;
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
[root @ testcourier-imap-4.1.3]  # mkdir –p/var/mailbox
[root @ testcourier-imap-4.1.3]  #chown –Rpostfix /var/mailbox
[root @ testcourier-imap-4.1.3]  # cpcourier-imap.sysvinit /etc/rc.d/init.d/courier-imapd
[root @ testcourier-imap-4.1.3]  # chmod 755/etc/rc.d/init.d/imapd
[root @ testcourier-imap-4.1.3]  # chkconfig—addimapd
[root @ testcourier-imap-4.1.3]  # chkconfig—level 2345 imapd on
[root @ testcourier-imap-4.1.3]  # servicecourier-imapd start
接下来重新配置SMTP 认证,编辑 /usr/local/lib/sasl2/smtpd.conf ,确保其为以下内容:
[root @ testcourier-imap-4.1.3]  # vi/usr/locla/lib/sasl2/smtpdconf
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/extmailwebmail.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 /etc/httpd/httpd.conf
将 User daemon
       Groupdaemon
改为
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(不安装ms也行)和Unix::syslogd功能,DBD::Mysql直接用cpan命令安装,另一个可以您可以去
http://search.cpan.org
搜索下载原码包进行安装。
[root @ test root] # tar zxvfDBD-mysql-3.0002_4.tar.gz  
[root @ test root] # cd DBD-mysql-3.0002_4
[root @ test DBD-mysql-3.0002_4] # perlMakefile.PL   (此步骤中如果出现类同Can'texec "mysql_config": No such file or directory at Makefile.PL line76.的错误是因为您的mysql的bin目录没有输出至$PATH环境变量)
[root @ test DBD-mysql-3.0002_4] # make(又一个错误,但是不影响安装)
[root @ test DBD-mysql-3.0002_4] # make install
好了,到此为止,您的Webmail已经可以使用了,可以在浏览器中输入指定的虚拟主机的名称进行访问,如下:
http://mail.test.com
注:要在 DNS 服务器已经配置好,并运行正常的情况下才可以用域名访问,如果没有配置 DNS 服务,直接输入 IP就行了(通过修改hosts也可以)

11、安装Extman-0.2.2
安装及基本配置
[root @ test root] #tarzxvf  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
[root @test extman ] # mysql -u root -p<extmail.sql;

[root @test extman ] # mysql -u root -p<init.sql;
mysql> GRANT all privileges on extmail.* TOwebman@localhost IDENTIFIED BY 'webman';
mysql> GRANT all privileges on extmail.* TO
webman@127.0.0.1
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 浏览器中输入
http://mail.test.com/extman
,进入邮件服务器的后台,添加域与添加用户邮箱。默认管理帐号为:
root@extmail.org
  密码为:extmail*123*。我这里添加了一个test.com域和一个用户邮箱:test@test.com。至于开通邮件服务器自动注册邮箱服务,只需要编辑该域,将“允许自由注册邮箱”前面打上勾即可。
说明:
(1)如果您安装后无法正常显示校验码,安装perl-GD模块会解决这个问题。通过cpan命令安装即可。也可以到以下地址下载适合您的平台的rpm包:  
http://dries.ulyssis.org/rpm/packages/perl-GD/info.html

(2)不知为什么,extman登录时,老是提示验证码错误,我搜了一下,把验证码去掉了

extmail 后台管理验证码解决

vi /var/www/extsuite/extman/webman.cf

不要验证码:
将:SYS_CAPTCHA_ON = 1
改为:SYS_CAPTCHA_ON = 0

更改验证码位数:

将:SYS_CAPTCHA_LEN = 6
改为:SYS_CAPTCHA_LEN = 2

更改验证码键值:

SYS_CAPTCHA_KEY = kjjas!23#$#5xSw (此处顺便输入)

(3)extman-0.2.2自带了图形化显示日志的功能;此功能需要rrdtool的支持,您需要安装此些模块才可能正常显示图形日志。
接下来安装图形日志的运行所需要的软件包Time::HiRes、File::Tail和rrdtool,其中前两个包可以通过cpan命令安装,后一个包您可以到
http://oss.oetiker.ch/rrdtool/pub/?M=D
在安装 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张碟中。
安装rrdtool-1.2.23
[root @test File-Tail-0.99.3]#tar zxvf rrdtool-1.2.23.tar.gz
[root @test File-Tail-0.99.3]#cd rrdtool-1.2.23
[root @test File-Tail-0.99.3]#./configure--prefix=/usr/local/rrdtool
[root @test File-Tail-0.99.3]#make
[root @test File-Tail-0.99.3]#make install
创建必要的符号链接(Extman会到这些路径下找相关的库文件)
[root @test File-Tail-0.99.3]#ln -sv/usr/local/rrdtool/lib/perl/5.8.5/i386-linux-thread-[root @testFile-Tail-0.99.3]multi/auto/RRDs/RRDs.so  /usr/lib/perl5/5.8.5/i386-linux-thread-multi/
[root @test File-Tail-0.99.3]#ln -sv/usr/local/rrdtool/lib/perl/5.8.5/RRDp.pm  /usr/lib/perl5/5.8.5
[root @test File-Tail-0.99.3]#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,并启动之
[root @test File-Tail-0.99.3]# cp -r/var/www/extsuite/extman/addon/mailgraph_ext  /usr/local  
[root @test File-Tail-0.99.3]# /usr/local/mailgraph_ext/mailgraph-init  start
[root @test File-Tail-0.99.3]#/usr/local/mailgraph_ext/qmonitor-init  start
添加到自动启动队列
[root @test File-Tail-0.99.3]# echo"/usr/local/mailgraph_ext/mailgraph-init start">> /etc/rc.local
[root @test File-Tail-0.99.3]# echo"/usr/local/mailgraph_ext/qmonitor-init start">> /etc/rc.local
好了,接下来您就可以到extman的后台查看图表日志了。局部效果如下图:
测试 smtp
通过以下命令获得
test@test.com
的用户名和密码的BASE64      编码
获得用户名BASE64编码
[root @test root] # perl -e 'use MIME::Base64; printencode_base64("test\@test.com")'
dGVzdEB0ZXN0LmNvbQ==
获得密码BASE64编码
[root @test root] # perl -e 'use MIME::Base64; printencode_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 notAvailable!
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
test@test.com
+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 -slogin
test@test.com
test
Authentication succeeded.
    Authenticated:
test@test.com
  (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
至此,邮件系统算是基本成型,已经可以用邮件服务器收发邮件啦.
FAQ:
查看 /var/log/maillog.出现authentication error: Input/outputerror错误的时候
Sep 17 22:06:45 redhat pop3d: authentication error: Input/outputerror
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/outputerror
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/outputerror
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/outputerror
解决方法:估计是查询mysql时,authdaemond出错了。具体要打开authdaemonrc里的:
DEBUG_LOGIN=2    原来默认是0
然后看看/var/log/message或/var/log/maillog在认证失败时有什么提示。根据提示去检查问题到底出在哪儿
2.warning: SASL authentication failure: cannot connect to Courierauthdaemond: Permission denied
解决方法:检查authdaemond的socket所在目录及其父目录的属性是否对smtpd可读。如果不可读则出现这个问题(permission的问题)。
3.warning: SASL authentication failure: cannot connect to Courierauthdaemond: 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 ordirectory
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 ordirectory
Sep 17 16:17:40 redhat postfix/smtpd[4481]: connect fromunknown[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=
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 fromunknown[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 ordirectory
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 ordirectory
解决方法:authmysqlrc 文件里 MYSQL_MAILDIR_FIELD 字段有空格。
5、错误提示如下
Sep 17 14:24:40 redhat postfix/trivial-rewrite[3378]: warning: donot list domain test.com in BOTH mydestination andvirtual_mailbox_domains
解决方法:将 mydestination 设置为空即可,或完全注释也行

 

附录:
DNS 服务器的配置
 

   DNS服务器采用的是系统自带的,如果在安装系统的时候没有选中安装的话,现在可以将 RedHat AS4.0的安装光碟拿出来(具体哪一张光碟我也不知道,我个人用的系统都是在安装的时候全选。),mount 上去,然后rpm.安装过程这里就免了
首先修改 /etc/named.conf  文件
[root @ test root] # vi /etc/named.conf
其它的不用改,在文件中添加如下几行
zone "test.com" IN {
       typemaster;
       file"test.zone";
       allow-update{ none; };
};
zone "98.168.192.in-addr.arpa" IN {
       typemaster;
       file"test.local";
       allow-update{ none; };
};
然后保存退出
在  /var/named/chroot/var/named/目录下创建 test.zone & test.lcoal 文件,然后编辑,test.zone文件内容如下:
$TTL    86400
          INSOA  bv-diannao-004.test.com.  root.test.com.(
                            42           ; serial (d.adams)
                            3H           ;refresh
                            15M           ;retry
                            1W           ;expiry
                             1D)          ;minimum
                  INNS         bv-diannao-004.test.com.
                  INA         192.168.98.204
test.com.            INMX                   10mail.test.com.
bv-diannao-004        INA                192.168.98.204
mail               INA                192.168.98.204
cf-test                   INA                192.168.101.224
www                INCNAME             bv-diannao-004.test.com.
test.local  文件内容如下:
$TTL    86400
          INSOA  bv-diannao-004.test.com.  root.test.com.(
                            42           ; serial (d.adams)
                            3H           ;refresh
                            15M           ;retry
                            1W           ;expiry
                             1D)          ;minimum
                  INNS    bv-diannao-004.test.com.
204                     INPTR    mail.test.com.
204                INPTR   bv-diannao-004.test.com.
224.101.168.192       INPTR    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] #  servicenamed 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

主要的参考文献地址:
http://bbs.winos.cn/thread-20878-1-1.html


 类似资料: