安装与配置工作:

1、 安装并配置MYSQL:

(1)安装mysql

# tar -zxvf mysql-5.1.49.tar.gz
# cd mysql-5.1.49
# groupadd mysql
# useradd -g mysql -s /sbin/nologin -M mysql
# ./configure --prefix=/usr/local/mysql --with-charset=gbk --with-extra-charsets=all --enable-thread-safe-client --enable-local-infile --with-low-memory
# make && make install
# cp support-files/my-medium.cnf  /etc/my.cnf
# chown -R mysql.mysql /usr/local/mysql/
# /usr/local/mysql/bin/mysql_install_db --user=mysql
# chown -R mysql.mysql /usr/local/mysql/var/

(2)启动数据库服务,并添加到自启动

# /usr/local/mysql/bin/mysqld_safe --user=mysql &
# cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig  --levels  345  mysqld  on

(3)配置库文件搜索路径

# echo "/usr/local/mysql/lib/mysql">>/etc/ld.so.conf
# ldconfig
#echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
#source /etc/profile

(4)添加root密码

# /usr/local/mysql/bin/mysqladmin -u root password "xxttest"

2、 安装apache

安装Apache有两个要注意的地方,因为我这里用的Postfix的后台管理是extman这个程序,而它是通过CGI的方式来进行管理的,所以这里启用了suexec的功能,还有一个是关于网站的存放路径的,如果不指定,那么在启用suexec后会出现 suexec-docroot的错误。

(1) 安装apache

#tar -jxvf httpd-2.2.9.tar.bz2

#cd httpd-2.2.9

#./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-mods-shared=all --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/var/www

#make

#make install

(2) 修改apache配置文件

#vi /usr/local/apache2/conf/httpd.conf  
找到DocumentRoot “/usr/local/apache2/htdocs”
修改为:DocumentRoot “/var/www”(后文中我们还会注释掉此行,以启用虚拟主机)
找到<Directory “/usr/local/apache2/htdocs”>
修改为:<Directory “/var/www”>
找到
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all        //这句改为Allow from all
</Directory>

启动apache
#/usr/local/apache2/bin/apachectl start

(3) 添加系统服务和自启动
# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd

# vi /etc/rc.d/init.d/httpd

