基於postfix做一個簡單的郵件服務器,你學會了嗎?

郵件服務器(Mail Server)是電子郵件系統的核心,它包括郵件發送服務器(SMTP服務器)和郵件接收服務器(POP3)。郵件服務器的功能是發送和接收郵件,同時還向發送人報告郵件的發送情況。

SMTP:Simple Mail Tansfer Protocol 簡單郵件傳輸協議,它使用傳輸層TCP協議的25端口;

POP3:Post Office Protocol 郵局協議,它使用傳輸層TCP協議的110端口。

一、首先做DNS服務器

1、下載yum源

clip_image002

2、安裝bind包

clip_image004

3、編輯配置文件內容vim /etc/named.conf 內容修改如下:

clip_image006

4、vim /etc/named.rfc1912.zones 添加內容如下

clip_image008

5、編輯完配置文件後檢查是否有語法錯誤

clip_image010

6、cd /var/named

vim wxx.com.zone 編輯配置文件內容如下

clip_image012

7、檢查是否有語法錯誤並關閉selinux

clip_image014

vim /etc/sysconfig/selinux (vim /etc/sysconfig/selinux是vim /etc/selinux/config的鏈接,這兩個路徑將來在很多地方都能看到)

clip_image016

8、修改權限

clip_image018

clip_image020

9、查看53號端口

clip_image022

測試一下

clip_image024

10、vim /etc/resolv.conf 編輯配置文件內容如下

clip_image026

11、編輯配置文件vim /etc/sysconfig/network 改自己的主機名

clip_image028

hostname mail.wxx.com 與主機名保持一致

named已完成,下一步安裝postfix

二、安裝postfix

1、安裝postfix前請確保我們的開發庫都已安裝

clip_image030

2、安裝mysql-server和mysql-devel

clip_image032

3、啓動mysql

clip_image034

clip_image036

chkconfig mysqld on 開啓mysql

4、測試mysql

clip_image038

5、下載安裝mysql

clip_image040

6、創建postfix用戶

groupadd -g 2525 postfix

useradd -g postfix -u 2525 -s /sbin/nologin -M postfix

groupadd -g 2526 postdrop

useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop

7、解壓postfix文件並設定系統用戶的時間

clip_image042

crontab -e 編輯內容如下

clip_image044

8、make makefiles

clip_image046

make

make install

9、vim /etc/init.d/postfix 編輯配置文件內容腳本如下:  

  1. #!/bin/bash  
  2. #  
  3. # postfix Postfix Mail Transfer Agent  
  4. #  
  5. # chkconfig: 2345 80 30  
  6. # description: Postfix is a Mail Transport Agent, which is the program \  
  7. # that moves mail from one machine to another.  
  8. # processname: master  
  9. # pidfile: /var/spool/postfix/pid/master.pid  
  10. # config: /etc/postfix/main.cf  
  11. # config: /etc/postfix/master.cf  
  12. # Source function library.  
  13. . /etc/rc.d/init.d/functions  
  14. # Source networking configuration.  
  15. . /etc/sysconfig/network  
  16. Check that networking is up.  
  17. [ $NETWORKING = "no" ] && exit 3  
  18. [ -x /usr/sbin/postfix ] || exit 4  
  19. [ -d /etc/postfix ] || exit 5  
  20. [ -d /var/spool/postfix ] || exit 6  
  21. RETVAL=0  
  22. prog="postfix" 
  23. start() {  
  24. # Start daemons.  
  25. echo -n $"Starting postfix: " 
  26. /usr/bin/newaliases >/dev/null 2>&1  
  27. /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start" 
  28. RETVAL=$?  
  29. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix  
  30. echo  
  31. return $RETVAL  
  32. }  
  33. stop() {  
  34. # Stop daemons.  
  35. echo -n $"Shutting down postfix: " 
  36. /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop" 
  37. RETVAL=$?  
  38. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix  
  39. echo  
  40. return $RETVAL  
  41. }  
  42. reload() {  
  43. echo -n $"Reloading postfix: " 
  44. /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload" 
  45. RETVAL=$?  
  46. echo  
  47. return $RETVAL  
  48. }  
  49. abort() {  
  50. /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort" 
  51. return $?  
  52. }  
  53. flush() {  
  54. /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush" 
  55. return $?  
  56. }  
  57. check() {  
  58. /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check" 
  59. return $?  
  60. }  
  61. restart() {  
  62. stop  
  63. start  
  64. }  
  65. # See how we were called.  
  66. case "$1" in 
  67. start)  
  68. start  
  69. ;;  
  70. stop)  
  71. stop  
  72. ;;  
  73. restart)  
  74. stop  
  75. start  
  76. ;;  
  77. reload)  
  78. reload  
  79. ;;  
  80. abort)  
  81. abort  
  82. ;;  
  83. flush)  
  84. flush  
  85. ;;  
  86. check)  
  87. check 
  88. ;;  
  89. status)  
  90. status master  
  91. ;;  
  92. condrestart)  
  93. [ -f /var/lock/subsys/postfix ] && restart || :  
  94. ;;  
  95. *)  
  96. echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}" 
  97. exit 1  
  98. esac  
  99. exit $?  
  100. END 

添加執行權限

clip_image048

10、cd /etc/postfix/

編輯配置文件vim main.cf

clip_image050

clip_image052

clip_image054

clip_image056

11、查看我們新配的項

clip_image058

12、查看日誌信息

clip_image060

發現sendmail忘記關閉不要着急,我們有應對方案

service sendmail stop 先停止sendmail

chkconfig sendmail off 關閉sendmail

clip_image062

13、查看25號端口新建用戶後並測試

clip_image064

useradd hadoop 新建用戶hadoop

useradd openstak 新建用戶openstack

echo "hadoop" | passwd --stdin hadoop 設置密碼同用戶名

ehho "redhat" | passwd --stdin openstack 設置密碼同用戶名

clip_image066

14、查看日誌

clip_image068

三、測試使用windows遠程發送郵件

1、配置OE嘗試發送郵件

clip_image070

clip_image072

clip_image074

clip_image076

clip_image078

clip_image080

2、登錄hadoop用戶給openstack發送一封郵件

clip_image082

3、由於我們現在還沒有收郵件的服務器,所以就在本機上查看內容郵件內容

clip_image084

這樣我們就實現了郵件的收發功能。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章