部署Postfix+MySQL+Dovecot+Postfixadmin+Extmail邮件系统(一)
2016-01-25 10:57
811 查看
一、安装前的准备工作邮件服务器的安装、配置工作是一个相对复杂的过称,在正式安装Postfix之前,我们必须要一些准备工作。1、 基本网络的设置在一个网络环境中,主机名是识别某个计算机的唯一标识,而在一个单机环境中,主机名只给出了系统的称呼。让修改的主机名永久生效, 则必须要修改/etc/sysconfig/network 文件,在该文件中,修改HOSTNAME一行:
view
sourceprint?
也可以在/etc/sysconfig/network增加缺省网关,在该文件中添加GATEWAY=网关地址字段即可。在RedHatLinux 中,要设置主机的IP
地址,通用的方法是直接更改脚本。例如,当主机中只有一块网卡时,其设备名为eth0,此时要给该网卡设置IP 地址,只需要修改/etc/sysconfig/network-scripts/ifcfg-eth0 文件即可,下面是一个ifcfg-eth0 文件的配置示例:
view
sourceprint?
/etc/hosts 它给每个主机赋一个IP 地址,即使计算机不在网络上,在/etc/hosts 中也会包含用户自己的主机名。
view
sourceprint?
设置DNS 服务器的方法比较简单,只需修改/etc/resolv.conf 文件即可。
view
sourceprint?
2、停止或卸载老的MTA软件Redhat Enterprise Linux 在安装系统的过程中默认就将Sendmail这个古老的邮件系统安装到你的系统中。既然我们选择使用Postfix这个邮件系统,俗话说“一山不容二虎,除非一公一母”,这个时候,又让我们做一个艰难的决定了,只能让我们二选一了。首先,使用chkconfig命令将Sendmail服务设置默认开机时关闭,同时将该服务关闭。
view
sourceprint?
或者,将 Sendmail软件包直接卸载,如果使用rpm命令卸载的话,由于软件包之间存在依赖关系,可能无法直接卸载的掉,可以使用--nodeps参数忽略软件包的依赖关系卸载。这里推荐使用yum remove命令删除,使用yum命令删除的好处是自动处理软件包的依赖关系。
view
sourceprint?
3、部署LAMP环境
由于我们使用的postfixadmin和extmail是基于php和perl编写的,首先需要安装lamp环境,用于解析php界面,我们直接使用yum安装即可。
view
sourceprint?
启动apache并将apache设置为开机自启动
view
sourceprint?
启动MySQL数据库服务并设置为开机自启动
view
sourceprint?
设置MySQL数据库密码并验证登录
view
sourceprint?
二、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的软件包是否被安装,如果没有安装安装即可。
view
sourceprint?
安装rpm-build软件包后,会在/usr/src/redhat/目录下产生如下目录结构:
view
sourceprint?
各个目录的说明:
<>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/目录下,
view
sourceprint?
你要自己编译二进制的RPM软件包文件,需要进入 /usr/src/redhat/SPECS目录下修改spec脚本即可。Postfix的源码软件包会生成一个叫做postfix.spec的脚本文件,如下所示:
view
sourceprint?
修改postfix.spec,将与MySQL和postfix用户的uid和gid相关行修改即可。
view
sourceprint?
使用rpmbuild命令重新编译Postfix,这个过程需要时间根据系统而定,有时候需要花费很长时间。
view
sourceprint?
编译完成后,默认RedHat将这个包放到了/usr/src/redhat/RPMS/i386这个目录下,进入该目录安装即可。
view
sourceprint?
安装完成后我们可以使用postconf –m命令验证postfix是否支持mysql。
view
sourceprint?
三、 Postfix的基本配置
Postfix最主要的配置文件保存在/etc/postfix/main.cf和/etc/postfix/master.cf两个文件中。main.cf中保存了Postfix的基本配置项,而master.cf中定义了组成Postfix的各个守护进程的调用信息。
首先要完成一些外围工作:
view
sourceprint?
接下来编辑Postfix的配置文件了。首先,我们要编辑main.cf文件,修改部分配置的参数为下面的内容:
view
sourceprint?
修改完以上述信息之后我们还需要添加一些配置信息:
view
sourceprint?
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在需要的时候读取这些配置信息,然后根据这些配置信息的指示,到另外的文件或者数据库中去读取实际的数据。
view
sourceprint?
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 文件的配置示例:
view
sourceprint?
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 中也会包含用户自己的主机名。
view
sourceprint?
1.
[root@mail ~]
# cat /etc/hosts
2.
……
3.
10.1.1.120 mail.xifeng.com
设置DNS 服务器的方法比较简单,只需修改/etc/resolv.conf 文件即可。
view
sourceprint?
1.
[root@noc ~]
# cat /etc/resolv.conf
2.
nameserver 10.1.1.120
2、停止或卸载老的MTA软件Redhat Enterprise Linux 在安装系统的过程中默认就将Sendmail这个古老的邮件系统安装到你的系统中。既然我们选择使用Postfix这个邮件系统,俗话说“一山不容二虎,除非一公一母”,这个时候,又让我们做一个艰难的决定了,只能让我们二选一了。首先,使用chkconfig命令将Sendmail服务设置默认开机时关闭,同时将该服务关闭。
view
sourceprint?
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命令删除的好处是自动处理软件包的依赖关系。
view
sourceprint?
1.
[root@mail ~]
# yum remove sendmail
3、部署LAMP环境
由于我们使用的postfixadmin和extmail是基于php和perl编写的,首先需要安装lamp环境,用于解析php界面,我们直接使用yum安装即可。
view
sourceprint?
1.
[root@mail ~]
# yum install httpd* mysql* php-*
启动apache并将apache设置为开机自启动
view
sourceprint?
1.
[root@mail~]
# /etc/init.d/httpd start
2.
Starting httpd: [ OK ]
3.
[root@mail ~]
# chkconfig --level 35 httpd on
启动MySQL数据库服务并设置为开机自启动
view
sourceprint?
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
33.
http://www.mysql.com
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数据库密码并验证登录
view
sourceprint?
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的软件包是否被安装,如果没有安装安装即可。
view
sourceprint?
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/目录下产生如下目录结构:
view
sourceprint?
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/目录下,
view
sourceprint?
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的脚本文件,如下所示:
view
sourceprint?
1.
[root@mail ~]
# cd /usr/src/redhat/SPECS/
2.
[root@mail SPECS]
# ls
3.
postfix.spec
修改postfix.spec,将与MySQL和postfix用户的uid和gid相关行修改即可。
view
sourceprint?
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,这个过程需要时间根据系统而定,有时候需要花费很长时间。
view
sourceprint?
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这个目录下,进入该目录安装即可。
view
sourceprint?
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。
view
sourceprint?
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的各个守护进程的调用信息。
首先要完成一些外围工作:
view
sourceprint?
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文件,修改部分配置的参数为下面的内容:
view
sourceprint?
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
修改完以上述信息之后我们还需要添加一些配置信息:
view
sourceprint?
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 diskspace
quota
, 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在需要的时候读取这些配置信息,然后根据这些配置信息的指示,到另外的文件或者数据库中去读取实际的数据。
相关文章推荐
- 使用参数innodb_file_per_table支持MySQL InnoDB表数据共享空间自动收缩
- mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法
- mysql中float,double,decimal的差别
- MySQL InnoDB存储引擎
- mysql添加外键
- 管理员 修改MySQL 5.7.9 新版本的root密码方法以及一些新变化整理
- 关于MySQL数据导出导入的文章
- 打开MySQL数据库远程访问的权限
- MySQL在远程访问时非常慢的解决skip-name-resolve 并且出现 Reading from net
- mysql经常使用的命令
- 逗号分隔存储 && mysql字符串函数初探
- MySql效率问题
- Cobar使用文档(可用作MySQL大型集群解决方案)
- dbutils + mysql事务
- mysql字符串分割
- MySQL实现统计数据并插入数据的存储过程
- mysql基础知识
- mysql加强
- mysql处理高并发,防止库存超卖
- MySql免安装版的配置