萬盛學電腦網

 萬盛學電腦網 >> 服務器教程 >> 搭建完整郵件系統(postfix+dovecot+clamAV+Spamassassin+amavisd-new)

搭建完整郵件系統(postfix+dovecot+clamAV+Spamassassin+amavisd-new)

   相關軟件:

  1. 發送郵件 --- postfix

  2. 身份認證 --- sasl2

  3. 接收郵件 --- dovecot

  4. 防病毒郵件 --- clamAV

  5. 防垃圾郵件 --- spamassassin

  6.控制病毒及垃圾郵件掃描程序 --- amavisd-new

  ============================

  待完善的問題:

  1. 群發郵件的權限設置

  2. 用戶郵箱的配額限制

  ============================

  完整郵件系統架構簡介

  我們知道,一個完整的郵件系統應該包括以下幾個重要功能:

  基本功能: 發送郵件、收取郵件

  安全性功能: 收發郵件的身份認證、防病毒、防垃圾

  完整的郵件系統架構流程圖如下:

搭建完整郵件系統(postfix+dovecot+clamAV+Spamassassin+amavisd-new) 三聯

  相關軟件的安裝及配置

  1. 安裝postfix,同時讓postfix支持mysql查詢

  # aptitude install postfix postfix-mysql

  2. 查看postfix是否支持外部數據庫mysql認證

  # postconf -m

  btree

  cidr

  environ

  hash

  internal

  mysql

  nis

  proxy

  regexp

  sdbm

  static

  tcp

  unix

  3. 查看postfix支持的sasl認證類型

  # postconf -a

  cyrus

  dovecot

  4. 安裝cyrus sasl認證

  # aptitude install sasl2-bin libsasl2-modules-sql

  5. 修改/etc/default/saslauthd

  START=no ====> START=yes

  6. 重啟saslauthd,並驗證saslauthd正常工作

  # /etc/init.d/saslauthd restart

  # testsaslauthd -u {username} -p {password}

  若出現如下結果,表示saslauthd已正常運行,並可進行認證服務,否則請檢查username和password並重試

  0: OK "Success."

  注:{username},{password}是登錄linux系統的用戶名和密碼

  7. postfix啟用sasl認證

  編輯/etc/postfix/main.cf,在最後添加如下內容:

  smtpd_sasl_auth_enable = yes

  broken_sasl_auth_clients = yes

  smtpd_sasl_security_options = noanonymous

  8. 修改/etc/postfix/master.cf,禁止postfix啟用chroot

  smtp inet n - - - - smtpd

  rewrite unix - - - - - trivial-rewrite

  cleanup unix n - - - 0 cleanup

  ==========>>>>>>

  smtp inet n - n - - smtpd

  rewrite unix - - n - - trivial-rewrite

  cleanup unix n - n - 0 cleanup

  這樣設置的原因:如果不這麼設置,則在發送郵件時,總是報如下錯誤,且郵件無法發送成功:

  postfix/trivial-rewrite[10698]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

  postfix/trivial-rewrite[10698]: fatal: mysql:/etc/postfix/mysql_virtual_alias_maps.cf(0,lock|fold_fix): table lookup problem

  postfix/smtpd[10394]: warning: problem talking to service rewrite: Success

  postfix/master[10386]: warning: process /usr/lib/postfix/trivial-rewrite pid 10698 exit status 1

  postfix/smtpd[10697]: warning: problem talking to service rewrite: Connection reset by peer

  postfix/master[10386]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling

  9. 安裝mysql並創建數據庫和表,同時插入數據

  # aptitude install mysql-client mysql-server

  # mysql -u root -p

  輸入密碼

  # sql> create database mail;

  # sql> create table mail.users( id in(8) primary key auto_increment, username varchar(50), password varchar(50), domain varchar(50), quota int(10), maildir varchar(200));

  # sql> insert into mail.users(username,password,domain,maildir,quota) values('test','test','tiddy.com','tiddy.com/test/',16000);

  # sql> commit;

  10. 修改postfix通過sasl的認證方式(pam/shadow/sql/ldap),在/etc/postfix/sasl目錄下新建文件smtpd.conf,內容如下:

  pwcheck_method: auxprop

  auxprop_plugin: sql

  mech_list: PLAIN LOGIN CRAM-MD5 DIGEST-MD5 NTLM

  sql_engine: mysql

  sql_hostnames: 127.0.0.1

  sql_user: root

  sql_passwd: tiddy

  sql_database: mail

  sql_select: SELECT password FROM users WHERE username = '%u'

  11. 在postfix上安裝telnet並進行測試

  # aptitude install telnet

  # telnet localhost 25

  Trying 127.0.0.1...

  Connected to localhost.

  Escape character is '^]'.

  220 mail.tiddy.com ESMTP Postfix (Debian/GNU)

  auth login

  334 VXNlcm5hbWU6

  dGVzdA==

  334 UGFzc3dvcmQ6

  dGVzdA==

  235 2.7.0 Authentication successful

  mail from:

  250 2.1.0 Ok

  rcpt to:

  250 2.1.5 Ok

  data

  354 End data with .

  Subject: alskdjlasd

  lasdjflasdf

  .

  250 2.0.0 Ok: queued as 4C1FB440E6

  postfix sasl mysql認證成功

  注意:上述紅色標記的文字表示經過BASE64編碼的用戶名(test)和密碼(test)

  12. 安裝POP3軟件dovecot

  # aptitude install dovecot-pop3d

  13. 創建虛擬用戶(以便該用戶有權限訪問郵件存放目錄)

  # groupadd -g 5000 vmail

  # useradd -u 5000 -g 5000 vmail -d /var/vmail -m

  14. 配置dovecot

  修改/etc/dovecot/dovecot.conf,主要修改如下部分

  1) 去掉注釋符號(#)

  base_dir = /var/run/dovecot

  2) dovecot所使用的協議

  protocols = pop3 pop3s

  3) dovecot所監聽的端口(*:監聽所有網絡端口)

  listen = *

  4) 打開明文密碼認證(采用pop3協議收取郵件時,采用明文密碼認證)

  disable_plaintext_auth = no

  5) 日志文件

  log_path = /var/log/dovecot.log

  6) debug日志文件

  info_log_path = /var/log/dovecot.info

  7) 每行日志輸出的前綴

  log_timestamp = "%Y-%m-%d %H:%M:%S "

  8) 客戶端用pop3協議收取郵件時的服務器收取路徑

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

  9) 是否開啟debug(測試階段使用,正式投入使用後,最好關閉)

  mail_debug = yes

  10) dovecot的pop3認證

  auth default {

  #認證方式

  mechanisms = plain login

  #認證過程中的密碼查詢方式(采用sql查詢)

  passdb sql {

  # Path for SQL configuration file

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

  }

  #認證過程中的用戶查詢方式(采用sql查詢)

  userdb sql {

  # Path for SQL configuration file

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

  }

  #監聽客戶端socket以便隨時發現客戶端發起的用戶身份認證

  socket listen {

  client {

  path = /var/spool/postfix/private/auth

  mode = 0660

  user = postfix

  group = postfix

  }

  }

  }

  15. 修改/etc/dovecot/dovecot-sql.conf

  1) 數據庫驅動

  driver = mysql

  2) 數據庫連接信息

  connect = host=localhost dbname=mail user=root password=tiddy

  3) 數據庫密碼的加密方式(PLAIN:明文方式,不加密)

  default_pass_scheme = PLAIN

  4) 數據庫查詢語句

  password_query = SELECT username, domain, password FROM users WHERE username = '%n'

  user_query = SELECT maildir, 5000 AS uid, 5000 AS gid FROM users WHERE username = '%n'

  16. 重新修改/etc/postfix/main.cf(注意:有的內容已經存在或添加過,請務必不要重復添加)

  ######################## 基本配置 ##########################

  myhostname = postfixsvr

  alias_maps = hash:/etc/aliases

copyright © 萬盛學電腦網 all rights reserved