添加(#!/bin/sh下面)

# chkconfig: 2345 10 90

# description: Activates/Deactivates Apache Web Server

然后添加为系统服务和开机器自启动

# chkconfig --add httpd

# chkconfig httpd on

3、 安装PHP

(1)安装PHP

# tar -zxvf php-5.2.6.tar.gz
# cd php-5.2.6
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php --with-zlib --enable-mbstring=all
# make && make install
# cp php.ini-dist /usr/local/php/php.ini

(2)配置PHP

# vi /usr/local/apache2/conf/httpd.conf
添加:
AddType application/x-httpd-php .php

AddType application/x-httpd-php .php3

AddType application/x-httpd-php .phtml

找到DirectoryIndex index.html
修改为DirectoryIndex index.html index.php

(4) 修改selinux,启动apache

# setenforce 0

# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache2/modules/libphp5.so

# service httpd restart
# setenforce 1

如果不修改会提示:

httpd: Syntax error on line 105 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

4、 安装courier-authlib

(1) 首先需要安装expect:

yum install expect

(2) 安装courier-authlib

#groupadd -g 1000 vmail

#useradd -g 1000 -u 1000 -M -s /sbin/nologin vmail

# tar -jxvf courier-authlib-0.62.4.tar.bz2

# cd courier-authlib-0.62.4

#./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --sysconfdir=/etc --without-authuserdb --without-authpam --without-authldap --without-authpwd --without-authshadow --without-authvchkpw --without-authpgsql --without-authcustom --with-authmysql --with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-includes=/usr/local/mysql/inculde/mysql --with-redhat --with-mailuser=vmail --with-mailgroup=vmail

# make && make install

# make install-migrate

# make install-configure

更新lib库文件搜索路径

# echo "/usr/local/courier-authlib/lib/courier-authlib/"&gt;&gt;/etc/ld.so.conf

# ldconfig

(3) 修改配置文件

# vi /etc/authlib/authdaemonrc

authmodulelist="authmysql"

authmodulelistorig="authmysql"

daemons=10

DEBUG_LOGIN=2

# vi /etc/authlib/authmysqlrc

修改以下内容

MYSQL_SERVER localhost

MYSQL_USERNAME extmail

MYSQL_PASSWORD extmail

MYSQL_SOCKET /tmp/mysql.sock

MYSQL_PORT 3306

MYSQL_DATABASE extmail

MYSQL_USER_TABLE mailbox

MYSQL_CRYPT_PWFIELD password

MYSQL_UID_FIELD "1000"

MYSQL_GID_FIELD "1000"

MYSQL_LOGIN_FIELD username

MYSQL_HOME_FIELD concat("/var/mailbox/",homedir)

MYSQL_MAILDIR_FIELD concat("/var/mailbox/",maildir)

MYSQL_QUOTA_FIELD concat(quota,"S")

(4) 启动及加入到自动运行队列

# cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib

# chmod 755 /etc/rc.d/init.d/courier-authlib

# chkconfig --add courier-authlib

# chkconfig courier-authlib on

# service courier-authlib start

# chmod a+x /usr/local/courier-authlib/var/spool/authdaemon

5、 安装courier-imap

(1) 安装courier-imap

# tar -jxvf courier-imap-4.8.0.tar.bz2

# cd courier-imap-4.8.0

# ./configure --prefix=/usr/local/courier-imap --with-redhat --enable-unicode --disable-root-check --with-trashquota --without-ipv6 COURIERAUTHCONFIG="/usr/local/courier-authlib/bin/courierauthconfig"

# make && make install

# make install-configure

(2) 编辑配置文件启用pop3及imap

# vi /usr/local/courier-imap/etc/pop3d

修改POP3DSTART=NO

POP3DSTART=YES

# vi /usr/local/courier-imap/etc/imapd

修改IMAPDSTART=NO

IMAPDSTART=YES

(3) 启动及加入自动运行队列

# cp courier-imap.sysvinit /etc/rc.d/init.d/courier-imapd

# chmod 755 /etc/rc.d/init.d/courier-imapd

# chkconfig --add courier-imapd

# chkconfig courier-imapd on

# service courier-imapd start

6、 安装cyrus-sasl

(1) 先卸载本机自带的sasl

# rpm -qa |grep cyrus-sasl |xargs rpm -e --nodeps

# rm -rf /usr/lib/sasl

# rm -rf /usr/lib/sasl2

(2) 安装cyrus-sasl

# tar -zxvf cyrus-sasl-2.1.22.tar.gz

# cd cyrus-sasl-2.1.22

# ./configure --enable-plain --enable-cram --enable-digest --enable-login --enable-sql --disable-anon --disable-ntlm --disable-gssapi --disable-krb4 --disable-otp --disable-srp --disable-srp-setpass --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

# make && make install

(3) 共享链接库

# ln -sv /usr/local/lib/sasl2 /usr/lib/sasl2

# echo "/usr/local/lib"&gt;&gt;/etc/ld.so.conf

# ldconfig

(4) 建立smtpd用户认证的配置文件

# vi /usr/local/lib/sasl2/smtpd.conf

pwcheck_method: saslauthd

mech_list: plain login

log_level:3

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

(5) 创建运行时需要的目录

# mkdir -pv /var/state/saslauthd

(6) 启动并测试

# /usr/local/sbin/saslauthd -a shadow pam

# /usr/local/sbin/testsaslauthd -u root -p xxttest // xxttest 为root的密码

(7) 开机自动启动

# echo "/usr/local/sbin/saslauthd -a shadow pam"&gt;&gt;/etc/rc.local

7、 安装postfix

(1) 首先卸载系统自带的sendmail

# service sendmail stop

# rpm -qa |grep sendmail |xargs rpm -e –nodeps

(2) 添加用户和安装

# groupadd -g 105 postfix

# useradd -g 105 -u 105 -M -s /sbin/nologin postfix

# groupadd -g 106 postdrop

# useradd -g 106 -u 106 -M -s /sbin/nologin postdrop

# tar -zxvf postfix-2.6.5.tar.gz

# cd postfix-2.6.5

# make makefiles "CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_CYRUS_SASL -DUSE_SASL_AUTH -I/usr/local/include/sasl" "AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/local/lib -lsasl2"

# make

# make install

(3) 按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值)

install_root: [/]

tempdir: [/root/postfix-2.6.5] /tmp //其他的都是默认

config_directory: [/etc/postfix]

command_directory: [/usr/sbin]

daemon_directory: [/usr/libexec/postfix]

data_directory: [/var/lib/postfix]

html_directory: [no]

mail_owner: [postfix]

mailq_path: [/usr/bin/mailq]

manpage_directory: [/usr/local/man]

newaliases_path: [/usr/bin/newaliases]

queue_directory: [/var/spool/postfix]

readme_directory: [no]

