配置postfix+dovecot+mysql+postfixadmin+squirrelmail 邮件系统笔记

最近想搭建一个完整的mailserver,查了很多资料,一直没有成功,网上大部分资料是在redhat系列的操作系统上的,而且很多都是采用rpm包。
我现在的系统是suse Linux有许多包已经安装,如果安装新的包,会产生很多冲突问题,卸载又遇到很多依赖问题,所以决定全部采用源代码的方法来安装。为了以后查询方便,将配置过程和资料整理如下。
下面开始正式安装,这次安装,首先是根据http://www.redlinux.org/read.php?tid-481.html
贴子中的安装的,开始不明白这些软件的用途,乱装一气,然后又参照橡皮树老师的网络视频配置,最终排错过程中不得不细细考究了一下这些软件的作用,为了简单,最后基本上安装橡皮树老师的配合来的,唯一不同的地方是,我的安装基本上是采用源代码方式,而且配置文件全部是自定义的,下面有些软件的安装对于本邮件系统并没有必要,但是考虑以后的功能增加,就先装上。

 

zlib的安装
zlib是一个传输的压缩支持库
zlib
./configure -prefix=/opt/mailserver/zlib -64

curl 的安装
curl是一个提供http,ftp,imap等协议的命令行模块。
下面是编译参数
./configure
-prefix=/opt/mailserver/curl
-with-ssl=/opt/mailserver/openssl
--with-zlib=/opt/mailserver/zlib


