阿里雲Centos7.3實踐:搭建Sendmail服務器和配置

*以服務器地址120.79.254.2爲例,服務器具體地址數值僅爲示範所需,並非真實所用地址,如有冒犯,請聯繫更改。

1. 切換權限

sudo su root


2.安裝DNS服務器軟件包

yum install bind -y

yum install bind-libs -y


3.配置/etc/named.conf文件

vim /etc/named.conf

修改:

listen-on port 53 { any; };

allow-query     { any; };

增加:

zone "uc-knight.top" IN{
        type master;
        file "uc-knight.top.zone";
};


zone "254.79.120.in-addr.arpa" IN{
        type master;
        file "254.79.120.zone";
};


4.配置 /var/named/uc-knight.top.zone 文件

vim /var/named/uc-knight.top.zone

$ttl 600

@        IN         SOA     lance.uc-knight.top.   lance.www.uc-knight.top.(
         2018060601  10800    3600    604800  38400 )
;        Serial      Refresh  Retry   Expire  MinumumTTL
;     Serial<2^32    Refresh>=Retry*2  Refresh+Retry<Expire
;                                                     Expire>=Retry*10
@                                    IN         NS      lance.uc-knight.top.
lance.uc-knight.top.           IN         A       120.79.254.2
@                                    IN         MX   5  www.uc-knight.top.
www.uc-knight.top.           IN          A       120.79.254.2


5.配置 /var/named/254.79.120.zone 文件

vim /var/named/254.79.120.zone

$ttl 600
@        IN            SOA     lance.uc-knight.top.   lance.www.uc-knight.top.(
         2018060601  10800    3600    604800  38400 )
;        Serial      Refresh  Retry   Expire  MinumumTTL
;     Serial<2^32    Refresh>=Retry*2  Refresh+Retry<Expire
;                                      Expire>=Retry*10
@        IN        NS       lance.uc-knight.top.
2         IN        PTR     lance.uc-knight.top.


6.啓動named服務,並設爲開機自啓

systemctl start named

systemctl enable named


