rss· 投稿· 设为首页· 加入收藏· 繁體版

基于CentOS5.2的Postfix与Extmail结合

转自http://www.boobooke.com/bbs/hushan1985作品
我选用的Linux版本是CentOS5.2(好像是最新的吧),在初期安装系统时,对于服务器所需的RPM包我基本都安装了,避免在实验中出现RPM依赖关系,这样不太好,呵呵~~~~基本配置如下:
IP地址是192.168.1.200,网关是192.168.1.1(我选用的是虚机,为了解析互联网地址,我把网关指向了这个IP)。主机名是mail.benet.com。
    邮件服务器的概况是基于独立网域搭配虚拟账号
第一部分 配置DNS
1. 基本配置
[root@mail ~]# vi /etc/named.rfc1912.zones
zone "benet.com" IN {
        type master;
        file "benet.com.zone";
        allow-update { none; };
};zone "1.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.1.rev";
        allow-update { none; };
};
#添加两个域的设置(正向和反向),没加提示的就保持原来的配置,后面一样第四部分 安装配置Extmail和Extman
   哈哈~~~~终于轮到我自己研究的东西了,希望能让大家满意!!!!
1. 安装配置Extmail
[root@mail ~]# tar -zvxf extmail-1\[1\]\[1\].0.4.tar.gz
#这个包和下面的Extman包可以到网上下载
[root@mail ~]# mv extmail-1.0.4/ /var/www/cgi-bin/extmail
[root@mail ~]# cd /var/www/cgi-bin/extmail/
[root@mail extmail]# cp webmail.cf.default webmail.cf
[root@mail extmail]# vi webmail.cf
SYS_CONFIG = /var/www/extsuite/extmail/修改为SYS_CONFIG = /var/www/cgi-bin/extmail/SYS_LANGDIR = /var/www/extsuite/extmail/lang修改为SYS_LANGDIR = /var/www/cgi-bin/extmail/langSYS_TEMPLDIR = /var/www/extsuite/extmail/html修改为SYS_TEMPLDIR = /var/www/cgi-bin/extmail/htmlSYS_SESS_DIR = /tmp/修改为SYS_SESS_DIR = /tmp/extmail
#需要手工创建并赋予权限SYS_USER_LANG = en_US修改为SYS_USER_LANG = zh_CNSYS_USER_CHARSET = utf-8修改为SYS_USER_CHARSET = gb2312SYS_MAILDIR_BASE = /home/domains修改为SYS_MAILDIR_BASE = /var/spool/mail
#这个修改是为了和Postfix和Dovecot一致SYS_MYSQL_USER = db_user修改为SYS_MYSQL_USER = extmailSYS_MYSQL_PASS = db_pass修改为SYS_MYSQL_PASS = extmailSYS_MYSQL_ATTR_NDQUOTA = netdiskquota修改为SYS_MYSQL_ATTR_NDQUOTA = quotaSYS_G_ABOOK_FILE_PATH = /var/www/extsuite/extmail/globabook.cf修改为SYS_G_ABOOK_FILE_PATH = /var/www/cgi-bin/extmail/globabook.cfSYS_G_ABOOK_FILE_CHARSET = utf-8修改为SYS_G_ABOOK_FILE_CHARSET = gb2312
#上面很多都修改了路径,原因是与等下需要配置的Apache服务想对应,因为看别人文档按照做时,连链接都打不开,所以我用我自己喜欢的配置路径来解决,所以要修改的地方很多
[root@mail extmail]# chown -R postfix:postfix cgi/
[root@mail extmail]# mkdir /tmp/extmail
[root@mail extmail]# chown -R postfix.postfix /tmp/extmail/
[root@mail perl]# rpm -ivh perl-Unix-Syslog-1.0-1.el5.rf.i386.rpm
#需要Perl-Unix-Syslog的支持,这个perl包和下面的需要安装的Perl包都可以到网上下载到,提示个地址给大家http://dag.wieers.com/rpm/packages/2. 安装配置Extman
[root@mail ~]# tar -zvxf extman-0\[1\]\[1\].2.4.tar.gz
[root@mail ~]# mv extman-0.2.4/ /var/www/cgi-bin/extman
[root@mail ~]# cd /var/www/cgi-bin/extman/
[root@mail extman]# vi webman.cf
SYS_CONFIG = /var/www/extsuite/extman/修改为SYS_CONFIG = /var/www/cgi-bin/extman/SYS_LANGDIR = /var/www/extsuite/extman/lang修改为SYS_LANGDIR = /var/www/cgi-bin/extman/langSYS_TEMPLDIR = /var/www/extsuite/extman/html修改为SYS_TEMPLDIR = /var/www/cgi-bin/extman/htmlSYS_MAILDIR_BASE = /home/domains修改为SYS_MAILDIR_BASE = /var/spool/mail添加SYS_LANG = zh_CN
    SYS_CHARSET = gb2312SYS_MYSQL_USER = webman修改为SYS_MYSQL_USER = extmailSYS_MYSQL_PASS = webman修改为SYS_MYSQL_PASS = extmail[root@mail extman]# chown -R postfix.postfix cgi/