Libssh2的安装
本打算把libssh的支持也编译进去,但是编译libssh失败,提示openssh的库文件不对。
Libssh build with openssl error
`OPENSSL_cpuid_setup' can not be used when making a shared object;
换了几个版本,故障依旧,因此就没有加入libssh支持。
下面是编译参数
./configure
--prefix=/opt/mailserver/curl
--with-zlib=/opt/mailserver/zlib
--with-ssl=/opt/mailserver/openssl
--with-libssh2=/opt/mailserver/libssh2

 

 

 


Libssh与libssh2的区别如下
item                                     libssh2                              libssh
Licence                           Modified BSD                           LGPL
Non-blocking API               everything                            parts
Limits on                           >4GB files yes                        no
Server-side                           no                                      yes
Stable API                             yes                                     no
C compatibility                       C89                                   C99
strict namespace                   yes                                     no
man pages for all functions    yes                                    no
SSHv1 support                        no                                     yes
Build concept                           Autotools                         CMake

 

 

安装:Berkeley-db
这是一个数据库软件,据说是Cyrus-SASL and Cyrus-IMAP所必需的数据库支持。

tar xzvf db-4.7.25.tar.gz
cd db-4.7.25
../dist/configure --prefix=/opt/mailserver/BerkeleyDB
make
make install


下面的步骤,主要是对让系统找到库文件和头文件,对于不同的系统,可能会有不同的操作。
如果不链接,下面装openldap就会报错,提示库文件不匹配。
当然,本次邮件系统并没有用到这个功能。

ln -s /opt/mailserver/ BerkeleyDB/include/* /usr/include/
mv /lib64/libdb-4.so /lib64/libdb-4.so.old
ln -s /opt/mailserver/ BerkeleyDB/lib/* /lib64/

安装:Openldap
这个软件功能还不是很了解,只是看到postfix支持此功能就顺便装上了。

tar xzvf openldap-stable-20100219.tgz
cd openldap-2.4.21
./configure --prefix=/opt/mailserver/openldap
make
make install


安装:Openssl
这个在postfix也是支持的,但是考虑到配置的复杂性,暂时没有在邮件系统中使用,在imap的软件安装中,也要用到openssl库,而且经常会报openssl库的错误,一般情况,分别编译静态库和动态库,或者编译含 -fPIC 选项的静态库,可能会解决问题。
./config shared 生成动态库
./config -fPIC 生成静态库加-fPIC选项


./config --prefix=/opt/mailserver/openssl
make
make install

下面再重新编译一次,生成动态库,默认的没有生成动态库,这个在php编译的时候会需要。
./config --prefix=/opt/mailserver/openssl shared
make
make install

我用这个库在安装最新版本的dovecot时,提示静态库需要用-fPIC来编译,本次就没有测试了,因为最终采用的是稳定版本的dovecot。

下面的步骤,主要是对让系统找到库文件和头文件,对于不同的系统,可能会有不同的操作。ln -s /opt/mailserver/openssl/include/openssl /usr/include/openssl
ln -s /opt/mailserver/openssl/lib/* /lib64

安装:mysql
mysql采用的是相应平台二进制包的形式安装,如果采用源代码安装难度要大一点,因为我曾经失败了几次,最终下载了一个二进制包,步骤基本上再INSTALL文件中有,需要的额外操作时如何修改配置文件的位置问题,而且Mysql配置文件修改后,其他配合的软件参数也有许多地方需要修改。

groupadd mysql
useradd -g mysql mysql
cd /opt/mailserver
tar xzvf mysql-5.1.45-linux-x86_64-glibc23.tar.gz
mv mysql-5.1.45-linux-x86_64-glibc23 mysql
cd mysql
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
bin/mysqld_safe --user=mysql & //测试是否正确启动
bin/mysqladmin -u root password 123 //给root用户加密码
cp support-files/mysql.server /etc/init.d/mailserver.mysql //增加自启动脚本

vi /etc/init.d/mailserver.mysql
------------------------------------------------------------------------------------------
basedir=/opt/mailserver/mysql
extra_args="-e $basedir/my.cnf" 改成 extra_args="-c $basedir/my.cnf"

$bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
改成
$bindir/mysqld_safe --defaults-file=$basedir/my.cnf --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
----------------------------------------------------------------------------------------------
剩余的配置,就是修改$basedir/my.cnf文件内的内容,主要是mysql.sock的路径,此处
我的配置是/opt/mailserver/mysql/data/mysql/mysql.sock
注意,data目录最好是777权限,以免出错。

安装:cyrus-sasl
这个软件是提供smtp的sasl验证的,因为本次最终是采用dovecot进行smtp验证,因此实际也没有利用这个软件的功能,考虑以后进行完善。

tar xzvf cyrus-sasl-2.1.22.tar.gz
cd cyrus-sasl-2.1.22
./configure --prefix=/opt/mailserver/cyrus-sasl --enable-login --enable-sql --disable-digest --with-openssl=/opt/mailserver/openssl --with-mysql=/opt/mailserver/mysql/

如何没有采用--disable-digest,有可能会编译不通过,在我的机器上是这样,Google后才知道要禁用。

下面先备份老的sasl安装包
mv /usr/lib/sasl /usr/lib/sasl.off
mv /usr/lib/sasl2 /usr/lib/sasl2.off
mv /usr/lib64/sasl2 /usr/lib64/sasl2.off //64位机器上需要运行
make
make install

下面的步骤,主要是对让系统找到库文件和头文件,对于不同的系统,可能会有不同的操作。
ln -s / opt/mailserver/cyrus-sasl /usr/local/sasl2
ln -s /opt/mailserver/cyrus-sasl/lib/* /lib64

 

安装:dovecot
tar xzvf dovecot-1.2.11.tar.gz
cd dovecot-1.2.11
./configure --prefix=/opt/mailserver/dovecot --with-ldap=yes --sysconfdir=/etc/dovecot --with-mysql --with-ssl=openssl --with-ssl --with-ssldir=/etc/ssl
make
make install
这个--with-ldap=yes参数我不记得是否加上了,而且即使不加上,默认应该是开启的,具体的可参考./configure -help

安装:Postfix

Postfix的安装需要支持mysql,默认的包安装方式是不支持的。
在这里我们让它支持mysql,ssl,sasl

groupadd -g postfix
useradd -g postfix -c postfix -d /dev/null -s /bin/false postfix
groupadd postdrop
make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/opt/mailserver/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/opt/mailserver/cyrus-sasl/include -DUSE_TLS -I/opt/mailserver/openssl/include ' 'AUXLIBS=-L/opt/mailserver/mysql/lib -lmysqlclient -lz -lm -L/ opt/mailserver/cyrus-sasl/lib -lsasl2 -L/opt/mailserver/openssl/lib64 -lssl -lcrypto'
make
make install

make install时可以用来定义配置文件的存放位置,在这里,除了postfix.conf配置文件
全部放在了/opt/mailserver/postfix内部。

安装完成后,
用postconf -a 来检查是否安装了sasl
用postconf -m 来检查是否安装了mysql


安装:apache2
Apache编译时加载全部模块
tar xzvf cd httpd-2.2.15.tar.gz
cd httpd-2.2.15
./configure
--prefix=/opt/mailserver/apache2
-enable-so
--enable-modules=all
--enable-mods-shared=all

-enable-so表示支持动态模块
--enable-modules=all表示编译所有模块
--enable-mods-shared=all 表示全部采用动态模块
其他参数参照:
http://hi.baidu.com/sheshi37c/blog/item/0455247fc7c1450029388a1e.html

make
make install

实际不需要全部将这些模块都编译,我这里只是为了想用Apache的mod_status和mod_info模块来查看所有服务器信息和模块安装情况,就和php安装后的phpinfo()函数一样,而又不想一个一个研究这些模块,

安装完成后,修改httpdconf,加入
Include conf/extra/httpd-info.conf
如果是完整安装,./conf/extra/httpd-info.conf文件已经为你写好了。
只要修改Allow from 部分,修改为 Allow from all,就可以在
http://servername/server-status 和
http://servername/server-info 中查看所有的apache2信息了。

conf/extra/httpd-info.conf中配置如下:
<Location /server-status>
SetHandler server-status
Order allow,deny
Deny from nothing
Allow from all
</Location>

<Location /server-info>
SetHandler server-info
Order allow,deny
Deny from nothing
Allow from all
</Location>

http://your.server.name/server-status?refresh=N访问状态页面可以每N秒自动刷新一次。

http://your.server.name/server-status?auto获得一个面向机器可读的状态文件

perl模块安装
参考
http://perl.apache.org/docs/2.0/user/install/install.html#Dynamic_mod_perl
tar xzvf mod_perl-2.0-current.tar.gz
cd mod_perl-2.0.4
perl Makefile.PL MP_AP_PREFIX=/opt/mailserver/apache2
make
make install

vi http.conf加入
LoadModule perl_module modules/mod_perl.so

 

fast-cgi模块安装
tar xzvf mod_fastcgi-2.4.6.tar.gz
cd mod_fastcgi-2.4.6
vi makefile
把/usr/local/httpd改成 /opt/mailserver/apache2
make
make intall

vi httpd.conf 加入
LoadModule fastcgi_module modules/mod_fastcgi.so

suexec模块安装
参考
http://bbs.linuxphp.org/thread-499-1-1.html
http://1kankan.com/ApacheManual/suexec.html
http://blog.5ilinux.com/archives/2006/07/

/opt/mailserver/apache2/bin/apxs -c mod_suexec.c
/opt/mailserver/apache2/bin/apxs -i -a -n suexec ./.libs/mod_suexec.so
cd ../../

./configure
--prefix=/opt/mailserver/apache2
-enable-so
--enable-suexec
--with-suexec-bin=/opt/mailserver/apache2/bin/suexec
--with-suexec-logfile=/var/log/suexec.log
--with-suexec-caller=daemon
--with-suexec-docroot=/srv/www/rcac
--enable-modules=all --enable-mods-shared=all

make suexec
make install-suexec

完成后用/opt/mailserver/apache2/bin/suexec -V 查看参数

 


安装:php5
因为postfixadmin需要用到imap和mbstring以及mysql,需要php5安装支持imap,mbstring,mysql

imap的安装,费了很多的时间,可参照
http://www.phpbuilder.com/board/showthread.php?p=10944374

对于imap安装另一种说法可能比较权威参照
http://squirrelmail.org/docs/admin/admin-3.html#ss3.2

根据文中所说SSLTYPE=unix表示用Openssl,SSLTYPE=unix表示用IMAP的ssl
make port-name PASSWDTYPE='' SSLTYPE=none
port-name 可从Makefile针对自己的系统查询,对于SUSE是lsu
因为我装了openssl, 所以我的参数是
make port-name PASSWDTYPE='' SSLTYPE=none

参考的安装方法见下面

通过yast安装pam-devel
wget ftp://ftp.cac.washington.edu/mail/imap.tar.Z
tar zxf imap.tar.Z
cd imap-2007a
vi Makefile
-----------------------------
Find EXTRACFLAGS=
and add change it to: //对于64位系统要增加额外的-fPIC选项
EXTRACFLAGS=-fPIC
-----------------------------
make lr5 PASSWDTYPE=std SSLTYPE=unix.nopwd IP6=4

echo "set disable-plaintext nil" > /etc/c-client.cf

mkdir /usr/local/imap-2007a
mkdir /usr/local/imap-2007a/include/
mkdir /usr/local/imap-2007a/lib/
chmod -R 077 /usr/local/imap-2007a
rm -rf /usr/local/imap-2007a/include/*
rm -rf /usr/local/imap-2007a/lib/*
rm -rf /usr/sbin/imapd

cp imapd/imapd /usr/sbin/
cp c-client/*.h /usr/local/imap-2007a/include/
cp c-client/*.c /usr/local/imap-2007a/lib/
cp c-client/c-client.a /usr/local/imap-2007a/lib/libc-client.a

此时,对于编译php5有2种方法,一种采用所有参数放在php5 config命令
另一种,先按照默认的配置编译,然后用模块分别安装的方法安装
不知道为什么,我用第一种方法安装后找不到模块文件或者说无法启用这些支持的模块,所以最后采用的是第二种方法。

第一种方法的参数是

./configure
--prefix=/opt/mailserver/php5
--with-apxs2=/opt/mailserver/apache2/bin/apxs
--with-mysql=/opt/mailserver/mysql
--enable-mbstring
--with-imap=/opt/mailserver/imap
SSLTYPE=unix
--with-imap-ssl
--with-openssl
--with-config-file-path=/opt/mailserver/php5
cp php.ini-production /opt/mailserver/php5/php.ini


编译时,如果不加SSLTYPE=unix会出现错误,提示库不匹配,原因可能如下
this is because php won't use IMAP without SSL. for some people building IMAP with SSL doesn't work and the compile IMAP with this option SSLTYPE=none
in order to make IMAP compile u need to install openssl to this folder:
/usr/local/ssl
make shure u have the ssl libs accesible too in /usr/local/ssl/lib or /lib
after that IMAP should compile just fine with SSLTYPE=unix

 

参考:
http://www.phpbuilder.com/board/showthread.php?p=10944374

因为我的openssl是安装在/opt/mailserver/openssl上的,默认的是要查找/usr/local/ssl
所以要做如下链接
ln -s /opt/mailserver/openssl /usr/local/ssl


第二种方法

----------------------------------------------------------------------------------------------------------------------
使用php的常见问题是:编译php时忘记添加某扩展,后来想添加扩展,但是因为安装php后又装了一些东西如PEAR等,不想删除目录重装,于是可以采用phpize。方法是:
要有与现有php完全相同的php压缩包 。我用的是php-5.2.6.tar.gz。展开后进入里面的ext/mcrypt目录 (里面是mcrypt的php扩展),然后执行/usr/local/php/bin/phpize。phpize是安装php时安装好的一个工具,如果你的机器没有安装phpize工具,那么可能还是要make,make install php,仅仅为了得到phpize.
执行完后,会发现当前目录下多了一些configure文件,如果没报错,则根据提示运行
./configure --with-php-config=/usr/local/php/bin/php-config
注意要先确保/usr/local/php/bin/php-config存在。
make
make install
Php代码
./configure --with-php-config=/usr/local/php/bin/php-config
make install 之后系统会提示你mcrypt.so文件所在的目录。根据php.ini中指示的extension_dir指向的目录中, 将其复制过去。修改php.ini,在最后添加一句extension=mcrypt.so
----------------------------------------------------------------------------------------------------------------------
具体方法参考
http://bbs2.chinaunix.net/viewthread.php?tid=1472578

我的步骤如下
先进入php目录编译默认的Php5主要命令是
./configure
--prefix=/opt/mailserver/php5
--with-apxs2=/opt/mailserver/apache2/bin/apxs
--with-mysql=/opt/mailserver/mysql
--with-config-file-path=/opt/mailserver/php5
cp php.ini-production /opt/mailserver/php5/php.ini

然后安装imap模块和mbstring模块
cd ext
cd imap
/opt/mailserver/php5/bin/phpize //完成后,该目录会生成configure文件
./configure
--with-imap=/opt/mailserver/imap
--with-openssl
--with-php-config=/opt/mailserver/php5/bin/php-config

make
make install
从屏幕提示中得到模块文件的安装位置,将它拷贝到自己定制的extensions目录。
然后修改php.ini,在末尾加入extensions=/opt/mailserver/php5/extensions/imap.so
cd ext
cd mbstring
./configure
--enable-mbstring
--with-php-config=/opt/mailserver/php5/bin/php-config

make
make install
同上,拷贝模块文件后在php.ini中加入
然后重新启动apache2

安装:Postfixadmin

网络上橡皮老师有个postfixadmin安装讲座,采用的是2.1.1版本,该版本有个txt数据库脚本用来导入数据库,而2.2以上的版本不一样,所以安装步骤依据各个版本会有很大差别这里采用的版本是2.3版本,但是数据库生成部分不是按照INSTALL文件里的说明操作的。因为按照说明文件操作后,总是提示连接不上数据库,后来下载了2.1.1版本,从该版本中的txt脚本文件导入到数据库中,再按照下面的步骤进行操作。

cd /opt/mailserver
tar -xvzf ~/Desktop/postfixadmin-2.3.tar.gz
mv postfixadmin-2.3.1 postfixadmin
vi postfixadmin/config.inc.php

$CONF['configured'] = true;
$CONF['postfix_admin_url'] = '/postfixadmin';
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['encrypt'] = 'cleartext';
$CONF['emailcheck_resolve_domain] = 'NO';

打开/opt/mailserver/apache2/conf/httpd.conf文件,加入下面一行
Alias /postfixadmin /usr/share/postfixadmin

重启appache2服务
/opt/mailserver/apache2/bin/apachctl restart

在浏览器中打开http://localhost/postfixadmin/setup.php
如果没有错误,就直接生成数据库,并输入密码
如果提示错误,则需要解决错误。

通常的错误有
1.Php没有找到数据库支持。
2.无法连接数据库对应的sock
3.配置文件中的用户被拒绝访问数据库
4.配置文件中的用户没有权限创建数据库

第一个错误,通常是php编译的时候没有加入mysql支持

第二次错误,通常是sock文件目录权限设置错误,或者是sock文件路径定义的错误。
这个地方很复杂,php查找sock文件的配置可以再php.ini的文件中配置,而mysql启动时建立的sock文件路径可以再启动脚本中进行配置。一般sock所在文件夹用户和组都为
mysql,而且权限高于755或者直接设置成777,如果还是无法连接数据库,则应该检查
mysqld进程和mysqld_safe进程,保证这2个进程都被启动,特别在多个版本的mysql数据库被启动的时候。

第三个错误,通常是数据库的初始化错误。
这个地方也折腾了很长时间,对mysql删除用户和权限设置不熟悉,总是提示命令错误,无法创建用户,最后不得不采用重新安装数据库,
其实最彻底的方法就是重新安装mysql。

第四个错误,一般是因为配置文件的用户没有权限访问Postfix数据库,
手动进入mysqls数据库,加入下面的2句命令就可以了。
grant all privileges on postfix.* to postfixadmin@localhost identified by 'postfixadmin';
flush privileges;

如果setup.php那里没有错误,那么就可以设置系统密码,然后直接创建管理员账户了。
创建的系统密码,会自动生成hash值,并显示出来,将它替换config.inc.php文件中的
setup passwd项。

创建完管理员账号,打开http://localhost/postfixadmin/login
就可以开始管理账户了。

接下来开始进入配置文件
我基本上采用的是橡皮树老师的配置。
下面贴上配置文件

/etc/postfix/main.cf
#-------------postfix install------------------------------------------------
queue_directory = /opt/mailserver/postfix/spool
command_directory = /opt/mailserver/postfix/sbin
daemon_directory = /opt/mailserver/postfix/daemon
data_directory = /opt/mailserver/postfix/caches
mail_owner = postfix
unknown_local_recipient_reject_code = 550
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
debug_peer_level = 2
debug_peer_list = 127.0.0.1
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = /opt/mailserver/postfix/html
manpage_directory = /opt/mailserver/postfix/man
sample_directory = /etc/postfix
readme_directory = /opt/mailserver/postfix/readme
#----------------------------------------------------------------------------
#-------------------------------------base-----------------------------------
myhostname = mail.rcac.xhu.edu.cn
mydomain = rcac.xhu.edu.cn
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain
mynetworks = 127.0.0.0/8
inet_interfaces = all
#----------------------------------------------------------------------------

#-------------vritual mailbox settings----------------------------------------
#virtual_minimum_uid = static:50
virtual_uid_maps = static:2001
virtual_gid_maps = static:2001
virtual_transport = virtual
virtual_mailbox_base = /opt/mailserver/postfix/spool/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_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_alias_domains =
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_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his disk space 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,permit
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = /var/run/dovecot/auth-client
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner = $myhostname ESMTP "Version not Available"
#----------------------------------------------------------------------------

/etc/postfix/mysql_virtual_alias_maps.cf
#----------------------------------------------------------------------------
user = postfix
password = postfix
hosts = unix:/opt/mailserver/mysql/data/mysql/mysql.sock
dbname = postfix
table = alias
select_field = goto
where_field = address
#----------------------------------------------------------------------------

mysql_virtual_domains_maps.cf
#----------------------------------------------------------------------------
user = postfix
password = postfix
hosts = unix:/opt/mailserver/mysql/data/mysql/mysql.sock
dbname = postfix
table = domain
select_field = description
where_field = domain
#----------------------------------------------------------------------------

 

mysql_virtual_mailbox_limit_maps.cf
#----------------------------------------------------------------------------
user = postfix
password = postfix
#hosts = localhost
hosts = unix:/opt/mailserver/mysql/data/mysql/mysql.sock
dbname = postfix
table = mailbox
select_field = quota
where_field = username
#----------------------------------------------------------------------------

mysql_virtual_mailbox_maps.cf
#----------------------------------------------------------------------------
user = postfix
password = postfix
#hosts = localhost
hosts = unix:/opt/mailserver/mysql/data/mysql/mysql.sock
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#----------------------------------------------------------------------------


/etc/dovecot/dovecot.conf
#----------------------------------------------------------------------------
base_dir = /var/run/dovecot/
protocols = imap pop3
listen = *
auth_verbose=yes
auth_debug=yes
auth_debug_passwords=yes
mail_debug=yes
verbose_ssl=yes
disable_plaintext_auth = no
log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot-info.log
ssl = no
#ssl_disable = yes
mail_location = maildir:/opt/mailserver/postfix/spool/mailbox/%d/%n
auth default {
mechanisms = PLAIN LOGIN CRAM-MD5 DIGEST-MD5
passdb sql {
args=/etc/dovecot/dovecot-mysql.conf
}
userdb sql {
args=/etc/dovecot/dovecot-mysql.conf
}
user = root
socket listen {
client {
path = /var/run/dovecot/auth-client
mode = 0660
user=postfix
group=postfix
}
}
}
#----------------------------------------------------------------------------

/etc/dovecot/dovecot-mysql.conf
#----------------------------------------------------------------------------
driver = mysql
connect=host=/opt/mailserver/mysql/data/mysql/mysql.sock dbname=postfix user=postfix password=postfix
default_pass_scheme=plain
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir,2001 AS uid,2001 AS gid FROM mailbox WHERE username='%u'
#----------------------------------------------------------------------------


对于数据库的配置
直接下载postfixadmin 2.1.1版本,解压缩后有一个用户mysql的数据库生成语句写的txt文件直接导入到mysql即可,然后再根据上面所说的方法配置postfixadmin。

对于SquirrelMail 的配置比较简单
解压缩后,运行目录下的./configure就会进入配置文件
具体步骤如下

root@node8:/opt/mailserver/squirrelmail # ./configure
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color on
S Save data
Q Quit

Command >>

选择1
Command >> 1
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : rcac
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : rcac
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://rcac.xhu.edu.cn/postfixadmin/users
8. Provider name : change password

R Return to Main Menu
C Turn color on
S Save data
Q Quit

Command >>

修改Organization Name Organization Title 返回
选择2

Command >> 2
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings

General
-------
1. Domain : rcac.xhu.edu.cn
2. Invert Time : false
3. Sendmail or SMTP : SMTP

A. Update IMAP Settings : localhost:143 (dovecot)
B. Update SMTP Settings : localhost:25

R Return to Main Menu
C Turn color on
S Save data
Q Quit
修改域名,和服务器类型,此处是smtp,修改A对应的imap软件名以及端口等,返回
选择4修改全局设置

Command >> 4
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
General Options
1. Data Directory : /srv/www/rcac/webmail/attachments/
2. Attachment Directory : /srv/www/rcac/webmail/data/
3. Directory Hash Level : 0
4. Default Left Size : 150
5. Usernames in Lowercase : false
6. Allow use of priority : true
7. Hide SM attributions : false
8. Allow use of receipts : true
9. Allow editing of identity : true
Allow editing of name : true
Remove username from header : false
10. Allow server thread sort : false
11. Allow server-side sorting : false
12. Allow server charset search : true
13. Enable UID support : true
14. PHP session name : SQMSESSID
15. Location base :
16. Only secure cookies if poss. : true
17. Disable secure forms : false
18. Page referal requirement :

R Return to Main Menu
C Turn color on
S Save data
Q Quit

Command >>
修改Data Directory,Attachment Directory,这个目录的权限需要设置成777

最后选择S保存推出。
此时所有参数都是写在config.php文件中,为了邮件用户能够通过webmail改密码,需要修改config.php文件中的下面2个参数

$provider_uri = 'http://rcac.xhu.edu.cn/postfixadmin/users'; //到postfixadmin的接口。
$provider_name = 'change password';

接下来
在目录/srv/www/rcac/处新建2个连接
ln -s /opt/mailserver/SquirrelMail /srv/www/rcac/webmail
ln -s /opt/mailserver/postfixadmin /srv/www/rcac/postfixadmin

然后再httpd.conf中将/srv/www/rcac/加到根目录

访问主页下的weimail即进入登陆界面,填写在postfixadmin中已经定义的帐户和密码即可登陆web邮箱了。


总结:

此次配置主要有如下难点

1. Mysql数据库的导入,虽然原理很简单,但是总是提示用户已经存在,原因是采用2.2.3的方法加入建立的数据库,后来又想通过2.1.1的方法来导入,最后想删除用户却总是删除不了用户信息,不得不重新安装mysql
2. Php5总是连接不上mysql,提示无法连接到sock文件,或者是用户没有权限,最终查到原因是mysql的启动不完整,以及my.cnf配置文件中的sock文件小错误。
3. Php5的imap模块的安装,这个地方总是会出现编译错误,找不到库文件。

4. Postfix中关于mysql的sock路径指定参数,Google了很长时间,才找到这个配置参数。

否则总是在取数据库那里出错,因为它默认利用的是/tmp/mysql.sock

5. postfix uid和gid最好要大于100或更高,否则虽然安装橡皮树老师设置的方法,最后还是不能成功,我最后采用了2001这个很高的uid和gid.

 


参考:

postfix系统用户smtp认证超简单配置
http://www.redlinux.org/read.php?tid-481.html

openssl+cyrus-sasl2+Berkeley DB+postfix
特点:
1) 本地系统用户
2) 不使用数据库
3) 使用dovecot做smtp认证,简单实用
4) 安装配置过程简单


linux下编译postfix时,使其支持mysql,ldap,sasl,ssl的脚本
http://lovesea.blog.51cto.com/382446/102732

 

redhat4.0up2+postfix+dovecot (源码安装) 实现虚拟用户,SMTP认证,POP3
http://hi.baidu.com/suping/blog/item/a03b793e5664ee3170cf6cc1.html

 

postfix+sasl+mysql+dovecot+apache+php 邮件服务器成功配置笔记
http://oldhand.3ren.com/profiles/blog/show?id=2795388334018897%3ABlogPost%3A2888407217226852

 

Exmail论坛
http://www.extmail.org/forum/

 

linux 用icc编译mysql
http://www.boobooke.com/bbs/thread-2999-1-1.html

 

linux下编译安装postfix+mysql+dovecot+postfixadmin
http://www.nginxs.com/linux/69.html

 

OpenLdap 与 BerkeleyDB 安装过程

http://blog.chinaunix.net/u1/56685/showart_1830385.html

 

Linux Apache2 + mysql5 + php5安装详解
http://linux.chinaunix.net/techdoc/database/2008/03/04/981250.shtml

 

邮件系统的安装
http://bbs.chinaunix.net/viewthread.php?tid=987344


Php imap的安装
http://hi.baidu.com/chenshake/blog/item/8266d4eae70d4cd6d439c9f9.html
http://www.phpbuilder.com/board/showthread.php?p=10944374


postfixadmin
http://www.linuxmail.info/postfix-admin-howto-centos-5/


php扩展的安装
http://bbs2.chinaunix.net/viewthread.php?tid=1485530


实用命令:利用openssl进行BASE64编码解码、md5/sha1摘要、AES/DES3加密解密
http://www.cppblog.com/sleepwom/archive/2010/01/05/104818.html
Trouble with virtual delivery
http://archives.neohapsis.com/archives/postfix/2005-04/0147.html


用SMTP/POP3访问邮箱暨SMTP/POP3原理
http://blog.163.com/sq-shi/blog/static/9310552120094173533027/


postfix virtual MySQL
hosts = unix:/var/run/mysqld/mysqld.sock
http://www.postfixvirtual.net/postfixconf.html


Trouble with virtual delivery
http://archives.neohapsis.com/archives/postfix/2005-04/0147.html


postfix+dovecot+postfixadmin+mysql认证
http://bbs.chinaunix.net/viewthread.php?tid=1638787


RHEL4上安装基于postfix的全功能邮件服务器(全部使用目前最新源码包构建)
http://www.chinaunix.net/jh/14/987344.html


apache 动态编译 静态编译
http://hi.baidu.com/sheshi37c/blog/item/0455247fc7c1450029388a1e.html


Postfix电子邮件系统完整安装教程
http://www.info110.com/map.asp?pid=14824


ExtMail Solution HOWTO for Linux
http://www.extmail.org/docs/extmail_solution_linux/#extmail


How to set up a mail server on a GNU / Linux system
Ubuntu + Postfix + Courier IMAP + MySQL + Amavisd-new +
SpamAssassin + ClamAV + SASL + TLS + SquirrelMail/Roundcube + Postgrey
http://flurdy.com/docs/postfix/


Mail server HOWTO
Postfix + Dovecot +Mysql+TLS/SSL+postgrey+DSPAM
http://johnny.chadda.se/article/mail-server-howto-postfix-and-dovecot-with-mysql-and-tlsssl-postgrey-and-dspam/


Creating a Linux Mail Server
(Postfix, Procmail, Fetchmail, SpamBayes, Courier-imap, Mutt, SquirrelMail)
http://www.hypexr.org/linux_mail_server.php


Secure Virtual Mailserver HOWTO
Postfix + OpenLDAP + Dovecot + Jamm + SASL + SquirrelMail
http://wanderingbarque.com/howtos/mailserver/mailserver.html

 

Debian Mail Server Setup with Postfix + Dovecot + SASL + Squirrel Mail
http://www.debianadmin.com/debian-mail-server-setup-with-postfix-dovecot-sasl-squirrel-mail.html


How to setup Relay host in mail server
http://webmail.tm.net.my/info/smtp-proxy.html

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值