一、系統環境
參考:
http://ywzhou.blog.51cto.com/2785388/1578211
1、本地設置
CentOS-6.5-x86_64-bin-DVD1.iso
CentOS-6.5-x86_64-bin-DVD2.iso
主機名:mail.yourmail.com
IP地址:eth0 = 10.188.1.83
2、安裝軟件
(1)編譯環境
[root@mail ~]# yum install gcc gcc-c++
(2)依賴軟件
[root@mail ~]# yum install openssl openssl-devel cyrus-sasl libtool-ltdl libtool-ltdl-devel db4 db4-devel expect expect-devel pcre pcre-devel
(3)LAMP環境
[root@mail ~]# yum install httpd httpd-devel mysql mysql-server mysql-devel php php-mysql
3、設置防火牆
[root@mail ~]# iptables -I INPUT -p tcp -m multiport --dport 21,80 -j ACCEPT [root@mail ~]# service iptables save
二、安裝POSTFIX
Postfix是Wietse Venema在IBM的GPL協議之下開發的MTA(郵件傳輸代理)軟件,用於取代sendmail;它比sendmail更快、更健壯、更靈活、更安全、兼容性更好。
1、安裝
[root@mail ~]# rpm -aq|grep postfix postfix-2.6.6-2.2.el6_1.x86_64 #CentOS6.5已默認安裝了2.6.6版本,再升級一下: [root@mail ~]# yum update postfix postfix-2.6.6-6.el6_5.x86_64
CentOS 7已經內置2.10.1版本了,暫時沒有去研究有何改進,將來會發布7下的搭建。
2、配置
[root@mail ~]# cd /etc/postfix [root@mail postfix]# postconf -n > /etc/postfix/main2.cf [root@mail postfix]# mv main.cf main.cf.old [root@mail postfix]# mv main2.cf main.cf [root@mail postfix]# vi main.cf # 註釋掉下面這行,否則25端口只能本地連接 # inet_interfaces = localhost # 添加以下基本配置 # 主機設置 mynetworks = 127.0.0.1 myhostname = mail.yourmail.com mydestination = $myhostname, localhost.$mydomain, localhost # 顯示連接信息 mail_name = Postfix - by yourmail.com smtpd_banner = $myhostname ESMTP $mail_name # 立即響應 smtpd_error_sleep_time = 0s # 郵件大小和郵箱大小限制10M、2G message_size_limit = 10485760 mailbox_size_limit = 2097152000 show_user_unknown_table_name = no # 隊列超時限制 1天 bounce_queue_lifetime = 1d maximal_queue_lifetime = 1d
3、啓動
[root@mail postfix]# service postfix start [root@mail postfix]# chkconfig postfix on [root@mail postfix]# ps aux|grep postfix root 3070 0.0 0.3 81292 3436 ? Ss 13:59 0:00 /usr/libexec/postfix/master postfix 3072 0.0 0.3 81372 3392 ? S 13:59 0:00 pickup -l -t fifo -u postfix 3073 0.0 0.3 81440 3440 ? S 13:59 0:00 qmgr -l -t fifo -u root 3124 0.0 0.0 103248 880 pts/1 S+ 14:02 0:00 grep postfix [root@mail postfix]# netstat -tlnp|grep 25 tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3070/master tcp 0 0 ::1:25 :::* LISTEN 3070/master
4、檢查
[root@mail postfix]# postfix check #沒有錯誤返回表示配置正確 [root@mail postfix]# postconf -a #出現cyrus表示可以支持cyrus認證用戶 [root@mail postfix]# postconf -m #出現mysql表示可以支持mysql存儲賬號
5、設置防火牆
[root@mail ~]# iptables -I INPUT -p tcp --dport 25 -j ACCEPT [root@mail ~]# service iptables save
三、安裝Courier-Authlib
Courier-Authlib是一個數據認證庫,負責courier-imap,maildrop的認證
官方網站:http://www.courier-mta.org
1、安裝
http://www.courier-mta.org/download.html#authlib
下載頁面中需要用到以下幾個包:
courier-authlib-0.66.1.tar.bz2 courier-unicode-1.1.tar.bz2 courier-imap-4.15.1.tar.bz2 maildrop-2.7.2.tar.bz2
我已上傳到下載中心,免費下載:
http://down.51cto.com/data/1955875
安裝courier-authlib:
#先查看下uid 1000是否已使用 [root@mail ~]# cat /etc/passwd #安裝系統時創建了一個用戶,佔用了1000,因此使用1002 [root@mail ~]# groupadd vmail -g 1002 [root@mail ~]# useradd vmail -u 1002 -g 1002 -d /home/domains [root@mail ~]# cd /usr/local/src [root@mail src]# wget http://cznic.dl.sourceforge.net/project/courier/authlib/0.66.1/courier-authlib-0.66.1.tar.bz2 [root@mail src]# tar -jxf courier-authlib-0.66.1.tar.bz2 [root@mail src]# cd courier-authlib-0.66.1 [root@mail courier-authlib-0.66.1]# ./configure --with-mysql-libs --with-mysql-includes --with-authmysql --with-authmysql=yes --with-mailuser=vmail --with-mailgroup=vmail [root@mail courier-authlib-0.66.1]# make [root@mail courier-authlib-0.66.1]# make install [root@mail courier-authlib-0.66.1]# make install-configure
說明:編譯時可能出現報錯,基本是因爲某些包沒有安裝,YUM裝上後重新編譯;因此建議先按上文“系統環境”安裝好依賴軟件。
mysql參數也可以指定絕對路徑:
--with-mysql-libs=/usr/local/mysql/lib/mysql\
--with-mysql-includes=/usr/local/mysql/include/mysql/ \
2、配置
[root@mail courier-authlib-0.66.1]# cd /usr/local/etc/authlib [root@mail authlib]# vi authmysqlrc MYSQL_SERVER localhost MYSQL_USERNAME extmail MYSQL_PASSWORD extmail MYSQL_SOCKET /var/lib/mysql/mysql.sock MYSQL_PORT 3306 MYSQL_OPT 0 MYSQL_DATABASE extmail MYSQL_USER_TABLE mailbox MYSQL_CRYPT_PWFIELD password MYSQL_UID_FIELD 1002 MYSQL_GID_FIELD 1002 MYSQL_LOGIN_FIELD username MYSQL_HOME_FIELD homedir MYSQL_NAME_FIELD name MYSQL_MAILDIR_FIELD maildir MYSQL_QUOTA_FIELD quota MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,\ CONCAT('/home/domains/',homedir), \ CONCAT('/home/domains/',maildir), \ quota, \ name \ FROM mailbox \ WHERE username = '$(local_part)@$(domain)' [root@mail authlib]# vi authdaemonrc authmodulelist="authmysql" authmodulelistorig="authmysql" [root@mail authlib]# ln -s /usr/local/etc/authlib /etc/authlib
3、啓動
[root@mail authlib]# /usr/local/sbin/authdaemond start [root@mail authlib]# ps aux|grep authdaemond root 9954 0.0 0.0 4308 440 ? S 15:31 0:00 /usr/local/sbin/courierlogger -pid=/usr/local/var/spool/authdaemon/pid -start /usr/local/libexec/courier-authlib/authdaemond root 9955 0.0 0.2 66500 2720 ? S 15:31 0:00 /usr/local/libexec/courier-authlib/authdaemond root 9956 0.0 0.0 66500 748 ? S 15:31 0:00 /usr/local/libexec/courier-authlib/authdaemond root 9957 0.0 0.0 66500 748 ? S 15:31 0:00 /usr/local/libexec/courier-authlib/authdaemond root 9958 0.0 0.0 66500 748 ? S 15:31 0:00 /usr/local/libexec/courier-authlib/authdaemond root 9959 0.0 0.0 66500 748 ? S 15:31 0:00 /usr/local/libexec/courier-authlib/authdaemond root 9960 0.0 0.0 66500 748 ? S 15:31 0:00 /usr/local/libexec/courier-authlib/authdaemond root 10024 0.0 0.0 112656 980 pts/1 S+ 15:31 0:00 grep --color=auto authdaemond [root@mail authlib]# echo "/usr/local/sbin/authdaemond start" >> /etc/rc.d/rc.local
四、安裝Maildrop
Maildrop是本地郵件投遞代理(MDA), 支持過濾(/etc/maildroprc)、投遞和磁盤限額(Quota)功能。
Maildrop以RPM包安裝會自動創建vuser用戶及vgroup用戶組,專門用於郵件的存儲;使用源碼安裝則需要手動創建用戶和用戶組,且ID大於1000,即上文創建的用戶vmail(1002)和組vmail(1002),並且家目錄/home/domain就是郵件存儲目錄,下節安裝webmail會講。
1、安裝Courier-Unicode
字符集庫文件,相當於RPM方式安裝的courier-authlib-devel包,不安裝這個會導致編譯maildrop時報錯:
configure: error: The Courier Unicode Library appears not to be installed. You may need to install a separate development subpackage, in addition to the main package
[root@mail ~]# cd /usr/local/src [root@mail src]# wget http://jaist.dl.sourceforge.net/project/courier/courier-unicode/1.1/courier-unicode-1.1.tar.bz2 [root@mail src]# tar -jxf courier-unicode-1.1.tar.bz2 [root@mail src]# cd courier-unicode-1.1 [root@mail courier-unicode-1.1]# ./configure [root@mail courier-unicode-1.1]# make && make install
2、安裝Maildrop
[root@mail ~]# cd /usr/local/src [root@mail src]# wget http://jaist.dl.sourceforge.net/project/courier/maildrop/2.7.2/maildrop-2.7.2.tar.bz2 [root@mail src]# tar -jxf maildrop-2.7.2.tar.bz2 [root@mail src]# cd maildrop-2.7.2 [root@mail maildrop-2.7.2]# ./configure --enable-maildirquota --enable-maildrop-uid=1002 --enable-maildrop-gid=1002 --with-trashquota [root@mail maildrop-2.7.2]# make [root@mail maildrop-2.7.2]# make install
3、配置
[root@mail maildrop-2.7.2]# vi /etc/postfix/master.cf maildrop unix - n n - - pipe flags=DRhu user=vmail argv=/usr/local/bin/maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}
[root@mail maildrop-2.7.2]# vi /etc/postfix/main.cf #控制maildrop一次只處理一封郵件 maildrop_destination_recipient_limit = 1
說明:用戶vmail和組vmail將慣穿整個郵件系統,一定要記住它們的名稱vmail和ID號1002,如果不和本文設置的一樣,請在編譯和配置時修改成你自己的。
結論:郵件系統的基本架構搭建好了,後臺有了MTA和MDA,下一節將搭建前臺Webmail。