全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 10375|回复: 6

[经验] CentOS 5.5 邮件服务器 postfix dovecot postfixadmin squirrelmail 配置

[复制链接]
发表于 2010-7-5 14:27:12 | 显示全部楼层 |阅读模式
本帖最后由 Host.HowPick 于 2012-5-20 18:20 编辑

文档比较长,Dz里面不好排版,需要看详细内容的朋友可以访问我们网站的文档区。

http://serveryou.com/articles


安装Postfix之前,你可能需要删除系统中已经带的sendmail。

yum -y remove sendmail

到 Postfix官方网站 http://www.postfix.org/ 选择下载点下载最新的稳定版源码。


1        wget http://www.tigertech.net/mirrors/postfix-release/official/postfix-2.7.1.tar.gz #下载
2        tar zxvf postfix-2.7.1.tar.gz #解压
3        cd postfix-* #进入 postfix目录

安装依赖包:

1        yum install -y db*-devel

安装 cyrus-sasl

1        yum install cyrus-sasl cyrus-sasl-devel

添加postfix需要的帐号 postfix 和 组postdrop。

1        adduser postfix --shell /bin/false -M
2        groupadd postdrop

安装Mysql数据库,如何安装Mysql数据库,请暂时查阅其他网站。

更新Postfix编译配置文件,支持mysql:

1        make makefiles \
2         'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql \
3         -DUSE_SASL_AUTH \
4         -DUSE_TLS \
5         -DUSE_CYRUS_SASL -I/usr/include/sasl' \
6         'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm \
7         -L/usr/lib/sasl2 -lsasl2 \
8         -lssl -lcrypto'
编译并且安装,安装(一般可以直接选择默认配置,临时目录可以稍作修改到/tmp/postfix下,其他没有必要改动)

1        make & make install

启动postfix

1        postfix start
2        cd ..

如果你的系统进程里面出现了postfix进程,就说明postfix已经安装成功,此时已经可以发送邮件了。

更新系统的alias库,

1        postfix stop  #停止Postfix
2        rm -f /etc/aliases.db  #删除已有的alias库
3        newaliases  #使用Postfix创建新的alias库
4        postfix start  #重启Postfix

评分

参与人数 1威望 +20 收起 理由
cnx + 20

查看全部评分

 楼主| 发表于 2010-7-5 14:27:40 | 显示全部楼层
修改 postfix 配置文件:

1        cd /etc/postfix
2        mv main.cf main.cf.bak
3        vi main.cf

加入以下内容:

