天天看點

基于虛拟賬号的郵件系統

按照如下圖是以建立基于虛拟賬号的郵件系統:

如上圖所示:用戶端登入郵件系統需要經過cyrus-sasl函數庫賬号的認證,但是cyrus-sasl無法調用mysql,是以必須安裝courier-authlib來調用mysql。

發送郵件時使用dovecot來進行接收。extmail為使用者提供web界面的方式來進行郵件的接收或發送。extman是為管理者提供管理的web界面。

postfix預設無法支援mysql資料庫,是以在此必須使用源碼按安裝postfix

修改主機名:

[root@lyt ~]# vim /etc/sysconfig/network

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631984tFsD.png"></a>

[root@lyt ~]# vim /etc/hosts

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631985aJCH.png"></a>

[root@lyt named]# init 6      #重新開機,使建立立的主機名生效

[root@lyt ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo      #編輯本地yum

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631986mqz6.png"></a>

搭建dns伺服器:

[root@lyt ~]# mkdir /mnt/cdrom

[root@lyt ~]# mount /dev/cdrom /mnt/cdrom/

[root@lyt ~]# cd /mnt/cdrom/Server/

[root@lyt Server]# yum install bind -y

[root@lyt Server]# yum install bind-chroot -y

[root@lyt Server]# yum install caching -y

[root@lyt Server]# yum install caching-nameserver -y

[root@lyt Server]# cd /var/named/chroot/etc/

[root@lyt etc]# cp -p named.caching-nameserver.conf named.conf

[root@lyt etc]# vim named.conf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476319916aK6.png"></a>

[root@lyt etc]# vim named.rfc1912.zones

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476319976X0Z.png"></a>

[root@lyt etc]# cd ../var/named/

[root@lyt named]# cp -p localhost.zone a.com.db

[root@lyt named]# vim a.com.db

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631998990r.png"></a>

[root@lyt named]# vim /etc/resolv.conf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347631999JxxS.png"></a>

[root@lyt named]# service named start

[root@mail ~]# chkconfig named on

[root@mail ~]# service sendmail stop       #使用postfix接收郵件,是以此處關閉sendmail

[root@mail ~]# chkconfig sendmail off       #設定開機關閉該伺服器

[root@mail ~]# yum install httpd  php  php-mysql  mysql  mysql-server  mysql-devel  openssl-devel  dovecot  perl-DBD-MySQL  tcl  tcl-devel  libart_lgpl       #使用yum安裝這些軟體包

libart_lgpl-devel libtool-ltdl  libtool-ltdl-devel  expect      #使用yum安裝響應的rpm軟體包

[root@mail Server]# yum grouplist      #檢視安裝以下開發所用到的rpm包組

[root@mail Server]# service mysqld start      #啟動mysql服務

[root@mail Server]# chkconfig mysqld on        #開機自動啟動mysql

[root@mail Server]# mysql      #進入mysql

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632006sYcj.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476320105uIZ.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476320122OM2.png"></a>

搭建postfix:

[root@mail ~]# groupadd -g 2525 postfix       #建立組postfix,組的id号2525

[root@mail ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix       #建立使用者postfix,-u表示使用者,id号為2525,-M表示不為該使用者建立家目錄;并将該使用者postfix加入到組postfix中。-s  /sbin/nologin表示不可登入

[root@mail ~]# groupadd -g 2526 postdrop    #建立組postdrop,組的id号為2526

[root@mail ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop      #建立使用者postdrop,-u表示使用者,id号為2526,-M表示不為該使用者建立家目錄;并将該使用者postdrop加入到組postdrop中。使用/bin/false表示不能登入,-s表示shell。

[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/        #拆包

[root@mail ~]# cd /usr/local/src/

[root@mail src]# cd postfix-2.8.2/

[root@mail postfix-2.8.2]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2   -lssl –lcrypto'      #CCARGS表示gcc的一些變量,-DHAS_MYSQL表示調用mysql       -I/usr/include/mysql 由于mysql是用rpm包裝的,是标準路徑下的頭檔案,-DUSE_SASL_AUTH表示要結合sasl驗證,-DUSE_CYRUS_SASL表示結合sasl 驗證,-I/usr/include/sasl 表示sasl的頭檔案,-DUSE_TLS表示使用tls安全傳輸層協定,AUXLIBS=-L/usr/lib/mysql表示輔助庫檔案,也即mysql的庫檔案,(在源碼安裝中,拆包後生成的檔案中都含有./configure檔案,此檔案中沒有./configure檔案,則使用此方法代替./configure檔案)

[root@mail postfix-2.8.2]# make     #編譯

[root@mail postfix-2.8.2]# make   install     #安裝。按照以下的提示輸入相關的路徑([]号中的是預設值,”]”後的是輸入值,省略的表示采用預設值))

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476320141WjL.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476320166KJx.png"></a>

[root@mail postfix-2.8.2]# newaliases     #生成别名二進制檔案,這個步驟如果忽略,會造成postfix效率極低:

[root@mail postfix-2.8.2]# postfix start     #啟動postfix

[root@mail postfix-2.8.2]# netstat -tupln |less    

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632019Qkjf.png"></a>

[root@mail postfix-2.8.2]# postconf -m      #檢視postfix可以調用的子產品,-m表示子產品

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632021Evtz.png"></a>

[root@mail postfix-2.8.2]# postconf –a       #檢視使用以下指令驗正postfix是否支援cyrus風格的sasl認證

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632025uTYy.png"></a>

啟用postfix可以使用指令postfix  start ,如果想要用service postfix start,可以作如下修改: 

[root@mail postfix-2.8.2]# mkdir /tmp/abc

[root@mail postfix-2.8.2]# cd /tmp/abc/

[root@mail abc]# cp /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./     #拷貝rpm包

[root@mail abc]# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio –id        #使用rpm2cpio将postfix拆包

[root@mail abc]# cd etc/rc.d/init.d/

[root@mail init.d]# cp postfix /etc/init.d/     #将該postfix檔案拷貝到開機腳本中(開機腳本有/etc/init.d或者/etc/rc.d/init.d)

[root@mail init.d]# service postfix restart      #已經可以使用此指令

[root@mail init.d]# chkconfig --add postfix      #将postfix加入到chkconfig中,可以使用chkconfig管理postfix的程序

[root@mail init.d]# chkconfig postfix on      #将postfix設定為開機自動啟動

[root@mail init.d]# useradd user1    #建立user1

[root@mail init.d]# passwd user1     #為user1建立密碼

[root@mail init.d]# telnet 127.0.0.1 25     #使用telnet登入本地郵件伺服器

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632026SN5R.png"></a>

[root@mail init.d]# vim /etc/postfix/main.cf      #編輯postfix的主配置檔案

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632031JTXr.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632034rz0K.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632035xbg5.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632038f8r2.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632041e825.png"></a>

[root@mail init.d]# postfix check       #檢測postfix的配置檔案的文法

[root@mail init.d]# service postfix restart     #重新開機該服務

[root@mail init.d]# vim /etc/postfix/main.cf          #添加以下内容

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632045QTKq.png"></a>

[root@mail init.d]# cd /usr/lib/sasl2/

[root@mail sasl2]# cp -p Sendmail.conf smtpd.conf

[root@mail sasl2]# vim smtpd.conf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632047q83a.png"></a>

[root@mail sasl2]# service saslauthd start       #啟用sasl驗證服務

[root@mail sasl2]# chkconfig saslauthd on      #開機自動啟動

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632048vFm8.png"></a>

安裝Courier authentication library

[root@mail ~]# tar -jxvf courier-authlib-0.63.1.20111230.tar.bz2 -C /usr/local/src/

[root@mail src]# cd courier-authlib-0.63.1.20111230/

[root@mail courier-authlib-0.63.1.20111230]# ./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include       #--prefix表示安裝路徑、sysconfdir表示配置檔案路徑、--with-authmysql表示要驗證賬号調用mysql資料庫、--with-mysql-libs表示mysql的庫檔案、--with-mysql-include表示頭檔案、--with-redhat表示紅帽

[root@mail courier-authlib-0.63.1.20111230]# make

[root@mail courier-authlib-0.63.1.20111230]# make install

[root@mail courier-authlib-0.63.1.20111230]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/      #更改該檔案權限

[root@mail courier-authlib-0.63.1.20111230]# cp /etc/authdaemonrc.dist  /etc/authdaemonrc

[root@mail courier-authlib-0.63.1.20111230]# cp /etc/authmysqlrc.dist  /etc/authmysqlrc

[root@mail courier-authlib-0.63.1.20111230]# vim /etc/authdaemonrc

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632050uPYO.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632052b5LW.png"></a>

[root@mail courier-authlib-0.63.1.20111230]# vim /etc/authmysqlrc     #編輯/etc/authmysqlrc 為以下内容,其中2525,2525 為postfix 使用者的UID和GID。

MYSQL_SERVER localhost 

MYSQL_PORT 3306                   (指定你的mysql監聽的端口,這裡使用預設的3306) 

MYSQL_USERNAME  extmail      (這時為後文要用的資料庫的所有者的使用者名) 

MYSQL_PASSWORD extmail        (密碼) 

MYSQL_SOCKET  /var/lib/mysql/mysql.sock 

MYSQL_DATABASE  extmail 

MYSQL_USER_TABLE  mailbox   (mysql使用者表格mailbox) 

MYSQL_CRYPT_PWFIELD  password   

MYSQL_UID_FIELD  '2525'      (虛拟賬号映射的真實賬号) 

MYSQL_GID_FIELD  '2525' 

MYSQL_LOGIN_FIELD  username 

MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)    (虛拟使用者的主目錄) 

MYSQL_NAME_FIELD  name 

MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)    (虛拟使用者的郵箱)

[root@mail courier-authlib-0.63.1.20111230]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib      #将該檔案拷貝到開機腳本中,以便使用service進行控制

[root@mail courier-authlib-0.63.1.20111230]# chmod 755 /etc/init.d/courier-authlib     #為該腳本賦予可執行權限

[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib restart     #此時已經可以使用service控制該服務

[root@mail courier-authlib-0.63.1.20111230]# chkconfig --add courier-authlib    #将該服務加入到chkconfig中,以便使用chkconfig進行控制

[root@mail courier-authlib-0.63.1.20111230]# chkconfig courier-authlib on     #設定開機自動啟動

[root@mail courier-authlib-0.63.1.20111230]# chkconfig --list |grep authlib        #使用--list檢視authlib服務已經在那些級别中啟

[root@mail courier-authlib-0.63.1.20111230]# echo "/usr/local/courier-authlib/lib/courier-authlib" &amp;gt;&amp;gt; /etc/ld.so.conf.d/courier-authlib.conf       #由于courier-authlib是源碼安裝,其庫檔案不是标準路徑,系統無法調用,是以将庫檔案/usr/local/courier-authlib重定向到标準路徑/etc/ld.so.conf.d/中,并建立立一個檔案名叫做courier-authlib.conf。

[root@mail courier-authlib-0.63.1.20111230]# ldconfig –v     #重新加載庫檔案調用

[root@mail courier-authlib-0.63.1.20111230]# ldconfig -pv |grep authlib       #檢視對庫檔案authlib的調用能否成功

[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib restart     #重新開機一下該服務

[root@mail courier-authlib-0.63.1.20111230]# mkdir -pv /var/mailbox      #建立虛拟使用者郵箱所在的目錄

[root@mail courier-authlib-0.63.1.20111230]# chown  -R postfix /var/mailbox      #将其權限賦予postfix使用者

[root@mail courier-authlib-0.63.1.20111230]# vim /usr/lib/sasl2/smtpd.conf       #編輯該檔案保證有一下行:

pwcheck_method: authdaemond 

mech_list:PLAIN LOGIN 

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

[root@mail courier-authlib-0.63.1.20111230]# service saslauthd restart       #重新開機

[root@mail courier-authlib-0.63.1.20111230]# service courier-authlib restart      #重新開機

讓postfix支援虛拟域和虛拟使用者

[root@mail courier-authlib-0.63.1.20111230]# vim /etc/postfix/main.cf        #編輯該檔案,保證有以下行:

安裝extmail(通路)和extman(管理)

[root@mail courier-authlib-0.63.1.20111230]# cd

[root@mail ~]# tar -zxvf  extman-1.1.tar.gz        #隻需拆包即可,他是一個導入檔案

[root@mail ~]# cd extman-1.1

[root@mail extman-1.1]# cd docs/

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632053yu0v.png"></a>

[root@mail docs]# mysql -u root –p      #登入mysql資料庫

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632055Lkp5.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632056Uxi3.png"></a>

[root@mail docs]#  cp mysql*  /etc/postfix/         #将mysql_virtual檔案拷貝到/etc/postfix中

[root@mail docs]# mysql -u root –p       #登入資料庫,授予使用者extmail通路extmail資料庫的權限

mysql&amp;gt; GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail'; 

mysql&amp;gt; GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail'; 

mysql&amp;gt;FLUSH PRIVILEGES;   讓設定的内容生效 

mysql&amp;gt; quit;

[root@mail docs]# service postfix restart      #重新開機postfix服務

搭建dovecot

[root@mail docs]# vim /etc/dovecot.conf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632061ZYf6.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632067He2U.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632068ylw5.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632070aFvu.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632071BkeQ.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476320724XrK.png"></a>

[root@mail docs]# vim /etc/dovecot-mysql.conf       #編輯該檔案,保證有以下行

driver = mysql 

connect = host=localhost dbname=extmail user=extmail password=extmail 

default_pass_scheme = CRYPT 

password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'                            

user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'

[root@mail docs]# vim /etc/postfix/main.cf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632074aMG5.png"></a>

[root@mail docs]# service postfix restart

[root@mail docs]# service dovecot start

[root@mail docs]# chkconfig dovecot on     #設定開機自動啟動

安裝Extmail-1.2 

[root@mail ~]# tar -zxvf extmail-1.2

[root@mail ~]# mkdir -pv /var/www/extsuite     #該目錄是extmail的固定目錄

[root@mail ~]# mv extmail-1.2 /var/www/extsuite/extmail       #移動并改名

[root@mail ~]# mv extman-1.1 /var/www/extsuite/extman

[root@mail ~]# cd /var/www/extsuite/

[root@mail extsuite]# cd extmail/

[root@mail extmail]# cp webmail.cf.default webmail.cf

[root@mail extmail]# vim webmail.cf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632075q1d2.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_134763207600QW.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632077uVMw.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632079Ulcg.png"></a>

apache相關配置

[root@mail extmail]# service httpd start

[root@mail extmail]# chkconfig httpd on

[root@mail extmail]# vim /etc/httpd/conf/httpd.conf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632083RDSA.png"></a>

[root@mail extmail]# chown -R postfix.postfix   /var/www/extsuite/extmail/cgi/    #修改extmail下cgi目錄的使用者群組

安裝Extman-1.1

[root@mail extmail]# cd /var/www/extsuite/

[root@mail extsuite]# cd extman/

[root@mail extman]# cp  webman.cf.default webman.cf       #拷貝該模闆檔案并改名

[root@mail extman]# vim webman.cf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632084uGxy.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632085zgVH.png"></a>

[root@mail extman]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/     #修改extman目錄下cgi目錄的使用者群組

[root@mail extman]# vim /etc/httpd/conf/httpd.conf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632089mRIA.png"></a>

[root@mail extman]# mkdir  -pv  /tmp/extman      #建立extman運作時所需的臨時目錄

[root@mail extman]# chown postfix.postfix  /tmp/extman      #修改其使用者群組權限

[root@mail extman]# cd

依賴關系的解決

[root@mail ~]# tar  -zxvf Unix-Syslog-1.1.tar.gz

[root@mail ~]# cd Unix-Syslog-1.1

[root@mail Unix-Syslog-1.1]# perl Makefile.PL

[root@mail Unix-Syslog-1.1]#  make

[root@mail Unix-Syslog-1.1]#  make install

[root@mail Unix-Syslog-1.1]# service httpd restart

測試:

此時郵件還不能發送,作如下修改即可:

[root@mail Unix-Syslog-1.1]# vim /etc/postfix/main.cf

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632092BmCF.png"></a>

[root@mail Unix-Syslog-1.1]# service postfix restart

首先要進入背景管理:

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632093pio5.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632097ZqkI.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476321002hGg.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632101FhcM.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632102kTvJ.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476321034kXx.png"></a>

注冊域:

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632104CPr1.png"></a>

注冊使用者test1:

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632105Sezc.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632106xetX.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632107VKff.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632108UPIw.png"></a>

注冊使用者test2與test1方法一樣,這裡不再贅述

test2向test1發送郵件:

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632111eAoF.png"></a>

test1向test2發送郵件:

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_1347632113g62v.png"></a>

<a href="http://5493845.blog.51cto.com/attachment/201209/14/5493845_13476321153sU4.png"></a>

本文轉自 liuyatao666 51CTO部落格,原文連結:http://blog.51cto.com/5503845/991092,如需轉載請自行聯系原作者

繼續閱讀