sendmail_path: [/usr/sbin/sendmail]

setgid_group: [postdrop]

(4) 生成别名二进制文件

# newaliases

(5) 建立邮件存放目录

# mkdir -pv /var/mailbox

# chown -R vmail.vmail /var/mailbox

(6) 建立配置文件

# cd /etc/postfix/

# mv main.cf main.cf.old

# vi main.cf

添加下面的内容

#=====================BASE=========================

myhostname = mail.xxt.cn

mydomain = xxt.cn

myorigin = $mydomain

mydestination =

mynetworks = 192.168.0.0/16, 127.0.0.0/8

inet_interfaces = all

readme_directory = no

sample_directory = /etc/postfix

sendmail_path = /usr/sbin/sendmail

html_directory = no

setgid_group = postdrop

command_directory = /usr/sbin

manpage_directory = /opt/postfix/man

daemon_directory = /usr/libexec/postfix

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

queue_directory = /var/spool/postfix

mail_owner = postfix

#=====================Vritual Mailbox settings=========================

virtual_mailbox_base = /var/mailbox

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_alias_domains =

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_uid_maps = static:1000

virtual_gid_maps = static:1000

virtual_transport = maildrop:

maildrop_destination_recipient_limit = 1

maildrop_destination_concurrency_limit = 1

#====================QUOTA========================

message_size_limit = 52428800

mailbox_size_limit = 209715200

virtual_mailbox_limit = 209715200

virtual_create_maildirsize = yes

virtual_mailbox_extended = yes

virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf

virtual_mailbox_limit_override = yes

virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.

virtual_overquota_bounce = yes

#====================SASL========================

smtpd_helo_required = yes

disable_vrfy_command = yes

strict_rfc821_envelopes = yes

invalid_hostname_reject_code = 554

multi_recipient_bounce_reject_code = 554

non_fqdn_reject_code = 554

relay_domains_reject_code = 554

unknown_address_reject_code = 554

unknown_client_reject_code = 554

unknown_hostname_reject_code = 554

unknown_local_recipient_reject_code = 554

unknown_relay_recipient_reject_code = 554

unknown_sender_reject_code = 554

unknown_virtual_alias_reject_code = 554

unknown_virtual_mailbox_reject_code = 554

unverified_recipient_reject_code = 554

unverified_sender_reject_code = 554

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

#smtpd_sender_restrictions=permit_mynetworks,reject_sender_login_mismatch,reject_authenticated_sender_login_mismatch,reject_unauthenticated_sender_login_mismatch

notify_classes = bounce, 2bounce, delay, policy, protocol, resource, software

bounce_template_file = /etc/postfix/bounce.cf

2bounce_notice_recipient = postmaster

bounce_notice_recipient = postmaster

delay_notice_recipient = postmaster

error_notice_recipient = postmaster

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $mydomain

smtpd_sasl_security_options = noanonymous

smtpd_sasl_application_name = smtpd

smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!

alias_maps = hash:/etc/aliases

#==================clamd==========================

content_filter=amavisfeed:[127.0.0.1]:10024

(7) 添加为支持虚拟域和虚拟用户所用到的配置文件,其实是直接在extman中复制过去

# tar zxvf extman-1.1.tar.gz

# cd extman-1.1

# cp docs/mysql_virtual_* /etc/postfix/

(8) 启动postfix并加入到自启动

# /usr/sbin/postfix start

# echo "/usr/sbin/postfix start"&gt;&gt;/etc/rc.local

8、 安装maildrop

(1) 安装和配置maildrop

# tar jxvf maildrop-2.5.0.tar.bz2

# cd maildrop-2.5.0

# ln -sv /usr/local/courier-authlib/bin/courierauthconfig /usr/bin/courierauthconfig

#yum install pcre-devel

#./configure --prefix=/usr/local/maildrop --enable-sendmail=/usr/sbin/sendmail --enable-trusted-users="rootvmail" --enable-syslog=1 --enable-maildirquota --enable-maildrop-uid=1000 --enable-maildrop-gid=1000 --with-trashquota--with-dirsync

# make && make install

# cp /usr/local/maildrop/bin/maildrop /usr/local/bin/

(2) 查看一下安装结果

# maildrop -v

maildrop 2.0.4 Copyright 1998-2005 Double Precision, Inc.

GDBM extensions enabled.

Courier Authentication Library extension enabled. //要保证这一行显示

Maildir quota extension enabled.

This program is distributed under the terms of the GNU General Public

License. See COPYING for additional information.

(3) 配置maildrop的日志文件

