郵件服務系列之怎樣實現基於虛擬域和虛擬用戶的認證過程

虛擬域和虛擬用戶的認證過程

準備工作:

1、安裝一些必要的rpm包

  1. # yum install perl-DBD-MySQL -y     #必須安裝,因爲mysql是編譯安裝的,這個不會自動安裝  
  2. # yum install mysql-devel -y        #因爲前面安裝dovecot時,由於依賴關係系統自動安裝了
  3. 一個mysql客戶端爲了不出錯誤,所以devel包也裝了  
  4. # yum install pcre-devel -y     # 編譯安裝apache用到  

2、由於後面的Extmail需要用到web服務,所以要安裝web服務,詳細過程請見博客-手動搭建LAMP

 

下面正式開始配置過程:

一、編譯安裝courier-authlib-0.64.0

  1. 1、安裝要用到的rpm包 
  2. [root@mail courier-authlib-0.64.0]# yum install mysql-devel 
  3. [root@mail courier-authlib-0.64.0]# yum install expect      #使用expect實現主機間通信的 
  4.  
  5. 查看和ldtl相關的包是否安裝: 
  6. [root@mail courier-authlib-0.64.0]# yum list | grep ltdl   
  7. Unable to read consumer identity 
  8. libtool-ltdl.i386                           1.5.22-7.el5_4             Base      
  9. libtool-ltdl-devel.i386                     1.5.22-7.el5_4             Base      
  10. [root@mail courier-authlib-0.64.0]# yum install libtool-ltdl libtool-ltdl-devel -y 
  11.  
  12. ltdl: 動態模塊加載器,courier-authlib需要用到,所以安裝相關的包 
  13.  
  14. 2、編譯安裝courier-authlib-0.64.0 
  15. 備註:在RHEL5上要使用0.64.0及之前的版本,否則,可能會由於sqlite版本過低問題導致configure檢查無法通過
  16. 或編譯無法進行。 
  17.  
  18. [root@mail ~]# date 0505145813.00  # 同步一下時間
  19. Sun May  5 14:58:00 CST 2013 
  20. [root@mail ~]# date 
  21. Sun May  5 14:58:13 CST 2013 
  22. [root@mail ~]# tar xf courier-authlib-0.64.0.tar.bz2  
  23. [root@mail ~]# cd courier-authlib-0.64.0   
  24. [root@mail courier-authlib-0.64.0]#./configure \ 
  25.     --prefix=/usr/local/courier-authlib \ 
  26.     --sysconfdir=/etc \ 
  27.     --without-authpam \ 
  28.     --without-authshadow \ 
  29.     --without-authvchkpw \ 
  30.     --without-authpgsql \ 
  31.     --with-authmysql \ 
  32.     --with-sqlite-libs=/usr/lib 
  33.     --with-sqlite-include=/usr/include 
  34.     --with-mysql-libs=/usr/local/mysql/lib \ 
  35.     --with-mysql-includes=/usr/local/mysal/include \ 
  36.     --with-redhat \ 
  37.     --with-authmysqlrc=/etc/authmysqlrc \ 
  38.     --with-authdaemonrc=/etc/authdaemonrc \ 
  39.     --with-mailuser=postfix \ 
  40.     --with-mailgroup=postfix \ 
  41.     --with-ltdl-lib=/usr/lib \ 
  42.     --with-ltdl-include=/usr/include 
  43. [root@mail courier-authlib-0.64.0]# make 
  44. [root@mail courier-authlib-0.64.0]# make install 
  45.  
  46.  
  47. 安裝完成後會在/usr/local/courier-authlib/目錄下生成一個var/spool/authdaemon套接字文件,系統會 
  48. 通過這個套接字文件和進程建立聯繫,所以權限要改爲755 
  49.  
  50. 備註:可以使用--with-authdaemonvar=/var/spool/authdaemon選項來指定進程套按字目錄路徑。 
  51.  
  52. [root@mail courier-authlib-0.64.0]# cd /usr/local/courier-authlib/var/  
  53. [root@mail spool]# ll 
  54. total 8 
  55. drwxr-x--- 2 postfix postfix 4096 Mar 31 04:41 authdaemon 
  56. [root@mail spool]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon 
  57. [root@mail spool]# ll 
  58. total 8 
  59. drwxr-xr-x 2 postfix postfix 4096 Mar 31 04:41 authdaemon 
  60.  
  61.  
  62. 在編譯路徑下複製幾個配置文件 
  63. [root@mail ~]# cd courier-authlib-0.64.0 
  64. [root@mail courier-authlib-0.64.0]# cp /etc/authdaemonrc.dist  /etc/authdaemonrc 
  65. [root@mail courier-authlib-0.64.0]# cp /etc/authmysqlrc.dist  /etc/authmysqlrc 
  66.  
  67. 修改/etc/authdaemonrc 文件 
  68. [root@mail courier-authlib-0.64.0]# vim /etc/authdaemonrc 
  69. authmodulelist="authmysql"         #認證模塊類型 
  70. authmodulelistorig="authmysql"     #支持認證的原始模塊類型 
  71. daemons=10                         #進程數,這個自己隨意指定
  72.  
  73.  
  74. 3、配置其通過mysql進行郵件帳號認證 
  75. 編輯/etc/authmysqlrc 爲以下內容,其中2525,2525 爲postfix 用戶的UID和GID。 
  76. MYSQL_SERVER localhost 
  77. MYSQL_PORT 3306                 #指定你的mysql監聽的端口,這裏使用默認的3306 
  78. MYSQL_USERNAME  extmail         #這時爲後文要用的數據庫的所有者的用戶名 
  79. MYSQL_PASSWORD  extmail         #密碼 
  80. MYSQL_SOCKET  /tmp/mysql.sock   #mysql的套接字文件,如果是rpm包裝的在/var/lib/mysql/mysql.lock 
  81. MYSQL_DATABASE  extmail         #虛擬用戶放在哪個庫中,這個庫有extman自動創建 
  82. MYSQL_USER_TABLE  mailbox       #mysql的用戶賬號放在哪個表中,這個也是由extman生成   
  83. MYSQL_CRYPT_PWFIELD  password 
  84. MYSQL_UID_FIELD  '2525' 
  85. MYSQL_GID_FIELD  '2525' 
  86. MYSQL_LOGIN_FIELD  username 
  87. MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)    #定義用戶郵箱地址   concat是一個內置函數
  88. MYSQL_NAME_FIELD  name  能將兩個字符串連接起來當做一個來使用
    MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)  
  89. 給courier-authlib提供SysV風格的服務腳本,並啓動服務 
  90. [root@mail courier-authlib-0.64.0]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib 
  91. [root@mail courier-authlib-0.64.0]# chmod +x /etc/init.d/courier-authlib 
  92. [root@mail courier-authlib-0.64.0]# chkconfig --add courier-authlib 
  93. [root@mail courier-authlib-0.64.0]# chkconfig --level 2345 courier-authlib on 
  94. [root@mail courier-authlib-0.64.0]# service courier-authlib start 
  95. Starting Courier authentication services: authdaemond 
  96.  
  97. 4、新建虛擬用戶郵箱所在的目錄,並將其權限賦予postfix用戶: 
  98. [root@mail ~]# mkdir -p /var/mailbox 
  99. [root@mail ~]# chown -R postfix /var/mailbox 
  100.  
  101. 接下來重新配置SMTP 認證,編輯 /usr/lib/sasl2/smtpd.conf ,確保其爲以下內容: 
  102. [root@mail ~]# vim /usr/lib/sasl2/smtpd.conf 
  103. pwcheck_method: authdaemond 
  104. mech_list: PLAIN LOGIN 
  105. authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket   #套接字文件路徑 
  106.  
  107. 由於要用到sasl,所以重啓一下saslauthd服務; 
  108. [root@mail ~]# service saslauthd restart 
  109. Stopping saslauthd:                                        [  OK  ] 
  110. Starting saslauthd:                                        [  OK  ] 

