打印

如何使用完全虚拟域名搭建openwebmail

如何使用完全虚拟域名搭建openwebmail

第一目标:组建不使用任何系统账户的openwebmail,暂时只是可以登陆,无实际功能,没有过滤、反垃圾邮件、防病毒、webdisk等功能
同时:1、邮件系统管理员可以管理帐号,暂时只设置添加功能
2、用户可以自行修改密码
第二目标:配置和使用postfix和dovecot配合一起工作
第三目标:开启过滤(smtp和openwebmail)、反垃圾邮件、防病毒、webdisk等功能
第四目标:优化过程,写出脚本——对centos4.3系统

前提:
1、禁止了sendmail,安装好postfix、dovecot、openwebmail-2.52-1.i386.rpm等RPM包。
2、做好了DNS的相关解析,比如A记录和MX记录


操作过程:
1、建立虚拟域名需要的文件和目录
mkdir /etc/virtual
mkdir /var/spool/virtual
mkdir /etc/virtual/DOMAINNAME
touch /etc/virtual/DOMAINNAME/passwd
chmod 644 /etc/virtual/DOMAINNAME/passwd
mkdir /var/spool/virtual/DOMAINNAME
chown nobody.mail /var/spool/virtual/DOMAINNAME

2、添加邮件系统管理员的用户名和密码,不可用默认的sysadm,这里新添加一个mailadmin
htpasswd /etc/virtual/DOMAINNAME/passwd mailadmin
随后输入两次密码,请记录这个密码,改账户为邮件系统管理员的账户名和密码

###以上操作参/var/www/cgi-bin/openwebmail/etc/defaults/auth_vdomain.conf的说明
3、创建对应DOMAINNAME的配置文件
touch /var/www/cgi-bin/openwebmail/etc/sites.conf/DOMAINNAME
编辑刚创建的文件,添加以下行:
mailspooldir /var/spool/virtual/DOMAINNAME
auth_withdomain yes
auth_module auth_vdomain.pl
domainnames DOMAINNAME
use_homedirspools no
use_syshomedir no
enable_autoreply no
enable_setforward no

enable_vdomain yes
vdomain_admlist mailadmin
vdomain_maxuser 100
vdomain_vmpop3_pwdpath /etc/virtual
vdomain_vmpop3_pwdname passwd
vdomain_vmpop3_mailpath /var/spool/virtual
vdomain_postfix_aliases /etc/postfix/aliases
vdomain_postfix_virtual /etc/postfix/virtual
vdomain_postfix_postalias /usr/sbin/postalias
vdomain_postfix_postmap /usr/sbin/postmap

enable_changepwd yes

保存以上添加内容

4、修正BUG:在虚拟域的邮件管理员登陆后发现管理账户的时候出现错误以及临时的文件权限
此处的问题主要是perl脚本的问题,可否以后使用对应的current版本的非RPM包解决

Undefined subroutine &ow::htmltext::str2html called at /var/www/cgi-bin/openwebmail/shares/ow-shared.pl line 1283.
根据http://www.freebsd.org/cgi/query-pr.cgi?pr=97171
参考http://openwebmail.acatysmoof.co ... 00605/msg00030.html
到/var/www/cgi-bin/openwebmail/openwebmail.pl的44行和/var/www/cgi-bin/openwebmail/shares/ow-shared.pl的23行添加

require "modules/htmltext.pl";

5、权限配置
以下操作属于postfix配置文件权限的问题
chown root.mail /etc/postfix/virtual
chown root.mail /etc/postfix/aliases
chmod 666 /etc/postfix/virtual
chmod 666 /etc/postfix/aliases
随后即可达到第一阶段目标

6 系统初始化
/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init
cp /var/www/cgi-bin/openwebmail/etc/defaults/dbm.conf /var/www/cgi-bin/openwebmail/etc
按照提示修改对应的文件
vi /var/www/cgi-bin/openwebmail/etc/dbm.conf
内容:
dbm_ext .db
dbmopen_ext .db
dbmopen_haslock no
重新初始化:
/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init