# vi /etc/maildroprc

logfile "/var/log/maildrop.log"

to "$HOME/Maildir"

VERBOSE="4"

或者

SHELL="/bin/sh"

logfile "/var/log/maildrop.log"

ACCOUNT=`echo "$LOGNAME" | cut -d@ -f1`

USERDOMAIN=`echo "$LOGNAME" | cut -d@ -f2`

############ Spam Filtering ###############

if (/^X-Spam-Flag: *YES/)

{

exception {

to "$HOME/Maildir/.Junk"

}

}

else

{

exception {

to "$HOME/Maildir"

}

}

下面的这个处理垃圾邮件,将垃圾邮件转移到垃圾邮件收件箱中

# touch /var/log/maildrop.log

# chown vmail.vmail /var/log/maildrop.log

(4) 配置Postfix

# vi /etc/postfix/master.cf

去掉下面两行前面的#

maildrop unix - n n - - pipe

flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}

第二行改为

flags=DRhu user=vmail argv=/usr/local/bin/maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}

此处要注意argv=后边的maildrop要加上路径,否则会出现

temporary failure. Command output: pipe: fatal: pipe_command: execvp maildrop: No such file or directory

注意maildrop unix这行前边不能有空格,要不会出现以下错误提示

warning: connect to transport maildrop: No such file or directory

Oct 31 23:21:24 localhost postfix/error[2235]: BE0AE27DAF6: to=<jjq002@abc.com>,relay=none,delay=1443,delays=1443/0.24/0/0.02,dsn=4.3.0, status=deferred (mail transport unavailable)

注意flags=Drhu这一行前边有两个空格,要不会出现以下错(fatal: /etc/postfix/master.cf: line 100: bad transport type: user= vmail)。

注意前面要保留两个空格,不然会有问题

9、 安装配置Extmail和Extman

(1) 安装和配置Extmail

# tar -zxvf extmail-1.2.tar.gz

# mkdir /var/www/extsuite

# mv extmail-1.2 /var/www/extsuite/extmail

# cd /var/www/extsuite/extmail/

# cp webmail.cf.default webmail.cf

# vi webmail.cf

部分修改选项的说明:

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

修改 cgi执行文件属主为apache运行身份用户:

# chown -R vmail.vmail /var/www/extsuite/extmail/cgi/

(2) 安装配置Extman

# mv extman-1.1 /var/www/extsuite/extman

#cd /var/www/extsuite/extman

# mv webman.cf.default webman.cf

修改配置文件以符合本例的需要:

# 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

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

# cd /var/www/extsuite/extman

# mysql -u root -p <docs/extmail.sql

# mysql -u root -p &lt;docs/init.sql

(4) 修改cgi目录的属主:

chown -R vmail.vmail /var/www/extsuite/extman/cgi

(5) extman和extmail需要Perl-Unix-Syslog、DBD-Mysql和perl-GD的支持

#perl -MCPAN -e shell

然后一路回车后出现:

cpan>

然后我们输入:

cpan&gt;install Unix::Syslog

cpan&gt;install GD

cpan&gt;install DBI

-----cpan&gt;install DBD::mysql # DBD-Mysql目前最新的版本为DBD-mysql-4.006,但它和系统中的perl结合使用时会造成extmail无法正常使用,因此我们采用 3的版本

# tar -zxvf DBD-mysql-3.0008_1.tar.gz

# cd DBD-mysql-3.0008_1

# perl Makefile.PL

# make

# make install

(6) 建立extman和extmail的目录

# mkdir /tmp/extman

# chown -R vmail.vmail /tmp/extman/

# mkdir /tmp/extmail

# chown -R vmail.vmail /tmp/extmail/

(7) apache相关配置

# vi /usr/local/apache2/conf/httpd.conf

去掉这行前面的#号

Include conf/extra/httpd-vhosts.conf

# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

去后面的<VirtualHost>两段

<VirtualHost *:80>

....

</VirtualHost>

添加下面内容

<VirtualHost *:80>

ServerName mail.xxt.cn

DocumentRoot /var/www/extsuite/

ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/

Alias /extmail/ /var/www/extsuite/extmail/html/

ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/

Alias /extman/ /var/www/extsuite/extman/html/

SuexecUserGroup vmail vmail

</VirtualHost>

(8) 重启一下apache服务器

#service httpd restart

到此,就全配置完了

在浏览器中输入http://mail.xxt.cn/extman进入管理界面,默认内置账号是root@extmail.org,密码是 extmail*123*,添加一个域和用户

在http://mail.xxt.cn/extmail中登陆