二、讓postfix支持虛擬域和虛擬用戶

  1. 1、編輯/etc/postfix/main.cf,添加如下內容: 
  2.  
  3. [root@mail ~]# vim /etc/postfix/main.cf 
  4.  
  5. ########################Virtual Mailbox Settings######################## 
  6. virtual_mailbox_base = /var/mailbox 
  7. virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf 
  8. virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf 
  9. virtual_alias_domains = 
  10. virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf 
  11. virtual_uid_maps = static:2525 
  12. virtual_gid_maps = static:2525 
  13. virtual_transport = virtual 
  14. maildrop_destination_recipient_limit = 1 
  15. maildrop_destination_concurrency_limit = 1 
  16.  
  17. ##########################QUOTA Settings######################## 
  18. message_size_limit = 14336000 
  19. virtual_mailbox_limit = 20971520 
  20. virtual_create_maildirsize = yes 
  21. virtual_mailbox_extended = yes 
  22. virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf 
  23. virtual_mailbox_limit_override = yes 
  24. virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later. 
  25. virtual_overquota_bounce = yes 
  26.  
  27.  
  28. 2、使用extman源碼目錄下docs目錄中的extmail.sql和init.sql建立數據庫: 
  29.  
  30. exman需要用到apache服務,所以請先安裝httpd,這裏是源碼編譯安裝的http-2.4.4,編譯過程 
  31. 請參考博客LAMP的搭建過程 
  32.  
  33. [root@mail ~]# tar xf extman-1.1.tar.gz  
  34. [root@mail ~]# cd extman-1.1 
  35. [root@mail extman-1.1]# ls 
  36. addon    cgi        contrib  docs  INSTALL  libs    README.fcgi  Version 
  37. AUTHORS  ChangeLog  daemon   html  lang     README  tools        webman.cf.default 
  38. [root@mail extman-1.1]# cd docs/ 
  39. [root@mail docs]# ls 
  40. backport        init.sql                      ldap_virtual_mailbox_maps.cf   mysql_virtual_limit_maps.cf 
  41. extmail.schema  ldap_virtual_alias_maps.cf    ldap_virtual_sender_maps.cf    mysql_virtual_mailbox_maps.cf 
  42. extmail.sql     ldap_virtual_domains_maps.cf  mysql_virtual_alias_maps.cf    mysql_virtual_sender_maps.cf 
  43. init.ldif       ldap_virtual_limit_maps.cf    mysql_virtual_domains_maps.cf  README.postfix 
  44. [root@mail docs]# sed -i 's@TYPE=MyISAM@ENGINE=InnoDB@g' extmail.sql  #改一下里面的引擎類型
  45. [root@mail docs]# mysql -uroot -p < extmail.sql 
  46. Warning: mysql: ignoring option '--named-commands' due to invalid value 'root' 
  47. Enter password:                                         #我這裏的mysql有密碼,你們的就沒有了 
  48. [root@mail docs]# mysql -uroot -p < init.sql 
  49. Warning: mysql: ignoring option '--named-commands' due to invalid value 'root' 
  50. Enter password:  
  51.   
  52.  
  53. 3、授予用戶extmail訪問extmail數據庫的權限 
  54.  
  55. [root@mail docs]# mysql -uroot -p 
  56. Warning: mysql: ignoring option '--named-commands' due to invalid value 'root' 
  57. Enter password:  
  58. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  59. Your MySQL connection id is 20 
  60. Server version: 5.5.28-log Source distribution 
  61.  
  62. Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 
  63.  
  64. mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail'
  65. Query OK, 0 rows affected (0.00 sec) 
  66. mysql>  GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail'
  67. Query OK, 0 rows affected (0.00 sec) 
  68.  
  69.  
  70. 4、提供配置文件 
  71.  
  72. [root@mail docs]# ls 
  73. backport        init.sql       ldap_virtual_mailbox_maps.cf   mysql_virtual_limit_maps.cf 
  74. extmail.schema  ldap_virtual_alias_maps.cf    ldap_virtual_sender_maps.
  75. mysql_virtual_mailbox_maps.cf 
  76. extmail.sql     ldap_virtual_domains_maps.cf  mysql_virtual_alias_maps.cf    mysql_virtual_sender_maps.cf 
  77. init.ldif       ldap_virtual_limit_maps.cf    mysql_virtual_domains_maps.cf  README.postfix 
  78. [root@mail docs]# cp mysql_virtual_* /etc/postfix/ 
  79. [root@mail docs]# cd /etc/postfix/ 
  80. [root@mail postfix]# ls 
  81. access             generic        main.cf.default              mysql_virtual_domains_maps.cf  relocated 
  82. aliases            header_checks  makedefs.out                 mysql_virtual_limit_maps.cf    TLS_LICENSE 
  83. bounce.cf.default  LICENSE        master.cf                    mysql_virtual_mailbox_maps.cf  transport 
  84. canonical          main.cf        mysql_virtual_alias_maps.cf  mysql_virtual_sender_maps.cf   virtual 
  85.  
  86.  
  87. 5、連接數據庫查看
  88.  
  89. [root@mail postfix]# mysql -uroot  
  90. Warning: mysql: ignoring option '--named-commands' due to invalid value 'root' 
  91. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  92. Your MySQL connection id is 23 
  93. Server version: 5.5.28-log Source distribution 
  94.  
  95. Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 
  96.  
  97. mysql> show databases; 
  98. +--------------------+ 
  99. Database           | 
  100. +--------------------+ 
  101. | information_schema |  
  102. | extmail            |  
  103. | mysql              |  
  104. | performance_schema |  
  105. | test               |  
  106. | wpdb               |  
  107. +--------------------+ 
  108. rows in set (0.00 sec) 
  109.  
  110. mysql> use extmail 
  111. Database changed 
  112. mysql> show tables; 
  113. +-------------------+ 
  114. | Tables_in_extmail | 
  115. +-------------------+ 
  116. | alias             |  
  117. | domain            |  
  118. | domain_manager    |  
  119. | mailbox           |  
  120. | manager           |  
  121. +-------------------+ 
  122. rows in set (0.04 sec) 
  123.  
  124. mysql> select * from domain\G            #讓查詢的內容縱向顯示 
  125. *************************** 1. row *************************** 
  126.               domain: extmail.org        #如果我們在domain這個表中添加lsq.com,他就給我們中
  127. 繼郵件了,此時只給這個域中繼郵件,這個域是sql腳本生成的 
  128.          description: virtualDomain for extmail.org        
  129.          hashdirpath: A0/B0 
  130.             maxalias: 50 
  131.             maxusers: 50 
  132.             maxquota: 1073741824 
  133.      maxnetdiskquota: 1073741824 
  134.            transport: NULL 
  135.           can_signup: 1 
  136.        default_quota: 5242880 
  137. default_netdiskquota: 5242880 
  138.       default_expire: 1y 
  139.         disablesmtpd: 0 
  140.          disablesmtp: 0 
  141.       disablewebmail: 0 
  142.       disablenetdisk: 0 
  143.          disableimap: 1 
  144.          disablepop3: 0 
  145.           createdate: 2007-02-14 15:10:04 
  146.           expiredate: 2010-11-08 
  147.               active: 1 
  148. 1 row in set (0.03 sec) 