至此不用任何系统账户的认证可以可以使用mailadmin@DOMAINNAME登陆openwebmail。

至此第一阶段工作完成。

注意:
此处的帐号修改并没有更新postfix的DB文件,还需要postalias postmap来更新,以后是否会改进?现在是否更新了对应的DB文件不知。
应该是自动更新的,或者使用脚本可以达到此的目标。注意重新加载postfix的配置文件


第二目标:配置和使用postfix和dovecot配合一起工作
1、获取最新的postfix和dovecot
官方网站
http://www.dovecot.org/
http://atrpms.net/name/dovecot/
http://dl.atrpms.net/all/dovecot-1.0-0_17.rc2.el4.at.i386.rpm
就是说使用1.0版本的dovecot

http://www.postfix.org/
http://postfix.wl0.org/en/
http://ftp.wl0.org/official/2.2/ ... 10-4.rhel4.i386.rpm
使用2.2.10版本的postfix

2.1、首先配置使用dovecot的pop3功能,编辑/etc/dovecot.conf文件,修改以下
#protocols = imap imaps pop3 pop3s
protocols = imap imaps pop3 pop3s
protocols = pop3 pop3s

完全开启pop3的支持,后面的参数暂时使用推荐
##pop3_uidl_format = %08Xu%08Xv
pop3_uidl_format = %08Xu%08Xv

------------------------------------
按照以前的提示,需要修改
auth_passdb = pam
更改为:
auth_passdb = shadow
但是新版本改变,以下为修改部分
------------------------------------
##auth_default_realm =
为使用虚拟域名设置
auth_default_realm = zjlsoft.net

下面的修改参考了http://wiki.dovecot.org/QuickCon ... 3e36b9099f25824c074
官方网站的快速设定并结合了虚拟帐号的东西

2.2、虚拟帐号使用认证信息
定义账户密码存放文件
###### passwd-like file with specified location
#passdb passwd-file {
# Path for passwd-file
#args =
#}
passdb passwd-file {
# Path for passwd-file
args = /etc/virtual/zjlsoft.net/passwd
}

userdb static {
args = uid=99 gid=99 home=/home/ mail=mbox:/var/spool/virtual/zjlsoft.net/%n nice=10
}

由于我们的passwd中不包含域名信息,所以需要去掉域名
##auth_username_format =
更改
auth_username_format = %n

同时要注释掉默认的PAM认证方式或者调整顺序,如果此处不注释掉,dovecot会使用这个而不是passwd那个文件认证,会出现错误。
##passdb pam {
##}

2.3、邮件存储的位置
这里不确定是mailbox还是maildir,暂时使用mailbox的格式
##default_mail_env =
default_mail_env = mbox:/var/spool/virtual/zjlsoft.net/:INDEX=/var/indexes/zjlsoft.net/%n

确认给与mail组权限修改邮件,似乎不是很必要
##mail_extra_groups =
mail_extra_groups = mail xxxxxxxxxxxxxxxxxx

改善性能设置,可选
##mbox_lazy_writes = yes
mbox_lazy_writes = yes xxxxxxxxxxxxxxxxxx

##maildir_copy_with_hardlinks = no
maildir_copy_with_hardlinks = yes xxxxxxxxxxxxxxxxx

至此pop3的服务基本可以用,可以使用虚拟账户进行收邮件的工作,dovecot会使用虚拟帐号认证通过。
存在问题:
必须先使用dovecot的登陆创建/var/spool/virtual/zjlsoft.net/yonghu
否则会产生死锁的问题,造成webmail不能登陆!

3、设置postfix使用虚拟域名
vm的前提:
# 1. the virtual user have to login openwebmail with USERNAME@VIRTUALDOMAIN
# 2. passwd file for each virtual domain is /etc/virtual/VIRTUALDOMAIN/passwd
# 3. mailspool for each user is /var/spool/virtual/VIRTUALDOMAIN/USERNAME
# 4. homedir for each user is $config{ow_usersdir}/USERNAME@VIRTUALDOMAIN
3.1 设置postfix的虚拟域名