001        queue_directory = /var/spool/postfix
002        command_directory = /usr/sbin
003        daemon_directory = /usr/libexec/postfix
004        data_directory = /var/lib/postfix
005         
006        mail_owner = postfix
007         
008        #default_privs = nobody
009         
010        myhostname = mail.howpick.com  #修改为你自己的主机名称,注意这里的设置不能和Mysql里面加入的域名重复。
011        #myhostname = virtual.domain.tld
012         
013        mydomain = howpick.com  #修改为你自己的域名。
014         
015        myorigin = $myhostname
016        #myorigin = $mydomain
017         
018        inet_interfaces = all
019        #inet_interfaces = $myhostname
020        #inet_interfaces = $myhostname, localhost
021         
022        #proxy_interfaces =
023        #proxy_interfaces = 1.2.3.4
024         
025        mydestination = $myhostname, localhost.$mydomain, localhost
026        #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
027        #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
028        #       mail.$mydomain, www.$mydomain, ftp.$mydomain
029         
030        #local_recipient_maps = unix:passwd.byname $alias_maps
031        #local_recipient_maps = proxy:unix:passwd.byname $alias_maps
032        #local_recipient_maps =
033         
034        unknown_local_recipient_reject_code = 550
035         
036        #relay_domains = $mydestination
037         
038        #relayhost = $mydomain
039        #relayhost = [gateway.my.domain]
040        #relayhost = [mailserver.isp.tld]
041        #relayhost = uucphost
042        #relayhost = [an.ip.add.ress]
043         
044        #relay_recipient_maps = hash:/etc/postfix/relay_recipients
045         
046        #in_flow_delay = 1s
047         
048        #alias_maps = dbm:/etc/aliases
049        #alias_maps = hash:/etc/aliases
050        #alias_maps = hash:/etc/aliases, nis:mail.aliases
051        #alias_maps = netinfo:/aliases
052         
053        #alias_database = dbm:/etc/aliases
054        #alias_database = dbm:/etc/mail/aliases
055        #alias_database = hash:/etc/aliases
056        #alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases
057         
058        #recipient_delimiter = +
059        #
060        #home_mailbox = Mailbox
061        #home_mailbox = Maildir/
062          
063        #mail_spool_directory = /var/mail
064        #mail_spool_directory = /var/spool/mail
065         
066        #mailbox_command = /some/where/procmail
067        #mailbox_command = /some/where/procmail -a "$EXTENSION"
068         
069        #mailbox_transport = lmtp:unix:/file/name
070        #mailbox_transport = cyrus
071         
072        #fallback_transport = lmtp:unix:/file/name
073        #fallback_transport = cyrus
074        #fallback_transport =
075         
076        #luser_relay = $user@other.host
077        #luser_relay = $local@other.host
078        #luser_relay = admin+$local
079          
080        #============================================
081        # JUNK MAIL CONTROLS
082        #============================================
083        #header_checks = regexp:/etc/postfix/header_checks
084         
085        # FAST ETRN SERVICE
086        #
087        #fast_flush_domains = $relay_domains
088         
089        # SHOW SOFTWARE VERSION OR NOT
090        #
091        #smtpd_banner = $myhostname ESMTP $mail_name
092        #smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
093         
094        # PARALLEL DELIVERY TO THE SAME DESTINATION
095        #
096        #local_destination_concurrency_limit = 2
097        #default_destination_concurrency_limit = 20
098         
099        debug_peer_level = 2
100         
101        #debug_peer_list = 127.0.0.1
102        #debug_peer_list = some.domain
103         
104        #debugger_command =
105        #        PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
106        #        ddd $daemon_directory/$process_name $process_id & sleep 5
107         
108        debugger_command =
109                PATH=/bin:/usr/bin:/usr/local/bin; export PATH; (echo cont;
110                echo where) | gdb $daemon_directory/$process_name $process_id 2>&1
111                >$config_directory/$process_name.$process_id.log & sleep 5
112         
113        # debugger_command =
114        #       PATH=/bin:/usr/bin:/sbin:/usr/sbin; export PATH; screen
115        #       -dmS $process_name gdb $daemon_directory/$process_name
116        #       $process_id & sleep 1
117         
118        sendmail_path = /usr/sbin/sendmail
119         
120        newaliases_path = /usr/bin/newaliases
121         
122        mailq_path = /usr/bin/mailq
123         
124        setgid_group = postdrop
125         
126        # html_directory: The location of the Postfix HTML documentation.
127        #
128        html_directory = no
129         
130        # manpage_directory: The location of the Postfix on-line manual pages.
131        #
132        manpage_directory = /usr/local/man
133         
134        # sample_directory: The location of the Postfix sample configuration files.
135        # This parameter is obsolete as of Postfix 2.1.
136        #
137        sample_directory = /etc/postfix
138         
139        # readme_directory: The location of the Postfix README files.
140        #
141        readme_directory = no
142         
143        #=====================Vritual Mailbox settings=========================
144        virtual_mailbox_base = /home/vmail/
145        virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
146        virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
147        virtual_alias_domains =
148        virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
149        virtual_uid_maps = static:12345  # 这里要和你添加的postfix用户的uid一致, 查看方法为 cat /etc/passwd
150        virtual_gid_maps = static:12345  # 这里要和你添加的postfix用户的gid一致, 查看方法为 cat /etc/passwd
151        virtual_minimum_uid = 501  # 这里要保证nginx/apache可以修改/home/vmail目录, 查看方法为 cat /etc/passwd
152        virtual_transport = virtual
153        maildrop_destination_recipient_limit = 1
154        maildrop_destination_concurrency_limit = 1
155         
156        #====================QUOTA========================
157        message_size_limit = 5242880  
158        #每个邮件最大尺寸5M
159        mailbox_size_limit = 209715200  
160        #邮箱大小限制200M
161        virtual_mailbox_limit = 209715200
162        #虚拟邮箱大小限制200M
163        virtual_create_maildirsize = yes
164        virtual_mailbox_extended = yes
165        virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf
166        virtual_mailbox_limit_override = yes
167        virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.
168        virtual_overquota_bounce = yes
169         
170        #====================SASL========================
171        smtpd_sasl_type = dovecot   
172        #使用dovecot进行验证
173        smtpd_sasl_path = /var/run/dovecot/auth-client  
174        #与dovecot.conf中如下的的path一致
175        broken_sasl_auth_clients = yes
176        smtpd_recipient_restrictions = permit_mynetworks,
177                                        permit_sasl_authenticated,
178                                        reject_invalid_hostname,
179                                        reject_non_fqdn_hostname,
180                                        reject_unknown_sender_domain,
181                                        reject_non_fqdn_sender,
182                                        reject_non_fqdn_recipient,
183                                        reject_unknown_recipient_domain,
184                                        reject_unauth_pipelining,
185                                        reject_unauth_destination,
186                                        permit
187         
188        #列出本地用户的列表,以便验证 From: 本地域 To: 本地域
189        #smtpd_sender_login_maps =
190        #    mysql:/etc/postfix/mysql_virtual_sender_maps.cf,
191        #    mysql:/etc/postfix/mysql_virtual_alias_maps.cf
192         
193        #smtpd_reject_unlisted_sender = yes
194         
195        #本地域向本地域发信也需要SMTP身份验证
196         
197        #smtpd_sender_restrictions =
198        #    reject_sender_login_mismatch,
199        #    reject_authenticated_sender_login_mismatch,
200        #    reject_unauthenticated_sender_login_mismatch
201         
202        #smtpd_error_sleep_time = 1s
203        #smtpd_soft_error_limit = 10
204        #smtpd_hard_error_limit = 20
205         
206        smtpd_sasl_auth_enable = yes
207        smtpd_sasl_local_domain = $myhostname
208        smtpd_sasl_security_options = noanonymous
209        smtpd_sasl_application_name = smtpd
210        smtpd_banner=$myhostname ESMTP "Version not Available"
211         
212        #====================SSL/TLS========================
213        smtp_use_tls = yes
214        smtpd_use_tls = yes
215        smtp_tls_note_starttls_offer = yes
216        smtpd_tls_key_file = /etc/ssl/smtpd.pem
217        smtpd_tls_cert_file = /etc/ssl/smtpd.pem
218        smtpd_tls_CAfile = /etc/ssl/smtpd.pem
219        smtpd_tls_loglevel = 1
220        smtpd_tls_received_header = yes
221        smtpd_tls_session_cache_timeout = 3600s
222        tls_random_source = dev:/dev/urandom
223         
224        #=======================BCC=========================