三、配置dovecot,是dovecot也支持虛擬域和虛擬用戶

  1. 1、修改postfix的配置文件 
  2.  
  3. [root@mail postfix]# vim /etc/dovecot.conf 
  4. mail_location = maildir:/var/mailbox/%d/%n/Maildir  #表示在/var/mailbox下有每一個域,
  5. 在每個域下又有每一個用戶名命名的文件,而用戶的郵件則在maildir目錄中保存 
  6.  
  7.  
  8. %d: dovecot所支持的宏,表示域名 
  9. %n:dovecot所支持的宏,表示用戶名 
  10.  
  11. 2、修改下面的內容,並啓用相關選項: 
  12. auth default { 
  13.     mechanisms = plain 
  14.     passdb sql { 
  15.         args = /etc/dovecot-mysql.conf 
  16.     } 
  17.     userdb sql { 
  18.         args = /etc/dovecot-mysql.conf 
  19.     } 
  20.  
  21. 禁用如下選項: 
  22.     userdb passwd { 
  23.  
  24.     passwdb pam { 
  25.  
  26. 注意:禁用時,前後括弧都禁用才能禁用此選項 
  27.  
  28. 3、編輯/etc/dovecot-mysql.conf 
  29.  
  30. [root@mail postfix]# vim /etc/dovecot-mysql.conf 
  31.  
  32. driver = mysql 
  33. connect = host=/tmp/mysql.sock dbname=extmail user=extmail password=extmail 
  34. default_pass_scheme = CRYPT 
  35. password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'  
  36. user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u' 
  37.  
  38. [root@mail postfix]# service dovecot restart 
  39. Stopping Dovecot Imap:                                     [  OK  ] 
  40. Starting Dovecot Imap:                                     [  OK  ] 
  41.  
  42. 上述表示dovecot認證用戶的時候基於哪個賬號密碼去連接數據庫並且到數據庫的哪個庫中的哪張表中去查找用戶和密碼 
  43. 從而驗證賬號和密碼是否匹配 
  44.  
  45.  
  46. 說明:如果mysql服務器是本地主機,即host=localhost時,如果mysql.sock文件不是默認的/var/lib/mysql/mysql.sock 
  47. 可以使用host=“sock文件的路徑”來指定新位置;例如,使用通用二進制格式或源碼安裝的MySQL,其sock文件位置爲/tmp/mysql.sock, 
  48. 相應地,connect應按如下方式定義: 
  49.  
  50. connect = host=/tmp/mysql.sock dbname=extmail user=extmail password=extmail 
  51.  
  52. 如果使用rpm包安裝的mysql,其connect按如下方式定義: 
  53.  
  54. connect = host=localhost dbname=extmail user=extmail password=extmail 

四、安裝Extmail-1.2

  1. 1、解壓縮extmail至網頁所在目錄下,並提供配置文件 
  2.  
  3. [root@mail ~]# tar xf extmail-1.2.tar.gz  
  4. [root@mail ~]# mkdir -p /web/vhosts/extsuite 
  5. [root@mail ~]# mv extmail-1.2 /web/vhosts/extsuite/extmail 
  6. [root@mail ~]# cp /web/vhosts/ 
  7. extsuite/ www1/     www2/      
  8. [root@mail ~]# cp /web/vhosts/extsuite/extmail/webmail.cf.default /web/vhosts/extsuite/extmail/webmail.cf 
  9.  
  10.  
  11. 我們這裏的網頁路徑是/web/vhosts/ 與默認的不一致,所以修改配置文件 
  12. 2、修改主配置文件 
  13.  
  14. 把SYS_CONFIG = /var/www/extsuite/extmail/  改爲  SYS_CONFIG = /web/vhosts/extsuite/extmail/ 
  15.  
  16. 把SYS_LANGDIR = /var/www/extsuite/extmail/lang  改爲  SYS_LANGDIR = /web/vhosts/extsuite/extmail/lang 
  17.  
  18. 把SYS_TEMPLDIR = /var/www/extsuite/extmail/html  改爲  SYS_TEMPLDIR = /web/vhosts/extsuite/extmail/html 
  19.  
  20.  
  21. 部分修改選項的說明: 
  22.  
  23. SYS_MESSAGE_SIZE_LIMIT = 5242880        #用戶可以發送的最大郵件 
  24.  
  25. SYS_USER_LANG = en_US 語言選項,可改作:SYS_USER_LANG = zh_CN 
  26.  
  27. SYS_MAILDIR_BASE = /home/domains     此處即爲您在前文所設置的用戶郵件的存放目錄 
  28.  
  29. 可改作: 
  30.  
  31. SYS_MAILDIR_BASE = /var/mailbox 
  32.  
  33. SYS_MYSQL_USER = db_user 
  34. SYS_MYSQL_PASS = db_pass 
  35.  
  36. 以上兩句句用來設置連接數據庫服務器所使用用戶名、密碼和郵件服務器用到的數據庫,這裏修改爲: 
  37.  
  38. SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock     rpm包安裝的不用改了 
  39.  
  40. 由於我們這裏的源碼編譯安裝的mysql所以的改爲: 
  41.  
  42. SYS_MYSQL_SOCKET = /tmp/mysql.sock 
  43.  
  44. SYS_MYSQL_USER = extmail 
  45. SYS_MYSQL_PASS = extmail 
  46.  
  47. SYS_MYSQL_HOST = localhost        #指明數據庫服務器主機名,這裏默認即可 
  48.  
  49. SYS_MYSQL_TABLE = mailbox 
  50. SYS_MYSQL_ATTR_USERNAME = username 
  51. SYS_MYSQL_ATTR_DOMAIN = domain 
  52. SYS_MYSQL_ATTR_PASSWD = password 
  53.  
  54. 以上用來指定驗正用戶登錄裏所用到的表,以及用戶名、域名和用戶密碼分別對應的表中列的名稱;這裏默認即可 
  55.  
  56. SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket 
  57.  
  58. 此句用來指明authdaemo socket文件的位置,這裏修改爲: 
  59.  
  60. SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket 

五、配置apache

  1. 由於extmail要進行本地郵件的投遞操作,故必須將運行apache服務器用戶的身份修改爲您的郵件投遞代理的用戶 
  2. 本例中打開了apache服務器的suexec功能,故使用以下方法來實現虛擬主機運行身份的指定。此例中的MDA爲 
  3. postfix自帶,因此將指定爲postfix用戶: 
  4.  
  5. [root@mail ~]# vim /etc/httpd/httpd.conf 
  6.  
  7. 1、定位至:DocumentRoot    禁用中心主機 
  8.  
  9.  
  10. 2、在配置文件尾部添加如下內容: 
  11.  
  12. <VirtualHost *:80> 
  13.     ServerName mail.magedu.com 
  14.     DocumentRoot /web/vhosts/extsuite/extmail/html/ 
  15.     ScriptAlias /extmail/cgi /web/vhosts/extsuite/extmail/cgi 
  16.     Alias /extmail /web/vhosts/extsuite/extmail/html 
  17.     SuexecUserGroup postfix postfix   #Suexec就表示運行某些服務時,不以系統指定的身份運行,而以suexec指定的身份運行 
  18. </VirtualHost> 
  19.  
  20. 修改 cgi執行文件屬主爲apache運行身份用戶: 
  21.  
  22. [root@mail ~]# cd /web/vhosts/extsuite/extmail/ 
  23. [root@mail extmail]# ls 
  24. AUTHORS    CREDITS        dispatch_lig.sh  html     libs         README.filter    Version 
  25. cgi        dispatch.fcgi  FAQ              INSTALL  README       README.vpopmail  webmail.cf 
  26. ChangeLog  dispatch-init  globabook.cf     lang     README.fcgi  tools            webmail.cf.default 
  27.  
  28. [root@mail extmail]# chown -R postfix.postfix cgi/ /var/www/extsuite/extmail/cgi/ 
  29.  
  30. [root@mail extmail]# httpd -t        #檢查配置文件語法問題 
  31.  
  32. 注意:如果您沒有打開apache服務器的suexec功能,也可以使用以下方法解決: 
  33.  
  34. [root@mail ~]# vim /etc/httpd/httpd.conf 
  35.  
  36. 修改apache服務的運行者爲postfix 
  37. User postfix 
  38. Group postfix 
  39.  
  40. <VirtualHost *:80> 
  41.     ServerName mail.magedu.com 
  42.     DocumentRoot /web/vhosts/extsuite/extmail/html/ 
  43.     ScriptAlias /extmail/cgi /web/vhosts/extsuite/extmail/cgi      #執行cgi腳本的目錄 
  44.     Alias /extmail /web/vhosts/extsuite/extmail/html               #別名路徑 
  45. </VirtualHost> 
  46.  
  47. 3、依賴關係的解決 
  48.  
  49. extmail將會用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下載原碼包進行安裝。 
  50.  
  51. [root@mail ~]# tar xf Unix-Syslog-1.1.tar.gz  
  52. [root@mail ~]# cd Unix-Syslog-1.1 
  53. [root@mail Unix-Syslog-1.1]# perl Makefile.PL 
  54. [root@mail Unix-Syslog-1.1]# make 
  55. [root@mail Unix-Syslog-1.1]# make install 
  56.  
  57. 4、啓動apache服務 
  58. # service httpd start 

六、安裝extman-1.1

  1. 1、安裝及基本配置 
  2.  
  3. 由於前面用到了extman,已經解壓過了,所以這了我們直接使用 
  4.  
  5. [root@mail ~]# mv extman-1.1 /web/vhosts/extsuite/extman 
  6.  
  7. 提供配置文件並修改配置文件以符合本例的需要: 
  8. [root@mail ~]# cd /web/vhosts/extsuite/extman/ 
  9. [root@mail extman]# ls 
  10. addon    cgi        contrib  docs  INSTALL  libs    README.fcgi  Version 
  11. AUTHORS  ChangeLog  daemon   html  lang     README  tools        webman.cf.default 
  12. [root@mail extman]# cp webman.cf.default webman.cf 
  13. [root@mail extman]# vim webman.cf 
  14.  
  15. 2、修改主配置文件 
  16.  
  17. 我們這裏的網頁路徑是/web/vhosts/ 與默認的不一致,所以修改配置文件 
  18.  
  19. 把SYS_CONFIG = /var/www/extsuite/extmail/  改爲  SYS_CONFIG = /web/vhosts/extsuite/extman/ 
  20.  
  21. 把SYS_LANGDIR = /var/www/extsuite/extmail/lang  改爲  SYS_LANGDIR = /web/vhosts/extsuite/extman/lang 
  22.  
  23. 把SYS_TEMPLDIR = /var/www/extsuite/extmail/html  改爲  SYS_TEMPLDIR = /web/vhosts/extsuite/extman/html 
  24.  
  25.  
  26. SYS_MAILDIR_BASE = /home/domains   此處即爲您在前文所設置的用戶郵件的存放目錄,可改作: 
  27.  
  28. SYS_MAILDIR_BASE = /var/mailbox 
  29.  
  30. 修改 SYS_CAPTCHA_ON = 1     爲   SYS_CAPTCHA_ON = 0 
  31.  
  32. SYS_CAPTCHA_ON =      # 是否開啓驗證碼功能,我們這裏不開啓 
  33.  
  34.  
  35. SYS_DEFAULT_UID = 1000 
  36. SYS_DEFAULT_GID = 1000 
  37.  
  38. 此兩處後面設定的ID號需更改爲前而創建的postfix用戶和postfix組的id號,本文使用的是2525 
  39. 因此,上述兩項需要修改爲: 
  40.  
  41. SYS_DEFAULT_UID = 2525 
  42. SYS_DEFAULT_GID = 2525 
  43.  
  44.  
  45. SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock   # 這個選項如果使用rpm包安裝的mysql就不用改了 
  46.  
  47. 我們這裏是源碼編譯安裝的,改爲: 
  48.  
  49. SYS_MYSQL_SOCKET = /tmp/mysql.sock 
  50.  
  51. 3、連上mysql,創建extman用戶,並賦予extman用戶extmail庫上對錶的所有權限 
  52.  
  53. [root@mail extman]# mysql -uroot -p 
  54. Warning: mysql: ignoring option '--named-commands' due to invalid value 'root' 
  55. Enter password:  
  56. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  57. Your MySQL connection id is 28 
  58. Server version: 5.5.28-log Source distribution 
  59.  
  60. Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 
  61.  
  62. mysql> grant all privileges on extmail.* to webman@localost identified by 'webman'
  63. Query OK, 0 rows affected (0.43 sec) 
  64.  
  65. mysql> grant all privileges on extmail.* to [email protected] identified by 'webman'
  66. Query OK, 0 rows affected (0.00 sec) 
  67.  
  68. mysql> flush privileges;        #讓mysql刷新授權表,重讀授權表 
  69. Query OK, 0 rows affected (0.20 sec) 
  70.  
  71. mysql>  
  72.  
  73.  
  74. 而後修改cgi目錄的屬主和數組爲postfix: 
  75.  
  76. [root@mail extman]# pwd 
  77. /web/vhosts/extsuite/extman 
  78. [root@mail extman]# chown -R postfix.postfix /web/vhosts/extsuite/extman/cgi 
  79.  
  80.  
  81. 在apache的主配置文件中Extmail的虛擬主機部分,添加如下兩行: 
  82.  
  83. ScriptAlias /extman/cgi /web/vhosts/extsuite/extman/cgi 
  84. Alias /extman /web/vhosts/extsuite/extman/html 
  85.  
  86. 完後重啓服務,讓之生效: 
  87. [root@mail extman]# service httpd restart 
  88. Stopping httpd:                                            [  OK  ] 
  89. Starting httpd:                                            [  OK  ] 
  90.  
  91. 創建其運行時所需的臨時目錄,並修改其相應的權限: 
  92.  
  93. [root@mail extman]# mkdir -pv /tmp/extman 
  94. mkdir: created directory `/tmp/extman' 
  95. [root@mail extman]# chown -R postfix.postfix /tmp/extman 

好了,這是我們的郵件服務給予虛擬域、虛擬用戶認證過程已經完工了,下面我們來試一下吧!

 

 

點擊那個添加域,我們可以添加一個域,然後在這個域裏申請兩個用戶,就可以用這兩個用戶,互相發送和接收郵件,大家都來試一試吧!

 下面就是怎樣實現pops和imaps來實現郵件加密了,未完待續!

 

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