[root@mail extman]# mkdir /tmp/extman
[root@mail extman]# chown -R postfix.postfix /tmp/extman
[root@mail perl]# rpm -ivh perl-GD-2.35-1.el5.rf.i386.rpm第五部分 配置Apache
[root@mail ~]# vi /etc/httpd/conf/httpd.conf
User postfix
Group postfix
#非常非常重要,使之以用户Postfix来识别Suexec模块,我的理解!!之后会因为这个配置没有修改会出现权限问题,相当之郁闷
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mail.benet.com
DocumentRoot /var/www/cgi-bin/
ScriptAlias /extmail/cgi/ /var/www/cgi-bin/extmail/cgi/
Alias /extmail/ /var/www/cgi-bin/extmail/html/
ScriptAlias /extman/cgi/ /var/www/cgi-bin/extman/cgi/
Alias /extman/ /var/www/cgi-bin/extman/html/
</VirtualHost>
[root@mail perl]# chkconfig httpd on
[root@mail perl]# /etc/rc.d/init.d/httpd start
访问http://192.168.1.200/extmail和http://192.168.1.200/extman,只要看到页面即可,因为没有配置MySQL,所以很多管理工作做不成~~~~~~第六部分 配置MySQL
[root@mail ~]# chkconfig mysqld on
[root@mail ~]# /etc/rc.d/init.d/mysqld start
#第一次启动会有初始化过程
[root@mail ~]# mysqladmin -u root password 123456
[root@mail ~]# mysql -u root -p
Enter password:
[root@mail ~]# mysql -u root -p < /var/www/cgi-bin/extman/docs/extmail.sql
Enter password:
[root@mail ~]# mysql -u root -p < /var/www/cgi-bin/extman/docs/init.sql
Enter password:
#上面就是把相关的数据库导入到MySQL里面
[root@mail ~]# /etc/rc.d/init.d/mysqld restart
[root@mail ~]# mysql -u extmail -p
#用命令show databases;来查看表是否导入,当然了,进入时的密码就是Extmail第七部分 测试
    再次访问http://192.168.1.200/extman,进入管理界面,默认内置账号是root@extmail.org(不能修改),密码是extmail*123*     。(句号放开点)
    我创建第一个域benet.com时,会提示“添加benet.com失败,原因:INSERT command denied to user 'extmail'@'localhost' for table 'domain'”,所以我们还要给extmail再MySQL中赋予权限
[root@mail ~]# mysql Cu root -p
mysql> grant all privileges on *.* to 'extmail'@'localhost' identified by 'extmail' with grant option;
#给的权限很大了~~~~~~
    好了,再次添加域和用户,在进入http://192.168.1.200/extmail进行用户登陆收发邮件,当然,最开始提到是搭建独立网域搭配虚拟用户,所以可以创建benet.com相关的子域sales.benet.com等等,当然不用去修改DNS的配置!!!!     好累,我写完了,如果大家喜欢,顶一下,这是给我最大的动力了!!!之后我会对邮件的安全的相关配置进行研究,力求大家都喜欢~~~~!!!!![root@mail ~]# cd /var/named/chroot/var/named