创建 mysql_virtual_alias_maps.cf 文件:

1        cat >> /etc/postfix/mysql_virtual_alias_maps.cf << EOF
2        user = postfix
3        password = yourpassword  # 修改为你的密码
4        hosts = localhost
5        dbname = postfix
6        query = SELECT goto FROM alias WHERE address='%s' AND active = 1
7        EOF

创建 mysql_virtual_domains_maps.cf 文件:

1        cat >> /etc/postfix/mysql_virtual_domains_maps.cf << EOF
2        user = postfix
3        password = yourpassword  # 修改为你的密码
4        hosts = localhost
5        dbname = postfix
6        query = SELECT domain FROM domain WHERE domain='%s'
7        #optional query to use when relaying for backup MX
8        #query = SELECT domain FROM domain WHERE domain='%s' and backupmx = '0' and active = '1'
9        EOF

创建 mysql_virtual_mailbox_limit_maps.cf 文件:

1        cat >> /etc/postfix/mysql_virtual_mailbox_limit_maps.cf << EOF
2        user = postfix
3        password = yourpassword  # 修改为你的密码
4        hosts = localhost
5        dbname = postfix
6        query = SELECT quota FROM mailbox WHERE username='%s'
7        EOF

创建 mysql_virtual_mailbox_maps.cf 文件:

1        cat >> /etc/postfix/mysql_virtual_mailbox_maps.cf << EOF
2        user = postfix
3        password = yourpassword  # 修改为你的密码
4        hosts = localhost
5        dbname = postfix
6        query = SELECT maildir FROM mailbox WHERE username='%s' AND active = 1
7        EOF
 楼主| 发表于 2010-7-5 14:27:57 | 显示全部楼层
