天天看點

linux6郵件伺服器搭建,CentOS 6 使用Postfix 和Dovecot 搭建郵件伺服器

本文介紹如何在用Postfix 和Dovecot 在CentOS 6 上搭建一個 POP3/IMAP/SMTP 郵件伺服器。你可能不知道啥子是Postfix,這貨是Sendmail的完美替代品,sendmail不但發信慢,而且還容易堆積一堆郵件,消耗伺服器資源。Postfix不但速度快,而且容易管理,還更安全。

如果你不會使用VI指令,請手動上傳下載下傳更新相應檔案。路徑為VI指令中的路徑。

更新系統

screen -U -S mailserver-screen

yum update

建立使用者組

groupadd vmail -g 2222

建立使用者

useradd vmail -r -g 2222 -u 2222 -d /var/vmail -m -c "mail user"

安裝Postfix

yum remove exim sendmail

yum install postfix cronie

修改postfix 配置檔案 main.cf

cp /etc/postfix/main.cf{,.orig}

vim /etc/postfix/main.cf

myhostname = fatesinger.com

mydomain = fatesinger.com

myorigin = $mydomain

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/libexec/postfix

data_directory = /var/lib/postfix

mail_owner = postfix

unknown_local_recipient_reject_code = 550

alias_maps = hash:/etc/postfix/aliases

alias_database = $alias_maps

inet_interfaces = all

inet_protocols = ipv4

mydestination = $myhostname, localhost.$mydomain, localhost

debug_peer_level = 2

debugger_command =

PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail.postfix

newaliases_path = /usr/bin/newaliases.postfix

mailq_path = /usr/bin/mailq.postfix

setgid_group = postdrop

html_directory = no

manpage_directory = /usr/share/man

sample_directory = /usr/share/doc/postfix-2.6.6/samples

readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

relay_domains = *

virtual_alias_maps=hash:/etc/postfix/vmail_aliases

virtual_mailbox_domains=hash:/etc/postfix/vmail_domains

virtual_mailbox_maps=hash:/etc/postfix/vmail_mailbox

virtual_mailbox_base = /var/vmail

virtual_minimum_uid = 2222

virtual_transport = virtual

virtual_uid_maps = static:2222

virtual_gid_maps = static:2222

smtpd_sasl_auth_enable = yes

smtpd_sasl_type = dovecot

smtpd_sasl_path = /var/run/dovecot/auth-client

smtpd_sasl_security_options = noanonymous

smtpd_sasl_tls_security_options = $smtpd_sasl_security_options

smtpd_sasl_local_domain = $mydomain

broken_sasl_auth_clients = yes

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

建立vmail_domains配置檔案

vim /etc/postfix/vmail_domains

mydomain.com OK

my-otherdomain.com OK

建立vmail_mailbox配置檔案

vim /etc/postfix/vmail_mailbox

[email protected] mydomain.com/info/

[email protected] my-otherdomain.com/info/

建立vmail_aliases配置檔案

vim /etc/postfix/vmail_aliases

[email protected] [email protected]

[email protected] [email protected]

hash 配置檔案

postmap /etc/postfix/vmail_domains

postmap /etc/postfix/vmail_mailbox

postmap /etc/postfix/vmail_aliases

touch /etc/postfix/aliases

vim +/submission /etc/postfix/master.cf

submission inet n - n - - smtpd

安裝DOVECOT

yum install dovecot

修改dovecot的配置檔案dovecot.conf

cp /etc/dovecot/dovecot.conf{,.orig}

vim /etc/dovecot/dovecot.conf

listen = *

ssl = no

protocols = imap lmtp

disable_plaintext_auth = no

auth_mechanisms = plain login

mail_access_groups = vmail

default_login_user = vmail

first_valid_uid = 2222

first_valid_gid = 2222

#mail_location = maildir:~/Maildir

mail_location = maildir:/var/vmail/%d/%n

passdb {

driver = passwd-file

args = scheme=SHA1 /etc/dovecot/passwd

}

userdb {

driver = static

args = uid=2222 gid=2222 home=/var/vmail/%d/%n allow_all_users=yes

}

service auth {

unix_listener auth-client {

group = postfix

mode = 0660

user = postfix

}

user = root

}

service imap-login {

process_min_avail = 1

user = vmail

}

建立虛拟使用者的密碼檔案。使用者名和密碼會儲存在這裡。

touch /etc/dovecot/passwd

doveadm pw -s sha1 | cut -d '}' -f2

vim /etc/dovecot/passwd

[email protected]:DOzcsKI8HY0bg8LAuz0DPKwS3WA=

chown root: /etc/dovecot/passwd

chmod 600 /etc/dovecot/passwd

啟動服務

chkconfig postfix on

chkconfig dovecot on

service postfix restart

service dovecot restart

如果是centos7 則使用如下指令

systemctl enable postfix.service

systemctl enable dovecot.service

systemctl start postfix.service

systemctl start dovecot.service

之後就可以測試收發郵件了。