postfix邮件系统解决方案(源代码安装

 

以前做的一个邮服的记录,从源代码编译安装的,从源代码编译安装适合所有的linux系统,而且安装到哪都很清楚,备份和愎复起来也容易,tar起来,再tar开就好了,嘻嘻嘻!还可以了解这些包之前的相互关联,利于深刻掌握!不过,还是觉得apt-get方式安装方便.

1、系统目标
  Maildir邮件存储格式
  smtp认证
  邮件地址和系统帐号分开
  多域支持
  web管理帐号、别名、域等资料
  pop3/imap支持
    webmail支持
  集成mysql数据库
2、TODO
  集成垃圾邮件过滤
  集成防病毒

Project:xx公司邮件系统解决方案
Date:
Author:

1、系统目标
  Maildir邮件存储格式
  smtp认证
  邮件地址和系统帐号分开
  多域支持
  web管理帐号、别名、域等资料
  pop3/imap支持
    webmail支持
  集成mysql数据库
2、TODO
  集成垃圾邮件过滤
  集成防病毒
3、系统架构
  +---------------------------------------------------+
  |                                                   |
  |  25/25    25/25     110/993  143/995    80/443    |
  | Incoming Outgoing     POP3     IMAP    WEB-MAIL   |
  |    /       /         /       /        /      |
  |    ||       ||         ||       ||        ||      |
  |    /       /         /       /        /      |
  +-------------------+---------------+---------------+
  |    Postfix        |               | Squirrelmail  |
  |                   |               +---------------+
  |                   |      Courier-imap             |
  |       +-----------+-------------------------------+
  |       +                  Courier-authlib          +
  |       |-------------------------------------------|
  |       |                  Cyrus-SASL               |
  |-------+-------------------------------------------+
  |                      MySQL                        |
  +---------------------------------------------------+
4、系统安装
   操作系统采用debian 3.1(sarge),下面没有独立安装的gcc,make,db,glibc等基本库和软件,邮件系统需要的全部用 apt-get install 包名称 来安装
  mail~#apt-get install gcc make
  mail~#apt-get install libdb4-*
  mail~#apt-get install curses*
  mail~#apt-get install termcap*
    ..............
4.1、mysql
    mail~#wget http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-4.1.12.tar.gz/from/http://mysql.cbn.net.id/
    mail~#groupadd mysql
    mail~#useradd -g mysql mysql
    mail~#tar zxvf /usr/src/mail/mysql-4.1.12.tar.gz -C /tmp
    mail~#cd /tmp/mysql-4.1.12
    mail~#./configure --prefix=/opt/mysql --localstatedir=/opt/mysql/data --with-unix-socket-path=/tmp/mysql.sock --with-mysql-user=mysql --with-charset=gb2312 --with-extra-charsets=all
    mail~#make
    mail~#make install
    mail~#chown -R mysql:mysql /opt/mysql/data/
  如果没有/opt/mysql/var/mail.err,就手动创建一个
    mail~#mkdir /opt/mysql/var
    mail~#touch /opt/mysql/var/mail.err
    mail~#/opt/mysql/bin/mysqld_safe --user=mysql &  #起动mysql服务
    mail~#/opt/mysql/bin/mysql     #起动mysql客户端
    mail~#vi /etc/ld.so.conf,添加
       /opt/mysql/lib/mysql
    mail~#ldconfig
    mail~#cp /opt/mysql/share/mysql/mysql.server /etc/init.d/mysqld
    mail~#chmod 755 /etc/init.d/mysqld
    mail~#ln -s /etc/init.d/mysqld /etc/rc3.d/S52mysqld
    mail~#ln -s /etc/init.d/mysqld /etc/rc5.d/S52mysqld
    mail~#ln -s /etc/init.d/mysqld /etc/rc0.d/K25mysqld
    mail~#ln -s /etc/init.d/mysqld /etc/rc1.d/K25mysqld
    mail~#ln -s /etc/init.d/mysqld /etc/rc2.d/K25mysqld
    mail~#ln -s /etc/init.d/mysqld /etc/rc4.d/K25mysqld
    mail~#ln -s /etc/init.d/mysqld /etc/rc6.d/K25mysqld
4.2、apahce
    mail~#wget http://apache.justdn.org/httpd/apache_1.3.33.tar.gz
    mail~#goupadd www
    mail~#useradd -g www -d /dev/null -s /bin/false www
    mail~#tar zxvf /usr/src/mail/apache_1.3.33.tar.gz -C /tmp
    mail~#cd /tmp/apache_1.3.33
    mail~#./configure --prefix=/opt/apache --enable-module=rewrite --enable-shared=rewrite --enable-module=proxy --enable-shared=proxy --enable-module=so --server-uid=www --server-gid=www
    mail~#make
    mail~#make install
    mail~#/opt/mysql/var# /opt/apache/bin/apachectl start #起动apache服务器
    mail~#cd /opt/apache/bin/
    mail~#cp apachectl /etc/init.d/httpd
    mail~#cd /etc/init.d/
    mail~#chmod 755 httpd
    mail~#ln -s /etc/init.d/httpd /etc/rc3.d/S51httpd
    mail~#ln -s /etc/init.d/httpd /etc/rc5.d/S51httpd
    mail~#ln -s /etc/init.d/httpd /etc/rc0.d/K15httpd
    mail~#ln -s /etc/init.d/httpd /etc/rc1.d/K15httpd
    mail~#ln -s /etc/init.d/httpd /etc/rc2.d/K15httpd
    mail~#ln -s /etc/init.d/httpd /etc/rc4.d/K15httpd
    mail~#ln -s /etc/init.d/httpd /etc/rc6.d/K15httpd
4.3、php4
    mail~#wget http://cn2.php.net/get/php-4.3.11.tar.gz/from/cn.php.net/mirror
    mail~#tar zxvf /usr/src/mail/php-4.3.11.tar.gz -C /tmp
    mail~#cd /tmp/php-4.3.11
    mail~#./configure --prefix=/opt/php4 --with-xml --with-mysql=/opt/mysql --with-mysql-sock=/tmp/mysqld.php4.sock --with-apxs=/opt/apache/bin/apxs
    mail~#make
    mail~#make install
    mail~#cp php.ini-dist /opt/php4/lib/php.ini
  修改/opt/apache/conf/httpd.conf,添加php4支持,添加内容如下:
          #php 4
      AddType application/x-httpd-php .php
      AddType application/x-httpd-php-source .phps
另更改
  <IfModule mod_dir.c>
       DirectoryIndex index.html
  </IfModule>

  <IfModule mod_dir.c>
       DirectoryIndex index.html index.php
  </IfModule>
   mail~#vi /opt/apache/htdocs/test.php,内容如下
  <?php
   phpinfo();
  ?>
     mail~#/opt/mysql/var# /opt/apache/bin/apachectl restart #重启apache服务器
使用lynx或常用的浏览器如IE、firefox,浏览http://ip/test.php,看到了PHP的信息页面,OK
4.4、openssl
     mail~#wget http://www.openssl.org/source/openssl-0.9.8.tar.gz
     mail~#tar zxvf /usr/src/mail/openssl-0.9.8.tar.gz -C /tmp
     mail~#cd /tmp/openssl-0.9.8
     mail~#./configure --prefix=/opt/openssl
     mail~#make
     mail~#make install
     mail~#ln -s /opt/openssl/include/openssl /usr/include/openssl
4.5、cyrus-sasl2
     mail~#wget http://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.21.tar.gz
     mail~#tar zxvf /usr/src/mail/cyrus-sasl-2.1.21.tar.gz -C /tmp
     mail~#cd /tmp/cyrus-sasl-2.1.21
     mail~#./configure --prefix=/opt/sasl2 --enable-login --enable-plain  --enable-sql --enable-pwcheck --disable-anon --disable-digest --with-mysql=/opt/mysql --with-mysql-includes=/opt/mysql/include/mysql --with-mysql-libs=/opt/mysql/lib/mysql --with-saslauthd=/var/run
     mail~#make
  如果出现下面的错误:
  auth_getpwent.c:48:20: des.h: No such file or directory
  make[3]: *** [auth_getpwent.o] Error 1
  make[3]: Leaving directory `/tmp/cyrus-sasl-2.1.21/saslauthd'
  make[2]: *** [all] Error 2
  make[2]: Leaving directory `/tmp/cyrus-sasl-2.1.21/saslauthd'
  make[1]: *** [all-recursive] Error 1
  make[1]: Leaving directory `/tmp/cyrus-sasl-2.1.21'
  make: *** [all] Error 2
  修改/tmp/cyrus-sasl-2.1.21/saslauthd/Makefiles内的变量CFLAGS添加-I/opt/openssl/include/openssl
    或者直接
     mail~#cp /tmp/cyrus-sasl-2.1.21/mac/libdes/public/des.h /tmp/cyrus-sasl-2.1.21/
     mail~#make
     mail~#make install
     mail~#vi /etc/ld.so.conf    #添加以下内容
  /usr/lib/sals2
  /opt/sasl2/lib/sasl2
     mail~#ldconfig
4.6、postfix
     mail~#wget http://postfix.it-austria.net/releases/official/postfix-2.2.4.tar.gz
     mail~#groupadd postfix
     mail~#ueradd -g postfix -d /dev/null -s /bin/false postfix
     mail~#make makefiles 'CCARGS=-DHAS_MYSQL -I/opt/mysql/include/mysql -DUSE_SASL_AUTH -I/opt/sasl2/include/sasl' 'AUXLIBS=-L/opt/mysql/lib/mysql -lmysqlclient -lm -lz -L/opt/sasl2/lib/sasl2 -lsasl2'
     mail~#make install  #一路回车默认就可以了
     mail~#vi /etc/init.d/postfix
#!/bin/sh
start() {
        #Start daemons.
        echo -n "Starting postfix: "
        /usr/sbin/postfix start
        }
stop() {
        #Stop daemons.
        echo -n "Shutting down postfix: "
        /usr/sbin/postfix stop
}
reload(){
        echo -n "Reloading postfix: "
        /usr/sbin/postfix reload
}
restart(){
        stop
        start
}
abort(){
        /usr/sbin/postfix abort
}
flush(){
        /usr/sbin/postfix flush
}
check(){
        /usr/sbin/postfix check
}
case $1 in
        start)
                start
                ;;
        stop)
                stop
                ;;
        reload)
                reload
                ;;
        restart)
                restart
                ;;
        abort)
                abort
                ;;
        flush)
                flush
                ;;
        check)
                check
                ;;
        *)
                echo "Usage: postfix {start|stop|restart|reload|abort|flush|check}"
esac
     mail~#chmod 755 /etc/init.d/postfix
     mail~#ln -s /etc/init.d/postfix /etc/rc3.d/S53postfix
     mail~#ln -s /etc/init.d/postfix /etc/rc5.d/S53postfix
     mail~#ln -s /etc/init.d/postfix /etc/rc0.d/K35postfix
     mail~#ln -s /etc/init.d/postfix /etc/rc1.d/K35postfix
     mail~#ln -s /etc/init.d/postfix /etc/rc2.d/K35postfix
     mail~#ln -s /etc/init.d/postfix /etc/rc4.d/K35postfix
     mail~#ln -s /etc/init.d/postfix /etc/rc6.d/K35postfix
4.7、courier-authlib
     mail~#wget http://www.courier-mta.org/beta/courier-authlib/courier-authlib-0.56.20050709.tar.bz2
     mail~#su - wxt
     wxt@mail:~$ tar xjvf /usr/src/mail/courier-authlib-0.56.20050709.tar.bz2 -C /tmp
     wxt@mail:~$cd /tmp/courier-authlib-0.56.20050709/
     wxt@mail:~$./configure --with-authmysql=yes --with-mailuser=www --with-mailgroup=www
 --with-mysql-libs=/opt/mysql/lib/mysql --with-mysql-includes=/opt/mysql/include
/mysql --prefix=/opt/courier-authlib
     wxt@mail:~$make
     wxt@mail:~$exit
     mail~#make install
4.8、courier-imap
     mail~#wget http://www.courier-mta.org/beta/imap/courier-imap-4.0.3.20050702.tar.bz2
     mail~#tar zxvf courier-imap-4.0.3.20050702.tar.bz2
     mail~#su - wxt
     wxt@mail:~$./configure --enable-unicode=utf-8,iso-8859-1,gb2312,gbk,gb18030,big5 --prefix=/opt/courier-imap --disable-root-check --with-trashquota --with-dirsync
  哪果没能完成,出错提示如下
  configure: WARNING: === Courier authentication library not found.
  configure: WARNING: === You need to download and install
  configure: WARNING: === http://www.courier-mta.org/download.php#authlib first.
  configure: WARNING: === If courier-authlib is installed in a non-default
  configure: WARNING: === directory, set the COURIERAUTHCONFIG environment
  configure: WARNING: === variable to the full path to the courierauthconfig
  configure: WARNING: === binary and rerun this configure script.
  configure: WARNING:
  configure: error: courierauthconfig not found
设置变量COURIERAUTHCONFIG
    wxt@mail:~$./export COURIERAUTHCONFIG=/opt/courier-authlib/bin/courierauthconfig
    wxt@mail:~$./configure --enable-unicode=utf-8,iso-8859-1,gb2312,gbk,gb18030,big5 --prefix=/opt/courier-imap --disable-root-check --with-trashquota --with-dirsync
完成
    wxt@mail:~$make
没有完成,出错提示如下
  tlspasswordcache.c:9:25: openssl/ssl.h: No such file or directory
  tlspasswordcache.c:10:25: openssl/err.h: No such file or directory
  tlspasswordcache.c:11:26: openssl/rand.h: No such file or directory
  make[3]: *** [tlspasswordcache.o] Error 1
  make[3]: Leaving directory `/tmp/courier-imap-4.0.3.20050702/tcpd'
  make[2]: *** [all] Error 2
  make[2]: Leaving directory `/tmp/courier-imap-4.0.3.20050702/tcpd'
  make[1]: *** [all-recursive] Error 1
  make[1]: Leaving directory `/tmp/courier-imap-4.0.3.20050702'
  make: *** [all] Error 2
没有找到openssl/ssl.h 等头文件
apt-get install libssl-dev或编译安装openssl,也就是要回头检查一下,安装openssl的时候,是不是哪个地方有问题
   有可能是这一步没做,做一下 #ln -s /opt/openssl/include/openssl /usr/include/openssl
    wxt@mail:~$make
没有完成,出错提示如下
Compiling imaplogin.c
imaplogin.c:35:32: courierauth.h: No such file or directory
imaplogin.c:36:37: courierauthdebug.h: No such file or directory
imaplogin.c:156: warning: `struct authinfo' declared inside parameter list
imaplogin.c:156: warning: its scope is only this definition or declaration, which is probably not what you want
imaplogin.c: In function `login_callback':
imaplogin.c:166: error: dereferencing pointer to incomplete type
imaplogin.c:167: warning: implicit declaration of function `auth_getoption'
imaplogin.c:167: error: dereferencing pointer to incomplete type
imaplogin.c:168: warning: assignment makes pointer from integer without a cast
imaplogin.c:172: error: dereferencing pointer to incomplete type
imaplogin.c:177: error: dereferencing pointer to incomplete type
imaplogin.c:181: error: dereferencing pointer to incomplete type
imaplogin.c:196: error: dereferencing pointer to incomplete type
imaplogin.c:197: error: dereferencing pointer to incomplete type
imaplogin.c:220: warning: implicit declaration of function `auth_callback_default'
imaplogin.c:224: error: dereferencing pointer to incomplete type
imaplogin.c:225: error: dereferencing pointer to incomplete type
imaplogin.c:230: error: dereferencing pointer to incomplete type
imaplogin.c:230: error: dereferencing pointer to incomplete type
imaplogin.c:240: error: dereferencing pointer to incomplete type
imaplogin.c:244: error: dereferencing pointer to incomplete type
imaplogin.c:248: error: dereferencing pointer to incomplete type
imaplogin.c:249: error: dereferencing pointer to incomplete type
imaplogin.c: In function `do_imap_command':
imaplogin.c:278: warning: implicit declaration of function `courier_authdebug_login'
imaplogin.c:372: warning: implicit declaration of function `auth_login'
imaplogin.c:373: warning: implicit declaration of function `courier_safe_printf'
imaplogin.c: In function `main':
imaplogin.c:451: warning: implicit declaration of function `courier_authdebug_login_init'
imaplogin.c: In function `login_imap':
imaplogin.c:596: warning: implicit declaration of function `DPRINTF'
make[3]: *** [imaplogin.o] Error 1
make[3]: Leaving directory `/tmp/courier-imap-4.0.3.20050702/imap'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/tmp/courier-imap-4.0.3.20050702/imap'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/tmp/courier-imap-4.0.3.20050702'
make: *** [all] Error 2
修改/tmp/courier-impa-4.3.20050702/imap/Makefile文件中变量CFLAGS,添加-I/opt/courier-authlib/include
保存
     wxt@mail:~$make
     wxt@mail:~$exit
     mail:~#make install
完成
     mail:~#imapd.rc /etc/init.d/imapd
     mail:~#chmod 755 /etc/init.d/imapd
     mail:~#ln -s /etc/init.d/imapd /etc/rc3.d/S54imapd
     mail:~#ln -s /etc/init.d/imapd /etc/rc5.d/S54imapd
     mail:~#ln -s /etc/init.d/imapd /etc/rc0.d/K45imapd
     mail:~#ln -s /etc/init.d/imapd /etc/rc1.d/K45imapd
     mail:~#ln -s /etc/init.d/imapd /etc/rc2.d/K45imapd
     mail:~#ln -s /etc/init.d/imapd /etc/rc4.d/K45imapd
     mail:~#ln -s /etc/init.d/imapd /etc/rc6.d/K45imapd
     mail:~#cp pop3d.rc /etc/init.d/pop3d
     mail:~#chmod 755 /etc/init.d/pop3d
     mail:~#ln -s /etc/init.d/pop3d /etc/rc3.d/S55pop3d
     mail:~#ln -s /etc/init.d/pop3d /etc/rc5.d/S55pop3d
     mail:~#ln -s /etc/init.d/pop3d /etc/rc0.d/K55pop3d
     mail:~#ln -s /etc/init.d/pop3d /etc/rc1.d/K55pop3d
     mail:~#ln -s /etc/init.d/pop3d /etc/rc2.d/K55pop3d
     mail:~#ln -s /etc/init.d/pop3d /etc/rc4.d/K55pop3d
     mail:~#ln -s /etc/init.d/pop3d /etc/rc6.d/K55pop3d
4.9、postfixadmin
    mail:~#wget http://high5.net/postfixadmin/download.php?file=postfixadmin-2.1.0.tgz
    mail:~#tar zxvf download.php?file=postfixadmin-2.1.0.tgz -C /opt/apache/htdocs/
    mail:~#cp config.inc.php.sample config.inc.php
// Language config
// Language files are located in './languages'.
$CONF['default_language'] = 'cn';

// Database Config
// 'database_type' is for future reference.
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';

$CONF['encrypt'] = 'cleartext';

// Mailboxes
// If you want to store the mailboxes per domain set this to 'YES'.
// Example: /usr/local/virtual/domain.tld/[email protected]
$CONF['domain_path'] = 'YES';
// If you don't want to have the domain in your mailbox set this to 'NO'.
// Example: /usr/local/virtual/domain.tld/username
$CONF['domain_in_mailbox'] = 'NO';

// Quota
// When you want to enforce quota for your mailbox users set this to 'YES'.
$CONF['quota'] = 'YES';
$CONF['quota_multiplier'] = '1048576';

    mail:~#chown -R wxt:wxt /opt/apache/htdocs/postfixadmin-2.1.0
    mail:~#mysql</opt/apache/htdocs/postfixadmin-2.1.0/DATABASE_MYSQL.TXT
   
4.10、配置postfix
    修改/etc/postfix/main.cf
#=============sasl2====================#
smtpd_sasl_auth_enable = yes
smtpd_sasl_application_name = smtpd
broken_sasl_auth_clients = yes
smtpd_sasl_local_domain = wjjennluen.com
smtpd_recipient_restrictions = reject_unauth_destination

#=================mysql================#
virtual_transport = virtual
virtual_mailbox_domains = mysql:/etc/postfix/mysql/mysql_mailbox_domains.cf
virtual_mailbox_base = /var/mailbox/
virtual_mailbox_maps = mysql:/etc/postfix/mysql/mysql_mailbox_maps.cf
virtual_minimum_uid = 1004
virtual_uid_maps = static:1004
virtual_gid_maps = static:1004
virtual_alias_maps = mysql:/etc/postfix/mysql/mysql_alias_maps.cf
   mail:~#vi /etc/postfix/mysql/mysql_alias_maps.cf
user = postfix
password = postfix
dbname = postfix

table = alias
select_field = goto
where_field = address
additional_conditions = and active='1'
   mail:~#vi /etc/postfix/mysql/mysql_mailbox_domains.cf
user = postfix
password = postfix
dbname = postfix

table = alias
select_field = goto
where_field = address
additional_conditions = and active='1'
   mail:~#vi /etc/postfix/mysql/mysql_mailbox_maps.cf
user = postfix
password = postfix
dbname = postfix

table = mailbox
select_field = maildir
where_field = username
additional_conditions = and active='1'
4.11、squirrelmail
    mail:~#wget http://keihanna.dl.sourceforge.net/sourceforge/squirrelmail/squirrelmail-1.4.5-rc1.tar.gz
    mail:~#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fcompatibility-2.0.tar.gz
    mail:~#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fmsg_flags-1.4.3.1-1.4.3.tar.gz
    mail:~#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fchange_mysqlpass-3.2-.2.8.tar.gz
    mail:~#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fquota_usage-1.3-1.2.7.tar.gz
    mail:~#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Faddgraphics-2.3-1.0.3.tar.gz
    mail:~#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fusername-2.3-1.0.0.tar.gz
    mail:~#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fweather-4.1.1-1.2.tar.gz
    mail:~#wget http://ufpr.dl.sourceforge.net/sourceforge/squirrelmail/zh_CN-1.4.5-20050713.tar.gz
    mail:~#wget http://ufpr.dl.sourceforge.net/sourceforge/squirrelmail/zh_TW-1.4.5-20050713.tar.gz
    mail:~#wget http://www.squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fattachment_doc.1.2-1.4.4.tar.gz
  解压squirrelmail到/opt/apache/htdocs/squirrelmail,中文补丁也解压到同样的目录,其它补丁解压到/opt/apache/htdocs/squirrelmail/plugin下,把各补丁下的sample配置文件复制为config.php,在/opt/apache/htdocs/squirrelmail下运行configure配置一下基本参数,完成。具体可看解开文件包内的INSTALL或者redme文件,注意要chown -R www:www /opt/apache/htdocs/squirrelmail

你可能感兴趣的:(linux)