安装Dovecot

访问Dovecot官方站点 http://www.dovecot.org/download.html ,下载最新的稳定版代码。

1        wget http://www.dovecot.org/releases/1.2/dovecot-1.2.12.tar.gz

解压缩源码

1        tar zxvf dovecot-1.2.12.tar.gz
2        cd dovecot*

配置dovecot编译需要的模块

1        CPPFLAGS="-I/opt/openssl/include -I/usr/local/include" LDFLAGS="-L/opt/openssl/lib -ldl" ./configure --with-ssl=openssl --with-mysql

编译安装

1        make && make install
2        cd ..

安装之后Dovecot安装位置在 /usr/local/sbin/dovecot

制作Dovecot需要的密匙:

1        make -C /etc/pki/tls/certs dovecot.pem

Dovecot 配置文件为 /usr/local/etc/dovecot.conf , 创建配置文件:

1        vi /usr/local/etc/dovecot.conf

加入以下内容:

01        base_dir=/var/run/dovecot
02        protocols=imap imaps pop3 pop3s
03         
04        listen=*
05        mail_location = maildir:/home/vmail/%d/%n/   # 和你postfixadmin的config.inc.php里面的设置要保持一致
06        ssl_cert_file = /etc/pki/tls/certs/dovecot.pem
07        ssl_key_file = /etc/pki/tls/certs/dovecot.pem
08         
09        disable_plaintext_auth = no
10        log_path = /var/log/dovecot.log
11         
12        login_process_size = 64
13        login_process_per_connection = yes
14        login_processes_count = 2
15        login_max_processes_count = 32
16        login_max_connections = 256
17         
18        auth_failure_delay = 2
19        auth default {
20                mechanisms = plain login digest-md5 cram-md5 ntlm rpa apop anonymous
21                passdb sql {
22                        args = /usr/local/etc/dovecot-sql.conf
23                }
24                userdb sql {
25                        args = /usr/local/etc/dovecot-sql.conf
26                }
27                socket listen {
28                        client {
29                                path = /var/run/dovecot/auth-client
30                                mode = 0660
31                                user = postfix
32                                group = postfix
33                        }
34                }
35        }

编辑 /usr/local/etc/dovecot-sql.conf

01        cat >> /usr/local/etc/dovecot-sql.conf << EOF
02        driver = mysql
03        connect = host=/tmp/mysql.sock dbname=postfix user=postfix password=LcGa4KXUUPsBNuGA
04        default_pass_scheme = MD5
05         
06        #password_query = select username as user,password from mailbox where substring(username,1,instr(username,'@')-1) = '%n' and active='1'
07        #这样写的话,不同的域有相同的用户的话会出现多个匹配导致认证失败
08        password_query = select username as user,password from mailbox where username = '%u' and active='1'
09        user_query = select concat('/home/vmail/', maildir) as home, 12345 as uid, 12345 as gid from mailbox where username='%u' and active='1'
10        EOF

启动 Dovecot

1        dovecot
安装 postfixadmin

首先到官方下载postfixadmin。

1        wget http://downloads.sourceforge.net ... ror=cdnetworks-kr-1

解压缩

1        tar zxvf postfixadmin_2.3.tar.gz

把 postfixadmin目录ln到你的域名一个子目录下

ln -s postfixadmin_2.3 /home/www/youdomain/postfixadmin

配置 postfixadmin 数据库。

先登录你的 phpmyadmin Mysql数据库管理系统,并且添加一个数据postfix。

添加数据库用户postfix,并且设置好密码。

通过命令行形式完成的代码如下

1        CREATE DATABASE postfix;
2          CREATE USER 'postfix'@'localhost' IDENTIFIED BY 'choose_a_password';
3          GRANT ALL PRIVILEGES ON `postfix` . * TO 'postfix'@'localhost';

编辑config.inc.php文件,在配置文件里面加入你的数据库密码,并且把配置里面的标记false修改为true。