*7.DNS客戶端配置(注意不是服務器端

Linux:  yum install bind-utils -y  然後編輯 vim /etc/resolv.conf  

本例中爲  nameserver 120.79.254.2

Windows: 本地連接/網絡適配器-ipv4協議-手動配置輸入dns地址 

本例中爲 使用下面的DNS服務器地址- 120.79.254.2


                                                                                                                         

**額外小內容:web服務器配置(基於完成以上DNS配置步驟)

a.安裝web服務器軟件包

yum install httpd -y

yum install httpd-tools -y

yum install http-manual -y


b.修改/etc/httpd/conf/httpd.conf 文件

vim /etc/httpd/conf/httpd.conf

修改以下內容

ServerAdmin [email protected]

ServerName www.uc-knight.top


c.將網頁保存到/var/www/html目錄中

本例使用echo命令生成index.html文件 

echo "Welcome to uc-knight.top! " >/var/www/html/index.html


d.啓動httpd服務,設爲開機自啓

systemctl start httpd

systemctl enable httpd

                                                                                                                         


8.安裝Sendmail服務器軟件包(sendmail, sendmail-cf, procmail, m4)

yum install sendmail -y

yum install sendmail-cf -y


9.驗證郵件交換器設置(通過配置好DNS的客戶端,即完成了執行第7點的客戶端)

nslookup -q=mx uc-knight.top

   輸出爲:

              Server:  120.79.254.2
              Address: 120.79.254.2#53

              uc-knight.top mail exchanger = 5 www.uc-knight.top.


10.配置 /etc/mail/sendmail.mc 文件

vim /etc/mail/sendmail.mc

修改:

dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

LOCAL_DOMAIN(`uc-knight.top')dnl


11.使用m4進行重定向/etc/mail/sendmail.cf

m4 /etc/mail/sendmail.mc >/etc/mail/sendmail.cf


12.vim /etc/mail/local-host-names

增加:

uc-knight.top              <--域

www.uc-knight.top      <--郵件主機名


13.vim /etc/hosts

增加:

120.79.254.2 lance www.uc-knight.top

   服務器ip地址;主機名;郵箱主機名 


**.修改主機名(靜態 瞬態 靈活主機名同時修改)

hostnamectl set-hostname <hostname>


**查詢主機名 hostname -f 

               或 vim /etc/hostname


*14.vim /etc/mail/access

120.79.254                              RELAY
uc-knight.top                          RELAY

修改後重定向:

makemap hash /etc/mail/access.db </etc/mail/access


*15.編輯/etc/aliases文件


編輯後使用newaliases生成/etc/aliases.db數據庫


16.運行sendmail服務,設置開機自啓

systemctl start sendmail

systemctl enable sendmail

*可使用 systemctl status sendmail 查看是否已啓動

*可使用 systemctl status sendmail -l 查看服務具體啓動情況

*可使用 systemctl is-enabled sendmail 查詢是否已設置爲開機啓動


17.安裝dovecot軟件包

yum install dovecot -y


18.vim /etc/dovecot/dovecot.conf

修改:

protocols = imap pop3 lmtp

listen = *

base_dir = /var/run/dovecot/


19.運行dovecot服務,設爲開機自啓

systemctl start dovecot

systemctl enable dovecot


開始測試 在配置好dns的客戶端上 遠程登陸pop3端口110

*SMTP 端口 TCP 25

*POP3 端口 TCP 110

*IMAP 端口 TCP  143

telnet 120.79.254.2 110

user test

pass test

(用戶自己在系統中添加)


問題一:輸入user test 回車後出現 

-ERR [AUTH] Plaintext authentication disallowed on non-secure (SSL/TLS) connections.

解決:

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

修改

disable_plaintext_auth = no


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

修改

ssl = no


重啓dovecot服務

systemctl restart dovecot


問題二:修改問題一後,輸入pass test,出現

 -ERR [SYS/TEMP] Internal error occurred. Refer to server log for more information.

Connection closed by foreign host.

使用命令查看log

tail /var/log/maillog

Jun  6 23:43:29 iz6yiqbo5vklydz dovecot: pop3(test): Error: user test: Initialization failed: Namespace '': Mail storage autodetection failed with home=/home/test

Jun  6 23:43:29 iz6yiqbo5vklydz dovecot: pop3(test): Error: Invalid user settings. Refer to server log for more information.


解決: vim /etc/dovecot/conf.d/10-mail.conf

設置mail_location參數

 mail_location = mbox:~/mail:INBOX=/var/mail/%u 



問題三:接着修改完問題二後,繼續登錄,出現

-ERR [SYS/PERM] Permission denied
Connection closed by foreign host.


查看日誌 tail /var/log/maillog

Error: chown(/home/test/mail/.imap, group=12(mail)) failed: Operation not permitted (egid=1002(test), group based on /var/mail/test - see http://wiki2.dovecot.org/Errors/ChgrpNoPerm)
Jun  6 23:51:12 iz6yiqbo5vklydz dovecot: pop3(test): Error: Couldn't open INBOX: Permission denied
Jun  6 23:51:12 iz6yiqbo5vklydz dovecot: pop3(test): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0


解決方案

更改權限 chmod 0600 /var/mail/*  (或者權限改爲777等)

本例中爲test用戶 故命令爲 chmod 0600 /var/mail/test




**使用命令查看日誌文件

 cat /var/log/maillog

 tail /var/log/maillog


**不要用root用戶遠程登錄郵箱服務器


WINDOWS客戶端登錄示例(需要先配置DNS)

1.FOXMAIL



或者 直接輸入郵件服務器IP地址 則不需要配置DNS




2.THUNDERBIRD







參考自:http://linux.vbird.org/linux_server/0350dns.php (DNS相關知識和設置)

https://wenku.baidu.com/view/09ada240a32d7375a5178006.html (配置dovecot常見錯誤問題 問題一二解決方案)

https://wiki2.dovecot.org/Errors/ChgrpNoPerm?spm=5176.10173289.0.0.70742e77HdSTBU(問題三解決方案)

發佈了35 篇原創文章 · 獲贊 13 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章