部署Postfix+MySQL+Dovecot+Postfixadmin+Extmail邮件系统(一)

一、安装前的准备工作邮件服务器的安装、配置工作是一个相对复杂的过称,在正式安装Postfix之前,我们必须要一些准备工作。1、 基本网络的设置在一个网络环境中,主机名是识别某个计算机的唯一标识,而在一个单机环境中,主机名只给出了系统的称呼。让修改的主机名永久生效, 则必须要修改/etc/sysconfig/network 文件,在该文件中,修改HOSTNAME一行:

1. [root@mail ~]# cat /etc/sysconfig/network
2. NETWORKING=yes
3. NETWORKING_IPV6=yes
4. HOSTNAME=mail.xifeng.com

也可以在/etc/sysconfig/network增加缺省网关,在该文件中添加GATEWAY=网关地址字段即可。在RedHatLinux 中,要设置主机的IP 地址,通用的方法是直接更改脚本。例如,当主机中只有一块网卡时,其设备名为eth0,此时要给该网卡设置IP 地址,只需要修改/etc/sysconfig/network-scripts/ifcfg-eth0 文件即可,下面是一个ifcfg-eth0 文件的配置示例:

 

01. [root@noc ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
02. # Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
03. DEVICE=eth0
04. BOOTPROTO=static
05. BROADCAST=10.1.1.255
06. HWADDR=00:0C:29:47:8F:7A
07. IPADDR=10.1.1.120
08. IPV6INIT=yes
09. IPV6_AUTOCONF=yes
10. NETMASK=255.255.255.0
11. NETWORK=10.1.1.0
12. ONBOOT=yes

/etc/hosts 它给每个主机赋一个IP 地址,即使计算机不在网络上,在/etc/hosts 中也会包含用户自己的主机名。

 

1. [root@mail ~]# cat /etc/hosts
2. ……
3. 10.1.1.120 mail.xifeng.com

设置DNS 服务器的方法比较简单,只需修改/etc/resolv.conf 文件即可。
 

1. [root@noc ~]# cat /etc/resolv.conf
2. nameserver 10.1.1.120

2、停止或卸载老的MTA软件Redhat Enterprise Linux 在安装系统的过程中默认就将Sendmail这个古老的邮件系统安装到你的系统中。既然我们选择使用Postfix这个邮件系统,俗话说“一山不容二虎,除非一公一母”,这个时候,又让我们做一个艰难的决定了,只能让我们二选一了。首先,使用chkconfig命令将Sendmail服务设置默认开机时关闭,同时将该服务关闭。
 

1. [root@mail ~]# chkconfig sendmail off
2. [root@mail ~]# /etc/init.d/sendmail stop
3. Shutting down sm-client: [ OK ]
4. Shutting down sendmail: [ OK ]
5. [root@mail ~]#

或者,将 Sendmail软件包直接卸载,如果使用rpm命令卸载的话,由于软件包之间存在依赖关系,可能无法直接卸载的掉,可以使用--nodeps参数忽略软件包的依赖关系卸载。这里推荐使用yum remove命令删除,使用yum命令删除的好处是自动处理软件包的依赖关系。
 

1. [root@mail ~]# yum remove sendmail

3、部署LAMP环境

由于我们使用的postfixadmin和extmail是基于php和perl编写的,首先需要安装lamp环境,用于解析php界面,我们直接使用yum安装即可。

 

1. [root@mail ~]# yum install httpd* mysql* php-*

启动apache并将apache设置为开机自启动

 

1. [root@mail~]# /etc/init.d/httpd start
2. Starting httpd:                                                                                        [    OK    ]
3. [root@mail ~]# chkconfig --level 35 httpd on

启动MySQL数据库服务并设置为开机自启动

 

01. [root@mail ~]# /etc/init.d/mysqld start
02. Initializing <a href="http://www.it165.net/database/dbmy/" target="_blank"class="keylink">MySQL</a> database:    Installing MySQL system tables...
03. OK
04. Filling help tables...
05. OK
06.  
07. To start mysqld at boot time you have to copy
08. support-files/mysql.server to the right place for your system
09.  
10. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
11. To do so, start the server, then issue the following commands:
12. /usr/bin/mysqladmin -u root pass<a href="http://www.it165.net/edu/ebg/" target="_blank"class="keylink">word</a> 'new-pass<a href="http://www.it165.net/edu/ebg/"target="_blank" class="keylink">word</a>'
13. /usr/bin/mysqladmin -u root -h mail.xifeng.com password 'new-password'
14.  
15. Alternatively you can run:
16. /usr/bin/mysql_secure_installation
17.  
18. which will also give you the option of removing the test
19. databases and anonymous user created by default.    This is
20. strongly recommended for production servers.
21.  
22. See the manual for more instructions.
23.  
24. You can start the MySQL daemon with:
25. cd /usr ; /usr/bin/mysqld_safe &
26.  
27. You can test the MySQL daemon with mysql-test-run.pl
28. cd mysql-test ; perl mysql-test-run.pl
29.  
30. Please report any problems with the /usr/bin/mysqlbug script!
31.  
32. The latest information about MySQL is available on the web at
34. Support MySQL by buying support/licenses at http://shop.mysql.com
35. [    OK    ]
36. Starting MySQL:                                                                                        [    OK    ]
37. [root@mail ~]# chkconfig --level 35 mysqld on

设置MySQL数据库密码并验证登录

 

01. [root@mail ~]# mysqladmin -u root password 123456
02. [root@mail ~]# mysql -u root -p
03. Enter password:
04. Welcome to the MySQL monitor.    Commands end with ; or \g.
05. Your MySQL connection id is 3
06. Server version: 5.0.77 Source distribution
07.  
08. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
09.  
10. mysql&gt; show databases;
11. +--------------------+
12. | Database                     |
13. +--------------------+
14. | information_schema |
15. | mysql                            |
16. test                             |
17. +--------------------+
18. 3 rows in set (0.00 sec)
19.  
20. mysql&gt;

二、Postfix的安装在安装Postfix之前,由于Postfix默认的安装包不支持MySQL,我们首先要在RedHat的FTP站点(ftp://ftp.redhat.com/pub/redhat/linux/enterprise/)下载Postfix的源码RPM软件包,重新编译Postfix使其支持MySQL。一般源码RPM软件包的命名格式如下:<软件包名称.软件的版本号>.src.rpm这种RPM文件封装着应用软件的源代码,所以被称为源码RPM软件包。源码软件包RPM文件主要用来制作(Build)出其他种类的RPM软件包文件。使用rpmbuild命令来制作成二进制的RPM软件包,以下命令是检查rpm-build的软件包是否被安装,如果没有安装安装即可。
 

1. [root@mail ~]# rpm -q rpm-build
2. package rpm-build is not installed
3. [root@mail ~]# yum install rpm-build

安装rpm-build软件包后,会在/usr/src/redhat/目录下产生如下目录结构:

 

1. [root@mail ~]# ls /usr/src/redhat/
2. BUILD    RPMS    SOURCES    SPECS    SRPMS
各个目录的说明:
<>l<>l<>l<>l<>lSRPMS:在制作过程中生成的源码RPM软件包

将下载回来的Postfix源码RPM软件包,直接执行rpm -i安装后,软件的源码会安装在/usr/src/redhat/SOURCES/目录下,

 

各个目录的说明:
l BUILD:源码软件包编译过程中的临时目录
l RPMS:从源码RPM软件包生成的二进制RPM软件包存放目录
l SOURCES :实际的源码包,通常是tar压缩包
l SPECS:建立二进制RPM软件包的规范文件spec存放位置
l SRPMS:在制作过程中生成的源码RPM软件包
将下载回来的Postfix源码RPM软件包,直接执行rpm -i安装后,软件的源码会安装在/usr/src/redhat/SOURCES/目录下,
 

1. [root@mail ~]# rpm -i postfix-2.3.3-2.3.el5_6.src.rpm
2. warning: user mockbuild does not exist - using root
3. warning: group mockbuild does not exist - using root
4. 省略若干……

你要自己编译二进制的RPM软件包文件,需要进入 /usr/src/redhat/SPECS目录下修改spec脚本即可。Postfix的源码软件包会生成一个叫做postfix.spec的脚本文件,如下所示:

 

1. [root@mail ~]# cd /usr/src/redhat/SPECS/
2. [root@mail SPECS]# ls
3. postfix.spec

修改postfix.spec,将与MySQL和postfix用户的uid和gid相关行修改即可。

 

1. [root@mail SPECS]# vim postfix.spec
2. %define LDAP 2
3. %define MYSQL 1                      #将默认的0修改为1
4. %define postfix_uid        1000    #将默认的89修改为1000
5. … …
6. %define postfix_gid        1000    #将默认的89修改为1000
7. … …

使用rpmbuild命令重新编译Postfix,这个过程需要时间根据系统而定,有时候需要花费很长时间。

 

1. [root@mail SPECS]# rpmbuild -ba postfix.spec
2. … …
3. + /bin/rm -rf /var/tmp/postfix-buildroot
4. exit 0
5. [root@mail SPECS]#

编译完成后,默认RedHat将这个包放到了/usr/src/redhat/RPMS/i386这个目录下,进入该目录安装即可。

 

1. [root@mail SPECS]# cd ../RPMS/i386/
2. [root@mail i386]# rpm -ivh postfix-2.3.3-2.3.i386.rpm
3. Preparing...                  ########################################### [100%]
4. 1:postfix                ########################################### [100%]
5. [root@mail i386]#

安装完成后我们可以使用postconf –m命令验证postfix是否支持mysql。

 

1. [root@mail i386]# postconf -m
2. ......
3. ldap
4. mysql
5. ......
6. [root@mail i386]#

三、 Postfix的基本配置
Postfix最主要的配置文件保存在/etc/postfix/main.cf和/etc/postfix/master.cf两个文件中。main.cf中保存了Postfix的基本配置项,而master.cf中定义了组成Postfix的各个守护进程的调用信息。
首先要完成一些外围工作:

 

1. [root@mail i386]# touch /etc/postfix/mysql_virtual_alias_maps.cf
2. [root@mail i386]# touch /etc/postfix/mysql_virtual_domains_maps.cf
3. [root@mail i386]# touch /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
4. [root@mail i386]# touch /etc/postfix/mysql_virtual_mailbox_maps.cf

接下来编辑Postfix的配置文件了。首先,我们要编辑main.cf文件,修改部分配置的参数为下面的内容:

 

1. [root@mail i386]# cat /etc/postfix/main.cf
2. #==============================BASE=============================
3. myhostname = mail.xifeng.com
4. mydomain = xifeng.com
5. myorigin = $mydomain
6. mydestination = $myhostname localhost localhost.$mydomain
7. mynetworks = 127.0.0.0/8
8. inet_interfaces = all

修改完以上述信息之后我们还需要添加一些配置信息:

 

01. #======================Virtual Mailbox Settings========================
02. virtual_minimum_uid = 100
03. virtual_mailbox_base = /var/spool/mail
04. virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
05. virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
06. virtual_alias_domains = $virtual_alias_maps
07. virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
08. virtual_uid_maps = static:1000
09. virtual_gid_maps = static:1000
10. virtual_transport = virtual
11. maildrop_destination_recipient_limit = 1
12. maildrop_destination_concurrency_limit = 1
13. #==============================QUOTA===========================
14. message_size_limit = 52428800
15. mailbox_size_limit = 209715200
16. virtual_mailbox_limit = 209715200
17. virtual_create_maildirsize = yes
18. virtual_mailbox_extended = yes
19. virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
20. virtual_mailbox_limit_override = yes
21. virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspacequota, please try again later.
22. virtual_overquota_bounce = yes
23. #==============================SASL=============================
24. broken_sasl_auth_clients = yes
25. 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
26. smtpd_sasl_auth_enable = yes
27. smtpd_sasl_type = dovecot
28. smtpd_sasl_path = /var/run/dovecot/auth-client
29. smtpd_sasl_local_domain = $myhostname
30. smtpd_sasl_security_options = noanonymous
31. smtpd_sasl_application_name = smtpd
32. smtpd_banner=$myhostname ESMTP "Version not Available"
33. #==============================================================
34. readme_directory = no
35. sample_directory = /etc/postfix
36. sendmail_path = /usr/sbin/sendmail
37. html_directory = no
38. setgid_group = postdrop
39. command_directory = /usr/sbin
40. manpage_directory = /usr/local/man
41. daemon_directory = /usr/libexec/postfix
42. newaliases_path = /usr/bin/newaliases
43. mailq_path = /usr/bin/mailq
44. queue_directory = /var/spool/postfix
45. mail_owner = postfix

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:这个配置参数指明邮件服务器上虚拟别名和实际邮件地址间的对应关系。 www.it165.net
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf:这个配置参数指明服务器上邮箱的一些限制参数。
通常我们将这些配置参数称为查询表,它定义了这个参数项的实际配置数据的存储位置和格式。比如“mysql:/etc/postfix/mysql_virtual_alias_maps.cf”的含义就是:查询表是MySQL数据库格式,访问这个数据库表的方法在文件“/etc/postfix/mysql_virtual_alias_maps.cf”中存放。另一种查询表格式是“alias_maps = hash:/etc/aliases”,它表示查询表是一个哈希文件,文件的路径是/etc/aliases。Postfix在需要的时候读取这些配置信息,然后根据这些配置信息的指示,到另外的文件或者数据库中去读取实际的数据。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
CentOS+Postfix+Dovecot+Postfixadmin+Roundcube邮件服务器的搭建步骤如下: 1. 安装 CentOS 操作系统,并更新至最新版。 2. 安装 Postfix 邮件服务器,并进行基本配置。 3. 安装 Dovecot IMAP/POP3 服务器,并进行基本配置。 4. 安装 Postfixadmin 邮箱管理系统,并进行基本配置。 5. 安装 Roundcube Webmail 邮件客户端,并进行基本配置。 具体步骤如下: 1. 安装 CentOS 操作系统,并更新至最新版。 在安装 CentOS 操作系统时,选择最小化安装,并根据实际情况进行分区和网络配置。安装完成后,使用以下命令更新系统: ``` yum update ``` 2. 安装 Postfix 邮件服务器,并进行基本配置。 使用以下命令安装 Postfix: ``` yum install postfix ``` 安装完成后,修改 /etc/postfix/main.cf 文件,使其支持 TLS 和 SASL 认证: ``` smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt smtpd_tls_key_file = /etc/pki/tls/private/server.key smtpd_tls_security_level = may smtp_tls_security_level = may smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination ``` 然后重启 Postfix 服务: ``` systemctl restart postfix ``` 3. 安装 Dovecot IMAP/POP3 服务器,并进行基本配置。 使用以下命令安装 Dovecot: ``` yum install dovecot ``` 安装完成后,修改 /etc/dovecot/dovecot.conf 文件,使其支持 TLS 和 SASL 认证: ``` ssl_cert = </etc/pki/tls/certs/server.crt ssl_key = </etc/pki/tls/private/server.key auth_mechanisms = plain login ``` 然后重启 Dovecot 服务: ``` systemctl restart dovecot ``` 4. 安装 Postfixadmin 邮箱管理系统,并进行基本配置。 使用以下命令安装 Postfixadmin: ``` yum install postfixadmin ``` 安装完成后,修改 /etc/httpd/conf.d/postfixadmin.conf 文件,使其支持 SSL: ``` SSLEngine on SSLCertificateFile /etc/pki/tls/certs/server.crt SSLCertificateKeyFile /etc/pki/tls/private/server.key ``` 然后重启 Apache 服务: ``` systemctl restart httpd ``` 访问 https://your-domain.com/postfixadmin,使用管理员账号登录,创建邮箱账号和域名等相关配置。 5. 安装 Roundcube Webmail 邮件客户端,并进行基本配置。 使用以下命令安装 Roundcube: ``` yum install roundcubemail ``` 安装完成后,修改 /etc/httpd/conf.d/roundcubemail.conf 文件,使其支持 SSL: ``` SSLEngine on SSLCertificateFile /etc/pki/tls/certs/server.crt SSLCertificateKeyFile /etc/pki/tls/private/server.key ``` 然后重启 Apache 服务: ``` systemctl restart httpd ``` 访问 https://your-domain.com/roundcubemail,使用邮箱账号登录,即可使用 Roundcube 邮件客户端。 以上就是 CentOS+Postfix+Dovecot+Postfixadmin+Roundcube邮件服务器的搭建步骤,如有问题可以参考相关文档或者咨询技术人员。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值