centos7.3 set up within the network postfix mail system


Requirements: network mail system, LAMP + Postfix + Dovecot + Postfixadmin

Environment: centos7.3 lnmp

One. Bind DNS service deployment

1. Uninstall system comes with the sendmail service

Shell > yum -y remove sendmail

2. Modify the server host name

Shell > hostnamectl set-hostname mail

$hostname

$mail


3. Install the DNS Service

3.1 yum install

Shell > yum -y install bind

3.2 Configuring DNS Services

Shell > vim /etc/named.conf

name.png

Two red box in Figure modification is any, which means listen to all addresses, allow everyone to access

  Shell > vim /etc/named.rfc1912.zones

zone11.png

Into / var / named directory are copied to named.localhost xx.com.zone, copy and edit named.loopback is xx.com.local

Shell > cp -rf named.localhost hy.com.zone

 

Shell > cp -rf named.loopback 2.168.192.local

 

Shell > vim hy.com.zone

hy.png 

Shell > vim 2.168.192.local

 hy1.png

3.3 Start and verify DNS Service

Shell > systemctl start named

Shell > systemctl enable named

Use netstat tool to view the port, nslookup tool to verify

 238.png 

 nslookup.png

two. postfix installation configuration

yum install postfix

Shell > yum -y install postfix

Modify the configuration to the configuration file main.cf postfix in

Shell > vim /etc/postfix/main.cf

myhostname = mail.hy.com

mydomain = hy.com

myorigin = $myhostname

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost

Shell > systemctl start postfix

Shell > systemctl enable postfix

三.Dovecot 安装配置

yum安装dovecot

Shell > yum -y install dovecot dovecot-devel dovecot-mysql pam-devel

Shell > dovecot --version

创建dovecot工作的用户及用户组

Shell > groupadd -g 2000 vmail

Shell > useradd -g vmail -u 2000 -s /sbin/nologin -M vmail

dovecot的配置文件都在/etc/dovecot/目录下。

Shell > vim /etc/dovecot/dovecot.conf

protocols = imap pop3 lmtp

listen = *

login_trusted_networks =192.168.2.0/24