[root@mail named]# vi benet.com.zone
$TTL    86400
@               IN SOA          mail.benet.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@       IN      NS      mail.benet.com.
mail    IN      A       192.168.1.200
@       IN      MX      5       mail.benet.com.[root@mail named]# vi 192.168.1.rev
$TTL    86400
@               IN SOA          mail.benet.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@       IN      NS      mail.benet.com.
200     IN      PTR     mail.benet.com.[root@mail named]# vi /etc/resolv.conf
nameserver 127.0.0.1
[root@mail named]# chkconfig named on
[root@mail named]# /etc/rc.d/init.d/named start
2. 测试
使用命令nslookup和dig查看是否能够解析域名,也可以去解析互联网地址,但是我觉得意义不大,我没有注册域名服务,所以不能对公网提供服务,注意2点:一是需要设置网关才能解析,在上面已经提示;二是默认安装时没有caching-nameserver这个包,所以到安装光盘下查找到并安装。第二部分 安装配置Postfix
1. 安装配置Postfix
[root@mail ~]# rpm -ivh postfix-2.3.3-2.src.rpm
[root@mail ~]# cd /usr/src/redhat/SPECS/
[root@mail SPECS]# vi postfix.spec
%define MYSQL 0修改为%define MYSQL 1
#使其支持MySQL服务。这些配置方法和橡皮树老师中视频的所需的软件包一样,如果嫌麻烦,可以到论坛搜橡皮树老师的视频,而且提示了所需软件包
[root@mail SPECS]# rpmbuild -ba postfix.spec
#我用真机安装时时间很短,但是我用虚机编译了很长时间(大概15分钟),所以要有耐心,不要中途觉得编译不正确而停止,这样你会更痛苦
[root@mail SPECS]# cd /usr/src/redhat/RPMS/i386/
[root@mail i386]# rpm -ivh postfix-2.3.3-2.i386.rpm
[root@mail ~]# cd /etc/postfix/
[root@mail ~]# mv main.cf main.cf.bak
#将原来配置更换名字做个备份
[root@mail ~]# vi main.cf
#=====================BASE=========================
myhostname = mail.benet.com
mydomain = benet.com
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain
mynetworks = 127.0.0.0/8, 192.168.1.0/24
inet_interfaces = all
#=====================Vritual Mailbox settings=========================
virtual_minimum_uid = 88
virtual_mailbox_base = /var/spool/mail
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:89
virtual_gid_maps = static:89
virtual_transport = virtual
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 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,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"readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/local/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
#这个配置文档是拿橡皮树老师的用的,很多也不知道意思,我只了解一些基本的配置参数的意义,呵呵   下面是4个与MySQL相关的配置,与橡皮树老师不同的是我后面将导入的数据库名称是Extmail,所以这里要做调整,Dovecot的配置也是一样,怎么导入数据库将在后面写出来;
[root@mail postfix]# vi mysql_virtual_alias_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = alias
select_field = goto
where_field = address
additional_conditions = AND active = '1'[root@mail postfix]# vi mysql_virtual_domains_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = domain
select_field = description
where_field = domain
additional_conditions = AND active = '1'[root@mail postfix]# vi mysql_virtual_mailbox_limit_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = mailbox
select_field = quota
where_field = username
additional_conditions = AND active = '1'[root@mail postfix]# vi mysql_virtual_mailbox_maps.cf
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = mailbox
select_field = maildir
where_field = username
additional_conditions = AND active = '1'[root@mail postfix]# chkconfig postfix on
[root@mail postfix]# chkconfig sendmail off
[root@mail postfix]# /etc/rc.d/init.d/sendmail stop
#需把Sendmail服务停掉
[root@mail postfix]# /etc/rc.d/init.d/postfix start
    好了,到此,Postfix的基本配置已经完成,如果启动成功就好了~~~~~第三部分 配置Dovecot
[root@mail postfix]# cp /etc/dovecot.conf /etc/dovecot.conf.bak
[root@mail postfix]# vi /etc/dovecot.conf
base_dir=/var/run/dovecot
protocols=imap pop3
listen=*
disable_plaintext_auth = no
ssl_disable = yes
mail_location = maildir:/var/spool/mail/%d/%n/Maildirauth default {
        mechanisms = PLAIN LOGIN CRAM-MD5 DIGEST-MD5
        passdb sql {
                args = /etc/dovecot-mysql.conf
        }
        userdb sql {
                args = /etc/dovecot-mysql.conf
        }
        socket listen {
                client {
                        path = /var/run/dovecot/auth-client
                        mode = 0660
                        user = postfix
                        group = postfix
                }
        }
}
first_valid_uid = 89[root@mail postfix]# vi /etc/dovecot-mysql.conf
#这个配置文件需要手工创建的,与MySQL联系
river = mysql
connect = host=/var/lib/mysql/mysql.sock dbname=extmail user=extmail password=extmail
default_pass_scheme = MD5
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 89 AS uid, 89 AS gid FROM mailbox WHERE username = '%u'[root@mail postfix]# chkconfig dovecot on
[root@mail postfix]# /etc/rc.d/init.d/dovecot start
顶一下
(0)
踩一下
(0)