码迷,mamicode.com
首页 > 其他好文 > 详细

PostFix邮件搭建

时间:2015-04-09 17:54:58      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:虚拟机   主机   数据库   

简单邮件服务搭建组合php,数据库的茶渣
准备两台虚拟机A,B
A机器为邮件发送端,配置DNS域
##############
设定A的IP:172.25.254.133 主机名:mail.westos.org
#vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
IPADDR=172.25.254.133
NETMASK=255.255.255.0
GATEWAY=172.25.254.101
编辑DNS指定文件/etc/resolv.conf
nameserver 172.25.254.133
#############
设定B的IP:172.25.254.144 主机名:mail.luck.com
#vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
DNS1=172.25.254.133
IPADDR=172.25.254.141
NETMASK=255.255.255.0
GATEWAY=172.25.254.101
编辑DNS指定文件/etc/resolv.conf
nameserver 172.25.254.133
二,配置DNS(在A机器)
#yum install -y bind
#vim /etc/named.conf
options {
//      listen-on port 53 { 127.0.0.1; };
//      listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
//      allow-query     { localhost; };
dnssec-enable yes;
dnssec-validation no;
dnssec-lookaside auto;
配置解析的域,westos.org;luck.com
#vim /etc/named.rfc1912.zones
添加如下代码:
zone "westos.org" IN {
        type master;
        file "westos.org.zone";//为管理的域
        allow-update { none; };
};

zone "luck.com" IN {
        type master;
        file "luck.com.zone";//为管理的域指定B机器的IP
        allow-update { none; };
};
#cd /var/named/
#cp -p named.localhost  westos.org.zone
#cp -p named.localhost  luck.com.zone
#vim westos.org.zone
$TTL 1D
@       IN SOA   mail.westos.org. root.westos.org. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                NS      mail.westos.org.
mail            A       172.25.254.133
westos.org.     MX  1   172.25.254.133.
#vim luck.com.zone
$TTL 1D
@       IN SOA  mail.luck.com. root.luck.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                NS      mail.luck.com.
mail            A       172.25.254.133
luck.com.       MX 1    172.25.254.141.
#systemctl restart named.service
在B机器上测试 dig
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> luck.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39547
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;luck.com.            IN    A

;; AUTHORITY SECTION:
luck.com.        10800    IN    SOA    mail.luck.com. root.luck.com. 0 86400 3600 604800 10800

;; Query time: 0 msec
;; SERVER: 172.25.254.133#53(172.25.254.133)
;; WHEN: Tue Feb 03 21:34:22 CST 2015
;; MSG SIZE  rcvd: 83
显示如上表示ok。

三,配置邮件postfix
在A机器上
#vim /etc/postfix/main.cf
76 myhostname = mail.westos.org
83 mydomain = westos.org
99 myorigin = $mydomain
116 inet_interfaces = all
119 inet_protocols = all
164 mydestination = $myhostname, $mydomain, localhost
#systemctl restart postfix
在B机器上
#vim /etc/postfix/main.cf
75 myhostname = mail.luck.com
83 mydomain = luck.com
99 myorigin = $mydomain
116 inet_interfaces = all
119 inet_protocols = all
164 mydestination = $myhostname, $mydomain, localhost
#systemctl restart postfix
在A机器发送邮件测试
# mail root@luck.com
Subject: hello world
hhhhh
.
EOT


在B机器查看
# mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 2 messages 1 new
    1 root                  Tue Feb  3 21:08  22/720   "ggg"
>N  2 root                  Tue Feb  3 21:47  21/719   "hello world"
& 2
Message  2:
From root@westos.org  Tue Feb  3 21:47:33 2015
Return-Path: <root@westos.org>
X-Original-To: root@luck.com
Delivered-To: root@luck.com
Date: Tue, 03 Feb 2015 21:47:33 +0800
To: root@luck.com
Subject: hello world
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@westos.org (root)
Status: R

hhhhh

####################################################
#cd /etc/postfix/             
#vim mysql-users.cf
hosts = localhost
user = mail
password = mail
dbname = mail
table = postfix
select_field = username
where_field = username      
#vim mysql-domains.cf
hosts = localhost
user = mail
password = mail
dbname = mail
table = postfix
select_field = domain
where_field = domain
     
#vim mysql-mailboxs.cf       
hosts = localhost
user = mail
password = mail
dbname = mail
table = postfix
select_field = maildir
where_field = username
#useradd -uid 8888 vmail
#id vmail    
#postconf -d |grep virtual     
   
#postconf -e " virtual_uid_maps = static:8888"   
#postconf -e " virtual_gid_maps = static:8888"   
#postconf -e " virtual_alias_maps = mysql:/etc/postfix/mysql-users.cf"   
#postconf -e " virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf"   
#postconf -e " virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailboxs.cf"         
#postconf  -e "virtual_mailbox_base = /home/vmail"    
#vim main.cf       
#systemctl restart postfix.service      
#echo > /var/log/maillog      
#postmap -q "user1@lee.com" mysql:/etc/postfix/mysql-users.cf
user1@lee.com  
#postmap -q "lee.com" mysql:/etc/postfix/mysql-domains.cf
lee.com           
#postmap -q "user1@lee.com" mysql:/etc/postfix/mysql-mailboxs.cf
/lee.com/user1/      
#echo > /var/spool/mail/root      
       
#systemctl restart postfix.service
二,配置数据库mariadb          
#systemctl restart mariadb
#mysql -uroot -ppassword
CREATE DATABASE mail;
create user mail@localhost identified by ‘mail‘;
grant select on mail.* to mail@localhost;

CREATE TABLE IF NOT EXISTS `postfix` (
  `username` varchar(100) NOT NULL,
  `password` varchar(100) NOT NULL,
  `domain` varchar(100) NOT NULL,
  `maildir` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `postfix`
--

INSERT INTO `postfix` (`username`, `password`, `domain`, `maildir`) VALUES
(‘user1@lee.com‘, ‘123‘, ‘lee.com‘, ‘/lee.com/user1/‘);

#systemctl restart mariadb
#mysql -umail -pmail
-->show databases;
-->use mail;
-->select * from postfix;
+---------------+----------+---------+-----------------+
| username      | password | domain  | maildir         |
+---------------+----------+---------+-----------------+
| user1@lee.com | 123      | lee.com | /lee.com/user1/ |
+---------------+----------+---------+-----------------+
1 row in set (0.00 sec)

      
#systemctl restart postfix.service      

#cd /home/vmail/       
#ls        
#cd /etc/postfix/             
#vim main.cf       
virtual_uid_maps = static:8888
virtual_gid_maps = static:8888
virtual_alias_maps = mysql:/etc/postfix/mysql-users.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-mailboxs.cf
virtual_mailbox_base = /home/vmail

#setenforce 0       
#systemctl stop firewalld      
#systemctl restart postfix.service      
#cho > /var/log/maillog         
#systemctl restart postfix
在A机器上增加lee.com域
# vim /etc/named.rfc1912.zones
增加:
zone "lee.com" IN {
        type master;
        file "lee.com.zone";
        allow-update { none; };
};
#cd /var/named/
#cp luck.com.zone  lee.com.zone -p
#vim  lee.com.zone
$TTL 1D
@       IN SOA  mail.lee.com. root.lee.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                NS      mail.lee.com.
mail            A       172.25.254.133
lee.com.        MX 1    172.25.254.141.

#systemctl restart named

在A机器执行mail user1@lee.com
mail user1@lee.com
Subject: hhhhhj
hhhhh
.
EOT
在B机器上查看
#cd /home/vmail/
#ls
lee.com
#cd lee.com
#ls
user1
#cd user1
cur  new  tmp//好像只有new目录中有来自机器A的邮件
#cd new
1422980585.Vfd01I28117c1M71169.mail.luck.com
1422983481.Vfd01I28117c2M272787.mail.luck.com











本文出自 “在时间里愛着你” 博客,谢绝转载!

PostFix邮件搭建

标签:虚拟机   主机   数据库   

原文地址:http://solongcc.blog.51cto.com/8979378/1630467

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!