!include conf.d/*.conf

Shell > vim /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_auth = no

auth_mechanisms = plain login

!include auth-system.conf.ext

Shell > vim /etc/dovecot/conf.d/10-ssl.conf

ssl = no

启用dovecot的日志,日志路径可以自定义

Shell > vim /etc/dovecot/conf.d/10-logging.confspacer.gif 

 logging.png

启动dovecot服务

Shell > systemctl start dovecot

四.postfix虚拟用户配置

1、 修改main.cf 文件

Shell > vim /etc/postfix/main.cf

#启用SMTP认证

smtpd_sasl_type = dovecot

smtpd_sasl_path = /var/spool/postfix/private/auth

smtpd_sasl_application_name = smtpd

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

broken_sasl_auth_clients = yes

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination,reject_unknown_sender_domain

smtpd_sasl_security_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

smtpd_client_restrictions = permit_sasl_authenticated

smtpd_sasl_security_options = noanonymous

proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps

#启用虚拟用户

virtual_mailbox_base = /home/vmail/

virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf

virtual_alias_maps =

   proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,

   proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf,

   proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf

virtual_mailbox_maps =

   proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,

   proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf

virtual_uid_maps = static:2000

virtual_gid_maps = static:2000

virtual_transport = dovecot

dovecot_destination_recipient_limit = 1

2. 修改master.cf 文件

Shell > vim /etc/postfix/master.cf

dovecot   unix  -       n       n       -       -       pipe

flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}

特别注意:flages前面有两个空格,不然会报错,不要入坑-_-.

2.1 数据库连接相关文件

连接数据库相关文件有7个,在创建配置文件之前,我们要在/etc/postfix/目录下建立sql目录用来存放这些配置如下:

Shell > mkdir /etc/postfix/sql

Shell > vim /etc/postfix/sql/mysql_virtual_alias_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

 

Shell > vim /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'

Shell > vim /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf

 

Shell > vim /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'

 

 

Shell > vim /etc/postfix/sql/mysql_virtual_domains_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'

 

Shell > vim /etc/postfix/sql/mysql_virtual_mailbox_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'

 

Shell > vim /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u','@',alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'

 

Shell > vim /etc/postfix/sql/mysql_virtual_mailbox_limit_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'

 

五.Dovecot 虚拟用户配置

1. 修改dovecot.conf文件

Shell > vim /etc/dovecot/dovecot.conf

protocols = imap pop3

listen = *

mail_location = maildir:/home/vmail/%d/%n   (曾经掉坑过)

!include conf.d/*.conf

passdb {

  driver = sql

  args = /etc/dovecot/dovecot-sql.conf.ext

}

userdb {

  driver = static

  args = uid=5000 gid=5000 home=/home/vmail/%d/%n

}

#调试日志

auth_debug_passwords=yes

mail_debug=yes

auth_verbose=yes

auth_verbose_passwords=plain

 

2. 修改10-auth.conf文件

Shell > vim /etc/dovecot/conf.d/10-auth.conf

disable_plaintext_auth = no

auth_mechanisms = plain login cram-md5

!include auth-system.conf.ext

3. 修改10-ssl.conf文件

Shell > vim /etc/dovecot/conf.d/10-ssl.conf

 

ssl = no

4. 修改10-mail.conf文件

Shell > vim /etc/dovecot/conf.d/10-mail.conf

mail_location = maildir:/home/vmail/%d/%n/Maildir   

mbox_write_locks = fcntl

 

5. 修改10-logging.conf文件

Shell > vim /etc/dovecot/conf.d/10-logging.conf

info_log_path = /var/log/dovecot_info.log

debug_log_path = /var/log/dovecot_debug.log

 

6. 修改10-master.conf文件

Shell > vim /etc/dovecot/conf.d/10-master.conf

service imap-login {

  inet_listener imap {

    port = 143

  }

}

service pop3-login {

  inet_listener pop3 {

    port = 110

  }

}

service auth {

   unix_listener auth-userdb {

mode = 0600

    user = vmail

    group = vmail

  }

  # Postfix smtp-auth

unix_listener /var/spool/postfix/private/auth {

    mode = 0666

    user = postfix

  }

}

7. 添加dovecot-sql.conf.ext文件

dovecot-sql.conf.ext 可能默认不在/etc/dovecot/

用find 命令查找一下此文件在哪,然后把此文件复制到/etc/dovecot/

Shell > find / -name dovecot-sql.conf.ext

sql1.png

Shell > vim /etc/dovecot/dovecot-sql.conf.ext

driver = mysql

connect = host=localhost dbname=postfix user=postfix password=postfix

default_pass_scheme = MD5-CRYPT

password_query = SELECT username AS user,password FROM mailbox WHERE username = '%u' AND active='1'

user_query = SELECT maildir, 2000 AS uid, 2000 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') as quota FROM mailbox WHERE username = '%u' AND active='1'

 

六.postfixadmin配置

1. 下载postfixadmin源码包

Shell > wget  \

https://nchc.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-3.2/postfixadmin-3.2.tar.gz

2. 把解压出来的postfixadmin-3.2 重命名下

Shell > mv postfixadmin-3.2 postfixadmin

然后放在nginx 网站根目录下

3. 创建config.local.php配置文件

Shell > vim config.local.php

 <?php

    $CONF['database_type'] = 'mysqli';

    $CONF['database_user'] = 'postfix';

    $CONF['database_host'] = '127.0.0.1';

    $CONF['database_password'] = 'postfix';

    $CONF['database_name'] = 'postfix';

    $CONF['configured'] = true;

?>

4. 修改config.inc.php配置文件

Shell > vim config.inc.php

修改 $CONF['configured'] = false; 为 $CONF['configured'] = true;

修改 $CONF['default_language'] = 'en'; 为 $CONF['default_language'] = 'cn';                                                 修改成默认为中文

修改 $CONF['database_type'] = 'mysqli'; 为 $CONF['database_type'] = 'mysql';                                              

修改 $CONF['database_host'] = 'localhost'; 为 $CONF['database_host'] = '127.0.0.1';                  

修改 $CONF['database_password'] = 'postfixadmin'; 为 $CONF['database_password'] = 'postfix';  

修改 $CONF['admin_email'] = ''; 为 $CONF['admin_email'] = '[email protected]';                                         

如下图所示:

sql2.png

sql3.png 

sql4.png

5. 配置文件改完,然后再浏览器中打开:http://ip/postfixadmin/public/setup.php 或者  http://域名/postfixadmin/public/setup.php

There is an error, an error based on its content, create a directory under templates_c postfixadmin directory, and authorized under my postfixadmin // directory / usr / share / nginx / html,

Shell > mkdir templates_c

Shell> chmod -R 755 templates_c # or 777

6. refresh the page, as shown below, and has a Error Warning

Note: The first suggested that Rom database, this time we want to check config.local.php config.inc.php configuration file and configuration data, account data, database name, password, address, etc. are correct database, which may be a configuration error, will have such an error.

 

The second prompt to install the php imap extension:

imap.png 

 

Shell > yum -y install php56w-imap-5.6.40-1.w7.x86_64

 

In the refresh, the error did not,

We began to set a password

admin.png 

At this time, we want a red box $ CONF [ 'setup_password'] = '264d4931e17c6ea7d7cead0123354f94: 67d1764819b702ee631d6c73bfff2c169fd7c717'; copied to the config.inc.php.

Shell > vim config.inc.php

inc.png 

 

Then refresh the page, add the Administrator mailbox, as

admin.png 

Finally, delete setup.php, use http: //ip/postfixadmin/public/index.php landing page management, as:

adminlogin.png 

 

Refer to the online link below:

https://blog.51cto.com/4746316/2314749

https://www.ilanni.com/?p=10963

 


Guess you like

Origin blog.51cto.com/xpu2001/2416783