zjlsoft.net anything
mailadmin@zjlsoft.net mailadmin.zjlsoft.net
设置好后用postmap /etc/postfix/virtual更新DB文件

3.2 设置postfix的别名规则,并将root的邮件转给mailadmin
root: /var/www/cgi-bin/openwebmail/etc/users/zjlsoft.net/mailadmin
mailadmin.zjlsoft.net: /var/www/cgi-bin/openwebmail/etc/users/zjlsoft.net/mailadmin
设置好后用postalias /etc/postfix/aliases更新别名数据库

在postfix创建邮箱的时候,使用的UID和GID按照以下规则:
GID使用mail的
UID在alias.db属于root用户的时候由main.cf中的default_privs确定(默认为nobody),非root用户则由该用户的UID确定
ID可以使用id 命令查看,这里一般为99和12

3.3 设置对应虚拟域名的权限
mkdir /var/spool/virtual/zjlsoft.net
chown root.mail /var/spool/virtual/zjlsoft.net
chmod og+wt /var/spool/virtual/zjlsoft.net

3.4 修改/etc/postfix/main.cf,添加或者修改
virtual_alias_maps=hash:/etc/postfix/virtual
alias_maps=hash:/etc/postfix/alias, $alias_database
default_privs=nobody

3.5 参考postfix的虚拟域名指引

-------------------------------------------
Postfix virtual MAILBOX example: separate domains, non-UNIX accounts××××××××××××××××××××××××
postfix虚拟邮件,独立域名,非系统账户
Here is an example of a virtual mailbox domain "example.com":
1 /etc/postfix/main.cf:
2 virtual_mailbox_domains = example.com ...more domains...
--virtual_mailbox_domains (default: $virtual_mailbox_maps)
--默认就是$virtual_mailbox_maps,需要设置和生成那个virtural文件及相关DB
忽略这个就不能收到或者发送虚拟域名的邮件,可指定或者生成,在一个域名的时候选择下
!!不要把这个域名在mydestination里列出
!!NEVER list a virtual MAILBOX domain name as a virtual ALIAS domain

3 virtual_mailbox_base = /var/mail/vhosts
没有 需要添加,设置相应路径,参前应该为/var/spool/virtrual/zjlsoft.net,避免作为系统邮件使用系统地址

4 virtual_mailbox_maps = hash:/etc/postfix/vmailbox
没有 是否需要添加?或者可以指向aliase?或passwd那个文件
参照下面的10 13 14行制作一个文件

5 virtual_minimum_uid = 100
最小user id,默认100,根据$virtual_uid_maps的表确定,小于这个值将被延迟
安全考虑?避免冲击系统账户

6 virtual_uid_maps = static:5000
默认是空值,????是否和dovecot和openwebmail相关
7 virtual_gid_maps = static:5000
默认是空值,????是否和dovecot和openwebmail相关
6-7可以根据需要指定,例子是一个比较安全的范围

8 virtual_alias_maps = hash:/etc/postfix/virtual
就是virtural那个文件,更改那个文件后必须用postmap /etc/postfix/virtual来更新新的DB
和下面的17 18是混合virtual aliases 和 virtual mailboxes,主要是重定向,这里是技巧

9
10 /etc/postfix/vmailbox:
11 info@example.com example.com/info
12 sales@example.com example.com/sales/
13 # Comment out the entry below to implement a catch-all.
14 # @example.com example.com/catchall
--how one would implement a catch-all virtual mailbox address. Be prepared to receive a lot of spam, as well as bounced --spam that was sent in the name of anything@example.com.
!!!NEVER put a virtual MAILBOX wild-card in the virtual ALIAS file!!

