在DNS为邮件服务器做好域名解析后
注意:在做该实验时有些设备应关闭selinux
就可以利用MYSQL和POSTFIX来搭建数据库所记录的虚拟用户来使用邮件服务器进行收发邮件了
首先在MYSQL中建立email库存放记录虚拟用户信息的表emailuser
usernamepassworddomainmaildir
[email protected]12345678redhat.com/redhat.com/fu/
在MYSQL中新建用户并使得该用户只可访问email库
GRANT SELECT ON email.* to [email protected] identified by ‘postfixuser‘;
新建用户并添加到postfix的主配置文件/etc/postfix/main.cf中
groupadd -g 451 vmail
useradd -s /bin/noligin -g 451 -u 451 vmail
postconf -e virtual_mailbox_base=/home/vmail
postconf -e virtual_uid_maps=static:451
postconf -e virtual_gid_maps=static:451
新建文件使数据库中信息与postfix关联
postconf -e virtual_alias_maps=mysql:/etc/postfix/my-emailuser.cf
postconf -e virtual_mailbox_domains=mysql:/etc/postfix/my-domain.cf
postconf -e virtual_mailbox_maps=mysql:/etc/postfix/my-maildir.cf
编辑文件my-emailuser.cf
|- -|
hosts = localhost
user = postfixuser
password = postfixuser
dbname = email
table = emailuser
select_field = username
where_field = username
|- -|
编辑my-domain.cf
|- -|
hosts = localhost
user = postfixuser
password = postfixuser
dbname = email
table = emailuser
select_field = domain
where_field = domain
|- -|
编辑my-maildir.cf
|- -|
hosts = localhost
user = postfixuser
password = postfixuser
dbname = email
table = emailuser
select_field = maildir
where_field = username
|- -|
测试
postmap -q “[email protected]” mysql:/etc/postfix/my-emailuser.cf
[email protected]
postmap -q “redhat.com” mysql:/etc/postfix/my-domain.cf
redhat.com
postmap -q “[email protected]” mysql:/etc/postfix/my-maildir.cf
/redhat.com/fu/
测试结果正确
reload postfix