http://bbs.yahunet.com/thread-10482-1-1.html
本文参考了很多google上的文档,经过实践测试完成,请大家多多指正。
试验环境
centos4.5
所用软件包:
mysql-5.0.67.tar.gz
cyrus-sasl-2.1.22.tar.gz
httpd-2.2.9.tar.gz
php-5.2.6.tar.gz
postfix-2.5.3.tar.gz
courier-authlib-0.61.tar.gz
courier-imap-4.1.0.tar.gz
maildrop-2.0.4.tar.bz2
extman-0[1][1].2.5.tar.gz
extmail-1[1][1].0.5.tar.gz
开始前请确保您已经配置好指向此邮件服务器MX记录及其它DNS设置;本示例中的域名为lin128.cn,邮件服务器FQDN为 mail.lin128.cn,IP地址为192.168.1.66.
1、安装mysql
# tar -zxvf mysql-5.0.67.tar.gz
# cd mysql-5.0.67
# groupadd mysql
# useradd -g mysql -s /sbin/nologin -M mysql
# ./configure --prefix=/usr/local/mysql--with-charset=gbk--with-extra-charset=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 root.root /usr/local/mysql/
# chown -R mysql.mysql /usr/local/mysql/var/
启动数据库服务,并添加到自启动
# /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 --level 345 mysqld on
添加root密码
# /usr/local/mysql/bin/mysqladmin -u root password "123456"
配置库文件搜索路径
# echo "/usr/local/mysql/lib/mysql">>/etc/ld.so.conf
# ldconfig
# ldconfig -v
#echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
#source /etc/profile
2、安装apache
安装Apache有两个要注意的地方,因为我这里用的Postfix的后台管理是extman这个程序,而它是通过CGI的方式来进行管理的,所以这里启用了suexec的功能,还有一个是关于网站的存放路径的,如果不指定,那么在启用suexec后会出现 suexec-docroot的错误.
#tar jxvf httpd-2.2.9.tar.bz2
#cd httpd-2.2.9
#./configure --prefix=/usr/local/www --enable-so--enable-rewrite--enable-mods-shared=all --enable-suexec--with-suexec-caller=daemon--with-suexec-docroot=/var/www
#make
#make install
修改apache配置文件
#vi /usr/local/www/conf/httpd.conf
找到DocumentRoot “/usr/local/apache/htdocs”
修改为:DocumentRoot “/var/www”(后文中我们还会注释掉此行,以启用虚拟主机)
找到<Directory “/usr/local/apache/htdocs”>
修改为:<Directory “/var/www”>
找到
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all //这句改为Allow from all
</Directory>
#mkdir /var/www
#/usr/local/www/bin/apachectl start
添加系统服务和自启动
# cp /usr/local/www/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
# tar -zxvf php-5.2.6.tar.gz
# cd php-5.2.6
# ./configure--prefix=/usr/local/php--with-apxs2=/usr/local/www/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
# vi /usr/local/www/conf/httpd.conf
添加一句
AddType application/x-httpd-php .php .phtml
找到DirectoryIndex index.html
在后面添加index.php
4、安装courier-authlib
需要先安装一下expect包
#groupadd -g 1000 vmail
#useradd -g 1000 -u 1000 -M -s /sbin/nologin vmail
# tar -jxvf courier-authlib-0.61.0.tar.bz2
# cd courier-authlib-0.61
#./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/">>/etc/ld.so.conf
# ldconfig
修改配置文件
# 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")
启动及加入到自动运行队列
# 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
# tar -jxvf courier-imap-4.1.3.tar.bz2
# cd courier-imap-4.1.3
# ./configure --prefix=/usr/local/courier-imap--with-redhat--enable-unicode --disable-root-check --with-trashquota--without-ipv6COURIERAUTHCONFIG="/usr/local/courier-authlib/bin/courierauthconfig"
# make && make install
# make install-configure
编辑配置文件启用pop3及imap
# vi /usr/local/courier-imap/etc/pop3d
POP3DSTART=YES
# vi /usr/local/courier-imap/etc/imapd
IMAPDSTART=YES
启动及加入自动运行队列
# 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
先卸载本机自带的sasl
# rpm -qa |grep cyrus-sasl |xargs rpm -e --nodeps
# rm -rf /usr/lib/sasl
# rm -rf /usr/lib/sasl2
# 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
共享链接库 :
# ln -sv /usr/local/lib/sasl2 /usr/lib/sasl2
# echo "/usr/local/lib">>/etc/ld.so.conf
# ldconfig
# ldconfig -v
建立smtpd用户认证的配置文件:
# vi /usr/local/lib/sasl2/smtpd.conf
pwcheck_method:authdaemond
mech_listLAIN LOGIN
log_level:3
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
创建运行时需要的目录
# mkdir -pv /var/state/saslauthd
启动并测试
# /usr/local/sbin/saslauthd -a shadow pam
# /usr/local/sbin/testsaslauthd -u root -p 123456 //123456为root的密码
开机自动启动
# echo "/usr/local/sbin/saslauthd -a shadow pam">>/etc/rc.local
7、安装postfix
首先卸载系统自带的sendmail
# service sendmail stop
# rpm -qa |grep sendmail |xargs rpm -e --nodeps
# 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.5.5.tar.gz
# cd postfix-2.5.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
按照以下的提示输入相关的路径([]号中的是缺省值,”]”后的是输入值)
install_root: [/]
tempdir: [/tmp/postfix-2.5-20071006] /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]
生成别名二进制文件
建立邮件存放目录
# mkdir -pv /var/mailbox
# chown -R vmail.vmail /var/mailbox
建立配置文件
# cd /etc/postfix/
# mv main.cf main.cf.old
# vi main.cf
添加下面的内容
#=====================BASE=========================
myhostname = mail.lin128.cn
mydomain = lin128.cn
myorigin = $mydomain
mydestination =
mynetworks = 192.168.100.0/24, 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========================
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
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!
添加为支持虚拟域和虚拟用户所用到的配置文件
//直接在extman中复制过去就可以了
# tar zxvf extman-0\[1\]\[1\].2.5.tar.gz
# cd extman-0.2.4
# cp docs/mysql_virtual_* /etc/postfix/
启动postfix并加入到自启动
# /usr/sbin/postfix start
# echo "/usr/sbin/postfix start">>/etc/rc.local
8、安装maildrop
# tar jxvf maildrop-2.0.4.tar.bz2
# cd maildrop-2.0.4
# ln -sv /usr/local/courier-authlib/bin/courierauthconfig /usr/bin/courierauthconfig
#./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
注:我的安装过程出现了pcre.h的错误,安装一下pcre-devel那个rpm包就可以了
# make && make install
# cp /usr/local/maildrop/bin/maildrop /usr/local/bin/
查看一下安装结果
# 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.
配置maildrop的日志文件
# vi /etc/maildroprc
logfile "/var/log/maildrop.log"
VERBOSE="4"
# touch /var/log/maildrop.log
# chown vmail.vmail /var/log/maildrop.log
配置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=vuser argv=/usr/local/bin/maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}
9、安装配置Extmail和Extman
# tar -zxvf extmail-1\[1\]\[1\].0.5.tar.gz
# mkdir /var/www/extsuite
# mv extmail-1.0.5 /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/
安装配置Extman
# mv extman-0.2.5 /var/www/extsuite/extman
修改配置文件以符合本例的需要:
# 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建立数据库:
# cd /var/www/extsuite/extman
# mysql -u root -p <docs/extmail.sql
# mysql -u root -p <docs/init.sql
修改cgi目录的属主:
# chown -R vmail.vmail /var/www/extsuite/extman/cgi/
extman和extmail需要Perl-Unix-Syslog、DBD-Mysql和perl-GD的支持,可以到网上下载到,提示个地址给大家http://dag.wieers.com/rpm/packages/和http://search.cpan.org下载
DBD-Mysql目前最新的版本为DBD-mysql-4.006,但它和系统中的perl结合使用时会造成extmail无法正常使用,因此我们采用 3的版本:
# rpm -ivh perl-Unix-Syslog-1.0-1.el4.rf.i386.rpm
# rpm -ivh perl-GD-2.35-1.el4.rf.i386.rpm
# rpm -ivh --nodeps perl-DBI-1.602-1.el4.rf.i386.rpm
# tar -zxvf DBD-mysql-3.0008_1.tar.gz
# cd DBD-mysql-3.0008_1
# perl Makefile.PL
# make
# make install
建立extman和extmail的目录
# mkdir /tmp/extman
# chown -R vmail.vmail /tmp/extman/
# mkdir /tmp/extmail
# chown -R vmail.vmail /tmp/extmail/
apache相关配置
# vi /usr/local/www/conf/httpd.conf
去掉这行前面的#号
Include conf/extra/httpd-vhosts.conf
# vi /usr/local/www/conf/extra/httpd-vhosts.conf
去后面的<VirtualHost>两段
<VirtualHost *:80>
....
</VirtualHost>
添加下面内容
<VirtualHost *:80>
ServerName mail.lin128.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>
重启一下apache服务器
# /usr/local/www/bin/apachectl restart
到此,就全配置完了
在浏览器中输入http://mail.lin128.cn/extman进入管理界面,默认内置账号是
[email protected],密码是 extmail*123*,添加一个域和用户
在http://mail.lin128.cn/extmail中登陆
图形化日志
1、安装gd-2.0.35
# tar -jxvf gd-2.0.35.tar.bz2
# cd gd-2.0.35
# ./configure --with-png --with-freetype --with-jpeg --with-zlib --with-fontconfig
# make
如果GD报错:configure.ac:64: warning: macro `AM_ICONV' not found in library
你就make clean一下,然后再make
如果你安装别的出现libtool没有找到,你就从/usr/bin/libtool cp 一个过来用就好了!
# make install
2、安装Time-HiRes
# tar -zxvf Time-HiRes-1.9715.tar.gz
# cd Time-HiRes-1.9715
# perl Makefile.PL
# make
# make test
# make install
3、安装File-Tail
# tar -zxvf File-Tail-0.99.3.tar.gz
# cd File-Tail-0.99.3
# perl Makefile.PL
# make
# make test
# make install
4、安装rrdtool(用最新版的编译没通过)
# tar -zxvf rrdtool-1.2.26.tar.gz
# cd rrdtool-1.2.26
# ./configure --prefix=/usr/local/rrdtool --enable-perl-site-install=/usr/lib/perl5/
# make
make的时候出现错误,安装一下tcl-devel
# make install
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