15 ...virtual mailboxes for more domains...
16
17 /etc/postfix/virtual:
18 postmaster@example.com postmaster
18的例子假定main.cf中的$myorigin在mydestination中列出,如果不是则需要在virtual alias table中指定,否则邮件将错误。

——————————————————————————————————————————————————————————————————————————————————————————————————————————
Non-Postfix mailbox store: separate domains, non-UNIX accounts
非postfix邮件格式存储,独立域名,非系统账户
比上一个相比增加了转换的设定,少了一点设定。

参考的地址类型
The local domain class.

Purpose: final delivery for traditional UNIX system accounts and traditional Sendmail-style aliases. This is typically used for the canonical domains of the machine. For a discussion of the difference between canonical domains, hosted domains and other domains, see the VIRTUAL_README file.

Domain names are listed with the mydestination parameter. This domain class also includes mail for user@[ipaddress] when the IP address is listed with the inet_interfaces or proxy_interfaces parameters.

Valid recipient addresses are listed with the local_recipient_maps parameter, as described in LOCAL_RECIPIENT_README. The Postfix SMTP server rejects invalid recipients with "User unknown in local recipient table". If the local_recipient_maps parameter value is empty, then the Postfix SMTP server accepts any address in the local domain class.

The mail delivery transport is specified with the local_transport parameter. The default value is local:$myhostname for delivery with the local(8) delivery agent.

The virtual alias domain class.

Purpose: hosted domains where each recipient address is aliased to a local UNIX system account or to a remote address. A virtual alias example is given in the VIRTUAL_README file.

Domain names are listed in virtual_alias_domains. The default value is $virtual_alias_maps for Postfix 1.1 compatibility.

Valid recipient addresses are listed with the virtual_alias_maps parameter. The Postfix SMTP server rejects invalid recipients with "User unknown in virtual alias table". The default value is $virtual_maps for Postfix 1.1 compatibility.

There is no mail delivery transport parameter. Every address must be aliased to some other address.

The virtual mailbox domain class.

Purpose: final delivery for hosted domains where each recipient address can have its own mailbox, and where users do not need to have a UNIX system account. A virtual mailbox example is given in the VIRTUAL_README file.

Domain names are listed with the virtual_mailbox_domains parameter. The default value is $virtual_mailbox_maps for Postfix 1.1 compatibility.

Valid recipient addresses are listed with the virtual_mailbox_maps parameter. The Postfix SMTP server rejects invalid recipients with "User unknown in virtual mailbox table". If this parameter value is empty, the Postfix SMTP server accepts all recipients for domains listed in $virtual_mailbox_domains.

The mail delivery transport is specified with the virtual_transport parameter. The default value is virtual for delivery with the virtual(8) delivery agent.

The relay domain class.

Purpose: mail forwarding to remote destinations that list your system as primary or backup MX host. For a discussion of the basic configuration details, see the BASIC_CONFIGURATION_README document. For a discussion of the difference between canonical domains, hosted domains and other domains, see the VIRTUAL_README file.

Domain names are listed with the relay_domains parameter.

Valid recipient addresses are listed with the relay_recipient_maps parameter. The Postfix SMTP server rejects invalid recipients with "User unknown in relay recipient table". If this parameter value is empty, the Postfix SMTP server accepts all recipients for domains listed with the relay_domains parameter.

The mail delivery transport is specified with the relay_transport parameter. The default value is relay which is a clone of the smtp(8) delivery agent.

The default domain class.

Purpose: mail forwarding to the Internet on behalf of authorized clients. For a discussion of the basic configuration details, see the BASIC_CONFIGURATION_README file. For a discussion of the difference between canonical domains, hosted domains and other domains, see the VIRTUAL_README file.

This class has no destination domain table.

This class has no valid recipient address table.

The mail delivery transport is specified with the default_transport parameter. The default value is smtp for delivery with the smtp(8) delivery agent.

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-9-5 14:42 京ICP证060528 号

Designed By 17DST