01        $CONF['configured'] = true;
02        $CONF['default_language'] = 'cn';
03        $CONF['database_password'] = 'your_database_password';
04        $CONF['domain_path'] = 'YES';
05        $CONF['domain_in_mailbox'] = 'NO';
06         
07        $CONF['transport_options'] = array (
08            'dovecot',  // <-- Add this.  添加 Dovecot 的连接方式。
09            'virtual',  // for virtual accounts
10            'local',    // for system accounts
11            'relay'     // for backup mx
12        );
13         
14        $CONF['transport_default'] = 'dovecot';  // 修改默认连接为Dovecot

在 vi 编辑器里面执行命令替换change-this-to-your.domain.tld为你的域名。

%s/change-this-to-your.domain.tld/host.howpick.com/g

修改upgrade.php 文件 (这个视Mysql版本,有的不需要这步)

把 date timestamp(14), 改为 `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

在浏览器里面打开http://www.yourdomain.com/postfixadmin /setup.php 创建数据库信息。

4
postfix-admin

接下来创建超级管理员帐号

6
postfix-create-superadmin-account

Postfixadmin 会要求你修改config.inc.php,设置setup密码,这个密码可以保证其他人无法通过setup.php文件创建管理员用户。

创建成功后,就可以使用管理员帐号登录了。

为了安全删除 setup.php 文件(设置好了setup密码,这个删除不删除没多大关系)。

1        remove setup.php -rf

登录进去,添加一个虚拟域,添加一个虚拟邮箱,就可以收发邮件了。

使用Outlook Express收发邮件测试,启动Outlook Express,设置好邮件帐号,

创建个邮件发送到 gmail邮箱,

然后从 gmail发送一个邮件到你的帐号中,测试一下收取邮件。

此外还有imap协议,以及使用SSL加密传输,测试无误,即告成功。

安装SquirrelMail

从 SquirrelMail的官网下载最新稳定版,并且解压缩,ln到你的一个域名的子目录中。

1        wget http://squirrelmail.org/countdl. ... lmail-1.4.20.tar.gz|
2        tar zxvf squirrelmail-1.4.20.tar.gz
3        ln -s squirrelmail-1.4.20 sq

1        mkdir -p /var/local/squirrelmail/data/  # 创建数据目录
2        chown -R www:www /var/local/squirrelmail/data/  # 允许nginx/apache修改

创建附件目录:

1        cd /var/local/squirrelmail/
2        mkdir attach
3        chgrp -R nobody attach
4        chmod 730 attach
5        crontab -e # 定时删除附件 命令为:  0,30 * * * * find /var/local/squirrelmail/attach -type f -atime +2 -exec rm {} \;

然后配置进入 squirrelmail目录运行里面的配置脚本

1        ./configure
配置上面没有什么好修改的,只需要改下Host name,关键是要保存退出。

打开它的测试页面,反复测试,改正所有错误,既可以登录了。

登录界面:

进入squirrelmail 之后,收信和发信还是不能使用中文的,先到官方下载语言包,解压缩到/tmp下。

1        cd /tmp
2        wget http://squirrelmail.org/countdl. ... .18-20090526.tar.gz
3        tar zxvf all_locales-1.4.18-20090526.tar.gz
4        ./install
5        # 输入squirrelmail的安装目录 一路确认y 就安装完成。

再次返回到 squirrelmail的目录下,执行configure脚本,修改配置Languages:

zh_CN, utf-8

保存退出后,刷新页面,squirrelmail 就可以中文显示,并且能够收发中文邮件了。

最后将Postfix和Dovecot加入到启动项中,随机器重启自动启动。

1        echo "postfix start" >> /etc/rc.local
2        echo "dovecot" >> /etc/rc.local
发表于 2010-7-5 14:34:31 | 显示全部楼层
你这样排版下来 复制的时候 序号怎么去掉
 楼主| 发表于 2010-7-5 14:47:54 | 显示全部楼层
可以使用 vi 编辑器批量替换。
:%s/^\d*\s*//g

嫌麻烦的,也可以看我们网站的文档。
发表于 2010-7-5 14:55:57 | 显示全部楼层
技术文章MARK  留着以后做签名链接  OYE
发表于 2010-7-5 20:46:46 | 显示全部楼层
虽然你的主要目的还是做广告,
但还是应该支持一下的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-27 08:37 , Processed in 0.063566 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表