实战部署Postfix+MySQL+Dovecot+Postfixadmin+Extmail邮件系统(2)
-----构建开源邮件系统系列
如果您对本系列文章感兴趣,可以通过点击以下链接查看全文:
点击《实战部署MySQL用户认证的Postfix邮件系统(1)》 查看第一篇
点击《实战部署MySQL用户认证的Postfix邮件系统(2)》 查看第二篇
点击《实战部署MySQL用户认证的Postfix邮件系统(3)》 查看第三篇
上面我们介绍了MySQL的查询表,接下来就来创建这个配置文件,看看文件中包含什么内容。
[root@mail i386]# cat /etc/postfix/mysql_virtual_alias_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
[root@mail i386]#
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
[root@mail i386]#
mysql_virtual_domains_maps.cf配置文件内容:
[root@mail i386]# cat /etc/postfix/mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
[root@mail i386]#
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = domain
where_field = domain
[root@mail i386]#
mysql_virtual_mailbox_limit_maps.cf配置文件内容:
[root@mail i386]# cat /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
[root@mail i386]#
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
[root@mail i386]#
mysql_virtual_mailbox_maps.cf配置文件内容:
[root@mail i386]# cat /etc/postfix/mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
[root@mail i386]#
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
[root@mail i386]#
Postfix的默认用户邮件存放目录是/var/spool/mail,由于RedHat默认设置的权限不是postfix用户本身,这里我们修改一下。笔者在搭建这个系统的过程中,由于这个目录导致使用Webmail登录不成功。当然我是如何发现的问题,通过看mail日志发现的这个问题。
[root@mail i386]# ls -ld /var/spool/mail/
drwxrwxr-x 2 root mail 4096 Jan 19 00:07 /var/spool/mail/
[root@mail i386]# chown postfix.postfix /var/spool/mail/
[root@mail i386]# ls -ld /var/spool/mail/
drwxrwxr-x 2 postfix postfix 4096 Jan 19 00:07 /var/spool/mail/
drwxrwxr-x 2 root mail 4096 Jan 19 00:07 /var/spool/mail/
[root@mail i386]# chown postfix.postfix /var/spool/mail/
[root@mail i386]# ls -ld /var/spool/mail/
drwxrwxr-x 2 postfix postfix 4096 Jan 19 00:07 /var/spool/mail/
四、创建Postfix所需的数据库
hh
[root@mail i386]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database postfix;
Query OK, 1 row affected (0.04 sec)
mysql> create user 'postfix'@'localhost' identified by 'postfix';
Query OK, 0 rows affected (0.09 sec)
mysql> grant all privileges on postfix.* to postfix@'localhost';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create database postfix;
Query OK, 1 row affected (0.04 sec)
mysql> create user 'postfix'@'localhost' identified by 'postfix';
Query OK, 0 rows affected (0.09 sec)
mysql> grant all privileges on postfix.* to postfix@'localhost';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
hh
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| postfix |
| test |
+--------------------+
4 rows in set (0.29 sec)
mysql> use postfix;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> show grants for postfix@'localhost';
+---------------------------------------------------------------------------------------+
| Grants for postfix@localhost |
+---------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'postfix'@'localhost' IDENTIFIED BY PASSWORD '3ecf3e4f55dd846f' |
| GRANT ALL PRIVILEGES ON `postfix`.* TO 'postfix'@'localhost' |
+---------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| postfix |
| test |
+--------------------+
4 rows in set (0.29 sec)
mysql> use postfix;
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> show grants for postfix@'localhost';
+---------------------------------------------------------------------------------------+
| Grants for postfix@localhost |
+---------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'postfix'@'localhost' IDENTIFIED BY PASSWORD '3ecf3e4f55dd846f' |
| GRANT ALL PRIVILEGES ON `postfix`.* TO 'postfix'@'localhost' |
+---------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
五、Postfixadmin安装与配置
Postfixadmin是postfix邮件系统的web管理工具,可以通过它管理虚拟邮件主机、添加删除虚拟域、管理员、邮箱、别名以及用户等,配置工作十分简单。
安装Postfixadmin较简单,只要将该软件解压到Apache的主目录中即可。使用rpm包安装的Apache的默认路径在/var/www/html下。
[root@mail ~]# tar -zxvf postfixadmin-2.3.6.tar.gz -C /var/www/html/
… …
postfixadmin-2.3.6/debian/control
postfixadmin-2.3.6/debian/lighttpd.conf
postfixadmin-2.3.6/debian/postfixadmin.docs
postfixadmin-2.3.6/edit-domain.php
[root@mail ~]# cd /var/www/html/
[root@mail html]# mv postfixadmin-2.3.6 postfixadmin
… …
postfixadmin-2.3.6/debian/control
postfixadmin-2.3.6/debian/lighttpd.conf
postfixadmin-2.3.6/debian/postfixadmin.docs
postfixadmin-2.3.6/edit-domain.php
[root@mail ~]# cd /var/www/html/
[root@mail html]# mv postfixadmin-2.3.6 postfixadmin
接下来设置postfixadmin的配置文件config.inc.php,主要修改下面的参数项:
[root@mail html]# vim postfixadmin/config.inc.php
……
$CONF['configured'] = true; //将默认的false修改为true
$CONF['default_language'] = 'cn'; // postfixadmin默认语言:"cn" 中文,"en"英文
$CONF['database_type'] = 'mysql'; //数据库类型
$CONF['database_host'] = 'localhost'; //数据库服务的位置
$CONF['database_user'] = 'postfix'; //postfixadmin连接数据库时使用的用户名
$CONF['database_password'] = 'postfix'; //访问数据库的密码
$CONF['database_name'] = 'postfix'; //连接MySQL数据库的库名
$CONF['smtp_server'] = 'localhost';
$CONF['smtp_port'] = '25';
$CONF['encrypt'] = 'md5crypt'; //数据库中密码的保存形式
$CONF['domain_path'] = 'YES'; //指定以域名作为邮箱文件夹的路径名,将默认的NO修改为YES
$CONF['domain_in_mailbox'] = 'NO';
$CONF['aliases'] = '1000';
$CONF['mailboxes'] = '1000';
$CONF['maxquota'] = '1000';
$CONF['quota'] = 'NO';
$CONF['quota_multiplier'] = '1024000'; //邮箱的大小限制 $CONF['emailcheck_resolve_domain']='NO'; //将默认的YES修改为NO
……
$CONF['configured'] = true; //将默认的false修改为true
$CONF['default_language'] = 'cn'; // postfixadmin默认语言:"cn" 中文,"en"英文
$CONF['database_type'] = 'mysql'; //数据库类型
$CONF['database_host'] = 'localhost'; //数据库服务的位置
$CONF['database_user'] = 'postfix'; //postfixadmin连接数据库时使用的用户名
$CONF['database_password'] = 'postfix'; //访问数据库的密码
$CONF['database_name'] = 'postfix'; //连接MySQL数据库的库名
$CONF['smtp_server'] = 'localhost';
$CONF['smtp_port'] = '25';
$CONF['encrypt'] = 'md5crypt'; //数据库中密码的保存形式
$CONF['domain_path'] = 'YES'; //指定以域名作为邮箱文件夹的路径名,将默认的NO修改为YES
$CONF['domain_in_mailbox'] = 'NO';
$CONF['aliases'] = '1000';
$CONF['mailboxes'] = '1000';
$CONF['maxquota'] = '1000';
$CONF['quota'] = 'NO';
$CONF['quota_multiplier'] = '1024000'; //邮箱的大小限制 $CONF['emailcheck_resolve_domain']='NO'; //将默认的YES修改为NO
在第一次访问的过程中会在MySQL数据库,postfix库中添加相应的表结构,可以使用如下命令验证:
[root@mail ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 156
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use postfix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_postfix |
+-----------------------+
| admin |
| alias |
| alias_domain |
| config |
| domain |
| domain_admins |
| fetchmail |
| log |
| mailbox |
| quota |
| quota2 |
| vacation |
| vacation_notification |
+-----------------------+
13 rows in set (0.00 sec)
mysql>
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 156
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use postfix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_postfix |
+-----------------------+
| admin |
| alias |
| alias_domain |
| config |
| domain |
| domain_admins |
| fetchmail |
| log |
| mailbox |
| quota |
| quota2 |
| vacation |
| vacation_notification |
+-----------------------+
13 rows in set (0.00 sec)
mysql>
在Change setup passwd下填写你要设置的密码后,将产生加密密码,如下所示:
按照提示,将产生的密码替换postfixadmin配置文件config.inc.php中$CONF['setup_password'] =’changeme”字段中的changeme,结果如下:
$CONF['setup_password'] = ' dbd193530d798b7cd5d6f0a3805ee4e4:b5b951b8706bec173e58aeb38d333926caa3863c';
接下来创建Postfixadmin的管理员,Postfixadmin将管理员划分为两种:超级管理员和普通管理员,他们分别用以下用途:
l超级管理员:可以添加删除邮件域、管理员;新建管理员并授予具有管理那个域的权限,新建用户邮箱等权限。
l普通管理员:为了安全起见,一般情况下,使用超级管理员来创建邮件域和普通管理员,而使用普通管理员来添加用户邮箱以及别名。
在新版本中的postfixadmin管理工具中,在设置完Setup password后,就可以按照向导完成超级管理员的创建。
点击“新增”后,postfixadmin会提示“新增管理员成功”提示
超级管理员创建完成后,将setup.php文件和所有motd开头的txt文件,移动到其它位置,或者删除。
[root@mail html]# mv postfixadmin/setup.php ~
[root@mail html]# mv postfixadmin/motd* ~
[root@mail html]# mv postfixadmin/motd* ~
输入“超级管理员用户名和密码”点击“登录”完成登录。
接下来我们来以下面的信息为例来创建相应的信息:
域名
|
邮箱名
|
邮箱密码
|
xifeng.com
|
yujinlong@xifeng.com
|
123456
|
vfast.com
|
linken@vfast.com
|
123456
|
在创建域的过程中,只需要点击“域名清单”/“新建域”,如下所示:
输入域名的相关信息之后,点击“新增”即可。
点击“域名清单”,可以列出已创建的邮件域:
在创建普通管理员的过程中,和创建域的过程一样简单。只需要单击“管理员清单”/“新建管理员”
注意管理员名称输入的管理账号名为邮件地址,并赋予这个账号可以管理那些域,如果是多个域可以按Ctrl键,选中要选择的域的名称即可。之后点击“新增”
点击“管理员清单”可以看到有两个管理员,其中一个为超级管理员,另一个为普通管理员,管理的域名为2个。
创建完成后也可以登录到MySQL数据库中,查询admin表,你会发现这管理员的的信息。
[root@mail ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 135
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use postfix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from admin;
+------------------------+------------------------------------+---------------------+---------------------+--------+
| username | password | created | modified | active |
+------------------------+------------------------------------+---------------------+---------------------+--------+
| admin@xifeng.com | $1$4a6944be$g1JKJSJ8uEk.KtW.OBaKa. | 2013-01-21 22:41:50 | 2013-01-21 22:41:50 | 1 |
| Super@postfixadmin.com | $1$7da3934e$/7Z5vzQmGXD3bVHFJGwu00 | 2013-01-21 22:36:31 | 2013-01-21 22:36:31 | 1 |
+------------------------+------------------------------------+---------------------+---------------------+--------+
2 rows in set (0.00 sec)
mysql>
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 135
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use postfix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from admin;
+------------------------+------------------------------------+---------------------+---------------------+--------+
| username | password | created | modified | active |
+------------------------+------------------------------------+---------------------+---------------------+--------+
| admin@xifeng.com | $1$4a6944be$g1JKJSJ8uEk.KtW.OBaKa. | 2013-01-21 22:41:50 | 2013-01-21 22:41:50 | 1 |
| Super@postfixadmin.com | $1$7da3934e$/7Z5vzQmGXD3bVHFJGwu00 | 2013-01-21 22:36:31 | 2013-01-21 22:36:31 | 1 |
+------------------------+------------------------------------+---------------------+---------------------+--------+
2 rows in set (0.00 sec)
mysql>
接下来使用我们创建的admin@xifeng.com这个普通管理员登录Postfixadmin,完成用户邮箱的添加,同样是使用http://mail.xifeng.com/postfixadmin这个管理链接来登录。
登录后,显示出了普通管理员能够完成的工作。
在创建用户邮箱的过程中,只需要点击“虚拟用户清单”/“新建邮箱”,如下所示:
输入用户名后选择用户要添加的邮件域名之后输入密码等信息,点击“增加邮箱”
完成后,会提示建立邮箱成功的提示,可以根据向导继续创建邮箱。
现在我们先测试一下Postfix服务是否能够启动,如果可以,并将其设置为开机自启动。
[root@mail ~]# /etc/init.d/postfix start
Starting postfix: [ OK ]
[root@mail ~]# chkconfig --level 35 postfix on
Starting postfix: [ OK ]
[root@mail ~]# chkconfig --level 35 postfix on
通常,Postfix输出这一行信息并不能确认Postfix已经正常运行,我们还需要查看Postfix的系统日志中有没有什么出错信息。
[root@mail ~]# tail /var/log/maillog
……
Jan 22 02:57:49 mail postfix/postfix-script: starting the Postfix mail system
Jan 22 02:57:49 mail postfix/master[27795]: daemon started -- version 2.3.3, configuration /etc/postfix
[root@mail ~]#
……
Jan 22 02:57:49 mail postfix/postfix-script: starting the Postfix mail system
Jan 22 02:57:49 mail postfix/master[27795]: daemon started -- version 2.3.3, configuration /etc/postfix
[root@mail ~]#
如果日志文件中包含上面的两行信息,那么恭喜你了,现在Postfix已经能够启动了,虽然它还不能提供服务。继续努力吧!
由于老是提示文章篇幅超过8万字符,特分为三篇发布,点击
本文转自yjlsy 51CTO博客,原文链接:http://blog.51cto.com/baidu/1123539,如需转载请自行联系原作者