系統:ubuntu-10.04.3-server-amd64php
安裝LAMP環境html
sudo apt-get install apache2node
sudo apt-get install mysql-server-5.0 mysql-client-5.0mysql
sudo apt-get install php5 libapache2-mod-php5linux
sudo /etc/init.d/apache2 restartc++
接下來修改apache2的配置文件。git
sudo vim /etc/apache2/apache2.confweb
把下面的代碼所有考到文件的最後。sql
AddType application/x-httpd-php .php .htm .html AddDefaultCharset UTF-8 ServerName 127.0.0.1 <IfModule dir_module> DirectoryIndex index.htm index.html index.php </IfModule>
從新啓動數據庫
/etc/init.d/apache2 restart
/etc/init.d/mysql restart
apt-get install liblzo2-2
apt-get install libstdc++6-4.4-dev
apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-fastcgi libfcgi-perl libapache2-mod-php5 php5 php5-mysql build-essential libtool libnet-server-perl libnet-cidr-perl libberkeleydb-perl arc zoo lzop libgd-gd2-perl libfile-tail-perl libdigest-sha1-perl libdigest-HMAC-perl libnet-ip-perl libnet-dns-perl libhtml-tagset-perl libhtml-parser-perl libio-stringy-perl libio-multiplex-perl libio-socket-ssl-perl libio-zlib-perl libnet-ssleay-perl libunix-syslog-perl libtimedate-perl libmailtools-perl libconvert-binhex-perl libconvert-tnef-perl libconvert-uulib-perl libcompress-zlib-perl libarchive-zip-perl perl-suid apache2-suexec
你會被詢問如下問題:
Create directories for web-based administration? <-- No
General type of mail configuration: <-- Internet Site
System mail name: <-- mail.extmail.org(直接改爲要用的域名:mail.object.com 待測試)
a2enmod suexec //打開apache2 suexec支持
a2enmod fastcgi //打開apache2 fastcgi支持
sudo /etc/init.d/apache2 restart
Extmail 是一個以perl語言編寫,面向大容量/ISP級應用,免費的高性能Webmail軟件,主要包括ExtMail、 Extman兩個部分的程序套件。ExtMail套件用於提供從瀏覽器中登陸、使用郵件系統的Web操做界面,而Extman套件用於提供從瀏覽器中管理郵件系統的Web操做界面。
下載extmail,並修改配置
我用的是ExtMail 1.1.0.tar.gz和ExtMan 1.0.0.tar.gz
tar zxvf extmail-1.1.0.tar.gz
tar zxvf extman-1.0.0.tar.gz
mkdir /var/www/extsuite
mv extmail-1.1.0 /var/www/extsuite/extmail
mv extman-1.0.0 /var/www/extsuite/extman
cp /var/www/extsuite/extman/docs/mysql_virtual_*.cf /etc/postfix/
注意:修改/etc/postfix/mysql_virtual_*.cf,將其中的「localhost」均改成「127.0.0.1」
(:g/a/s//b/g將文中全部a均用b替換(或者:%s/a/b/g)
Sudo sed –i ‘/localhost/s/localhost/127.0.0.1/’ file*)
chmod o= /etc/postfix/mysql_virtual_*.cf
chgrp postfix /etc/postfix/mysql_virtual_*.cf
注:若是打算使用默認用戶vuser:vgroup,那麼需建立此用戶,且uid:gid爲1001:1001.而本文爲了之後方便,使用的是手動建立的用戶vmail,因此需修改下邊這些文件中的相關參數.
新建一個用戶vmail組爲vmail uid和gid爲1001,不允放登陸。用戶下用來存放全部的用戶的郵件
groupadd -g 1001 vmail
useradd -m -g vmail -u 1001 -d /home/vmail -s /bin/bash vmail
id vmail
注:若是打算使用默認用戶vu修改uid和gid 因爲程序中默認使用的爲vuser:vgroup,其uid:gid爲1001:1001。而當前採用了一個新建用戶vmail,因此需修改程序中的全部相關參數,具體操做以下:
chown -R vmail:vmail /var/www/extsuite/extmail/cgi/
chown -R vmail:vmail /var/www/extsuite/extman/cgi/
cd /var/www/extsuite/extmail/
cp webmail.cf.default webmail.cf
修改/var/www/extsuite/extmail/webmail.cf裏的其餘參數,主要變更的內容見下:
gedit webmail.cf
SYS_USER_LANG = zh_CN SYS_USER_CHARSET = gb2312 SYS_MYSQL_USER = root SYS_MYSQL_PASS = 123 SYS_MYSQL_DB = extmail SYS_MYSQL_HOST = 127.0.0.1 SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock SYS_AUTHLIB_SOCKET = /var/run/courier/authdaemon/socket SYS_G_ABOOK_FILE_CHARSET = gb2312 SYS_MAILDIR_BASE = /home/vmail SYS_MESSAGE_SIZE_LIMIT = 102400000 //注:這個選項爲修改附件的大小,默認爲5M,你能夠自行修改,這裏面改了是不行的,還要去postfix裏面修改,我在下面會講到。
vi ../extman/webman.cf
cp webman.cf.default webman.cf
vi webman.cf
SYS_CAPTCHA_ON = 0 //用於關閉後臺登陸時的驗證碼 SYS_MAILDIR_BASE = /home/vmail SYS_DEFAULT_UID = 1001 SYS_DEFAULT_GID = 1001 SYS_MYSQL_USER = root SYS_MYSQL_PASS = 123 SYS_MYSQL_DB = extmail SYS_MYSQL_HOST = 127.0.0.1 SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock SYS_LANG = zh_CN SYS_GROUPMAIL_SENDER = postmaster@extmail.org //注: 這個選項是,你在後臺羣發後,用戶收到郵件的發件人地址,你能夠自行修改。
Cd ..
Cd extmail
gedit dispatch-init
SU_UID=vmail
SU_GID=vmail
gedit dispatch_lig.sh
BASE=/var/www/extsuite/extmail
$BASE/tools/suid-with -u vmail -g vmail /usr/bin/perl $BASE/dispatch.fcgi
:q
cd ../extman/
gedit tools/setid.pl
set_gid('vmail');
set_uid('vmail');
gedit tools/adminctl.pl
--setgid=vmail
--setuid=vmail
gedit tools/userctl.pl
--setgid=vmail
--setuid=vmail
gedit tools/aliasctl.pl
--setgid=vmail
--setuid=vmail
gedit tools/domainctl.pl
--setgid=vmail
--setuid=vmail
注:這上面實際上都是把vuser改爲vmail,vgroup改爲vmail.
gedit contrib/passwd2ext.pl
my $sock = '/var/run/mysqld/mysqld.sock';
my $uid = '1001';
my $gid = '1001';
gedit libs/Ext/Mgr/LDAP.pm
uidNumber => $opt{uidnumber} || '1001', //349行
gidNumber => $opt{gidnumber} || '1001', //350行
︰
uidNumber => $opt{uidnumber} || '1001', //541行
gidNumber => $opt{gidnumber} || '1001', //542行
gedit docs/init.ldif
uidNumber: 1001
gidNumber: 1001
gedit /var/www/extsuite/extman/docs/init.sql
修改18行中的uid和gid
INSERT INTO `mailbox` VALUES ('postmaster@extmail.org','postmaster','$1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0','','PostMaster','','extmail.org/postmaster/Maildir/','extmail.org/postmaster','104857600S','52428800S','extmail.org',1001,1001,'2007-02-14 15:10:04','2010-11-08',1,0,0,0,0,0,0,0,'my question', 'my answer');
gedit /var/www/extsuite/extman/docs/extmail.sql
修改uid和gid
CREATE TABLE mailbox (
︰
︰
129行 uidnumber int(6) NOT NULL default '1001',
130行 gidnumber int(6) NOT NULL default '1001',
︰)
到此,vmail用戶組修改完畢。
數據庫初始化
執行如下命令導入mysql數據庫結構及初始化數據,注意必須逐行輸入如下命令.
mysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql
mysql -u root -p < /var/www/extsuite/extman/docs/init.sql
連接基本庫到Extmail
創建臨時文件夾:
mkdir /tmp/extman
chown -R vmail:vmail /tmp/extman
gedit /etc/rc.local
編輯rc.local,加入下面內容以實現開機自動創建編輯rc.local,加入下面內容以實現開機自動創建
if [ ! -d /tmp/extman ]; then
mkdir /tmp/extman
chown -R vmail:vmail /tmp/extman
fi
注:linux系統有個tmpwatch工具,該工具會按期掃描/tmp/下的文件,若是這些文件好久都沒被使用,將被刪除,所以若是後臺長期不使用, /tmp/extman目錄有可能被tmpwatch刪除,因此要麼按期登錄後臺,要麼修改 webman.cf將臨時目錄修改到另外一個地方。此處暫以/tmp/extman默認值爲例。
(若是/tmp下沒有extman目錄,後臺登錄不了,會報錯)
創建上邊導入mysql的postmaster@extmail.org賬戶的Maildir,請輸入以下命令:
cd /var/www/extsuite/extman/tools
./maildirmake.pl /home/vmail/extmail.org/postmaster/Maildir
chown -R vmail:vmail /home/vmail/extmail.org/
Postfix配置
修改/etc/postfix/mysql_virtual_*.cf,將其中的localhost均改成127.0.0.1
cd /etc/postfix/
cp main.cf main.cf_backup
gedit main.cf
刪除全部,添加下列文件
# TLS parameters smtpd_tls_cert_file = /etc/postfix/smtpd.cert smtpd_tls_key_file = /etc/postfix/smtpd.key smtpd_use_tls = yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. mydomain = extmail.org myhostname = mail.$mydomain myorigin = $mydomain mydestination = mail.$mydomain, localhost.$mydomain, localhost alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases relayhost = mynetworks = 127.0.0.1 message_size_limit = 102400000 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all html_directory = /usr/share/doc/postfix/html ######### virtual config############ virtual_alias_domains = virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf virtual_mailbox_base = /home/vmail virtual_uid_maps = static:1001 virtual_gid_maps = static:1001 virtual_create_maildirsize = yes virtual_mailbox_extended = yes virtual_overquota_bounce = yes virtual_mailbox_limit_override = yes virtual_maildir_limit_message = Sorry, the your Maildir has overdrawn your diskspace quota, please free up some of spaces of your mailbox try again. proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps
把上面的都複製到你的main.cf文件中,各位能夠按本身的要求自行配置
代碼:
cd /etc/postfix
openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509
它們詢問你問題
Country Name (2 letter code) [AU]: //國家
State or Province Name (full name) [Some-State]: //省
Locality Name (eg, city) []: //城市
Organization Name (eg, company) [Internet Widgits Pty Ltd]: //組織名稱
Organizational Unit Name (eg, section) []: 組織單位名稱
Common Name (eg, YOUR name) []: 通用名稱
Email Address []: 郵件地址
更改smtpd.key權限
chmod o= /etc/postfix/smtpd.key
/etc/init.d/postfix restart
接下來是Apache2配置:
咱們能夠新建一個站點,若是你的服務器,只是作郵件服務器,你能夠直接修改默認的配置文件,不過修改前,仍是要備份一下。
我到sites-available下新建了一個extmail的文件件,裏面的代碼是這樣(參考)
<VirtualHost *:80> ServerAdmin wqk@test.com ServerName mail.test.com DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/ Alias /extmail /var/www/extsuite/extmail/html/ ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/ Alias /extman/ /var/www/extsuite/extman/html/ Alias /phpmyadmin /var/www/extsuite/phpmyadmin/ ErrorLog /var/log/apache2/extmail-error.log CustomLog /var/log/apache2/extmail-access.log combined </VirtualHost>
接下來咱們加載站點
a2ensite extmail
/etc/init.d/apache2 restart
你還要修改apache2裏的配置文件
gedit /etc/apache2/apache2.conf
User vmail
Group vmail
添加apache2的啓動用戶 user vmail group vmail
你還要去執行這兩條命令,否則apache2啓動不起來的
chmod 777 /var/lib/apache2/fastcgi
chmod 777 /var/lib/apache2/fastcgi/dynamic
sudo /etc/init.d/apache2 restart
編輯/var/www/extsuite/extmail/dispatch-init文件:
MAXFORK=10
最後啓動fastcgi server:
sudo /var/www/extsuite/extmail/dispatch-init start
若是沒有意外將啓動10個dispatch.fcgi守護進程,能夠經過如下命令將啓動命令加到rc.local中,實現自啓動:
echo "/var/www/extsuite/extmail/dispatch-init start" >> /etc/rc.local
/etc/init.d/apache2 restart
訪問頁面
在客戶端(XP)測試
添加hosts文件
192.168.10.67 mail.test.com瀏覽器訪問
http://mail.test.com/extman/cgi/index.cgi
進入後臺管理
添加域名
域列表--添加域 添加郵箱所要使用的域。
mail.test.com
後臺用戶名:root@extmail.org 密碼:extmail*123*
如今咱們來作SMTP認證
1.更改saslauthd
代碼:
gedit /etc/default/saslauthd
更改以下幾項:
代碼:
START=yes 設置開機自動啓動 OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"
2. 建立文件/etc/pam.d/smtp
內容以下:
代碼:
auth required pam_mysql.so user=root passwd=123456 host=127.0.0.1 db=extmail table=mailbox usercolumn=username passwdcolumn=password crypt=1 account sufficient pam_mysql.so user=root passwd=123456 host=127.0.0.1 db=extmail table=mailbox usercolumn=username passwdcolumn=password crypt=1
解釋一下:其實就是定義一個查詢的方式 crypt=1或者0表示加密或者不加密 注意對照你的數據庫 還有用戶名密碼 請保持跟本身的一致
3.因爲postfix處於chroot,要想調用到saslauthd 必須更改socket文件
代碼:
mkdir -p /var/spool/postfix/var/run/saslauthd
gedit /etc/postfix/sasl/smtpd.conf
建立smtpd.conf,而且內容以下:
代碼:
pwcheck_method:saslauthd mech_list:plain login allow_plaintext: true auxprop_plugin: mysql sql_hostnames: 127.0.0.1 sql_user: root //數據庫用戶名 sql_password: 123456 //數據庫密碼 sql_database: extmail log_level:7 sql_select: SELECT password FROM mailbox WHERE username='%u@%r' and domain='%r'
4.更改main.cf 文件
代碼:
gedit /etc/postfix/main.cf
代碼:
###########SMTP AUTH config############### broken_sasl_auth_clients = yes smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous ###########smtpd related config############ smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_sender_login_mismatch, reject_unknown_sender_domain, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, check_recipient_maps
加入以上的內容
添加用戶
代碼:
adduser postfix sasl
5.重啓postfix saslauthd
代碼:
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart
來作一下驗證測試
telnet localhost 25
ehlo localhost <——輸入
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
出現這兩項表示 sasl 配置成功
而後繼續操做
auth login——輸入
334 VXNlcm5hbWU6
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
334 UGFzc3dvcmQ6
ZXh0bWFpbA==
235 2.0.0 Authentication successful
quit
221 2.0.0 Bye
若是出現Authentication successful 表示沒有問題了
POP驗證
代碼:
gedit /etc/courier/authdaemonrc
更改以下一項
代碼:
authmodulelist="authmysql"
代碼:
cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig
cat /dev/null > /etc/courier/authmysqlrc
gedit /etc/courier/authmysqlrc
內容以下:
代碼:
代碼:
MYSQL_SERVER 127.0.0.1 MYSQL_USERNAME root MYSQL_PASSWORD 123456 MYSQL_SOCKET /var/run/mysqld/mysqld.sock MYSQL_PORT 3306 MYSQL_OPT 0 MYSQL_DATABASE extmail MYSQL_USER_TABLE mailbox MYSQL_CRYPT_PWFIELD password MYSQL_UID_FIELD uidnumber MYSQL_GID_FIELD gidnumber 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/vmail/',homedir), \ CONCAT('/home/vmail/',maildir), \ quota, \ name, \ CONCAT("disablesmtpd=",disablesmtpd, \ ",disablesmtp=",disablesmtp, \ ",disablewebmail=",disablewebmail, \ ",disablenetdisk=",disablenetdisk, \ ",disableimap=",disableimap, \ ",disablepop3=",disablepop3, \ ",netdiskquota=",netdiskquota) \ FROM mailbox \ WHERE username = '$(local_part)@$(domain)'
配置Courier-POP3
編輯/etc/courier/pop3d修改下面參數
代碼:
MAILDIRPATH=/home/vmail/
配置Courier-IMAP
編輯/etc/courier/imapd修改下面參數
代碼:
MAILDIRPATH=/home/vmail/
從新啓動
代碼:
/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop restart
/etc/init.d/courier-pop-ssl restart
測試Courier-Authlib是否能成功鏈接mysql
代碼:
authtest -s login postmaster@extmail.org extmail
若是成功應該有以下顯示
Authentication succeeded.
Authenticated: postmaster@extmail.org (uid 1000, gid 1000)
Home Directory: /home/vmail/extmail.org/postmaster
Maildir: /home/vmail/extmail.org/postmaster/Maildir/
Quota: 104857600S
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options:disablesmtpd=0,disablesmtp=0,disablewebmail=0,disablenetdisk=0,disableimap=0,disablepop3=0,netdiskquota=52428800S
若是出現error請檢查數據庫鏈接,分析mail.log。 通常都是input/output
Tips: chown daemon:vmail /var/run/courier/authdaemon 可能避免錯誤
測試pop3
telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Hello there.
user postmaster@extmail.org
+OK Password required.
pass extmail
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
若是出現問題請仔細分析日誌
MDA配置
概念:MDA mail deliver agent其實就是郵件投遞代理,postfix自己有不少郵件投遞代理,因爲咱們的環境虛擬域因此可使用postfix本身的virtual 這個代理,可是它必須建立一個用戶來執行投遞操做,main.cf中有記錄象這樣:
代碼:
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
virtual_transport = virtual
下面介紹另外一種MDA maildrop
安裝Maildrop
代碼:
apt-get install maildrop
建立一個文件
代碼:
gedit /etc/maildropmysql.config
代碼:
hostname 127.0.0.1 port 3306 database extmail dbuser root dbpw 123456 dbtable mailbox default_uidnumber 1000 default_gidnumber 1000 uidnumber_field uidnumber gidnumber_field gidnumber uid_field username homedirectory_field concat('/home/vmail/',homedir,'/') maildir_field concat('/home/vmail/',maildir) quota_field quota mailstatus_field active
修改/etc/maildroprc
代碼:
gedit /etc/maildroprc
代碼:
logfile "/var/log/maildrop.log"
手動建立日誌
代碼:
gedit /var/log/maildrop.log
chown vmail:vmail /var/log/maildrop.log
chmod 766 /var/log/maildrop.log
建立 /etc/logrotate.d/maildrop
內容爲下面:
代碼:
/var/log/maildrop.log { daily notifempty missingok rotate 5 compress create 766 vmail vmail sharedscripts }
編輯/etc/postfix/master.cf,註釋掉原來maildrop的配置內容並改成:
代碼:
maildrop unix - n n - - pipe flags=DRhu user=vmail argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}
因爲maildrop不支持一次接收多個收件人,所以必須在/etc/postfix/main.cf增長以下參數:
代碼:
###### Maildrop config ######## maildrop_destination_recipient_limit = 1 maildrop_destination_concurrency_limit = 2 virtual_transport = maildrop:
建立 /etc/quotawarnmsg,爲郵箱空間超過配額時的警告郵件內容
代碼:
X-Comment: Rename/Copy this file to quotawarnmsg, and make appropriate changes X-Comment: See deliverquota man page for more information From: Mail Delivery System <Mailer-Daemon@example.com> Reply-To: support@example.com To: Valued Customer:; Subject: Mail quota warning Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Your mailbox on the server is now more than 90% full. So that you can continue to receive mail you need to remove some messages from your mailbox.
圖形日誌extmail
代碼:
apt-get install mailgraph
cp -r /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext
修改/usr/local/mailgraph_ext/mailgraph-init爲:
代碼:
MAIL_LOG=/var/log/mail.log
而後複製文件
代碼:
cp /var/www/extsuite/extman/addon/mailgraph_ext/mailgraph-init /etc/init.d/mailgraph
update-rc.d mailgraph start 20 2 3 4 5 . stop 20 0 1 6 .
啓動服務
代碼:
/usr/local/mailgraph_ext/mailgraph-init start
把上面的代碼加入到/etc/rc.local中,讓系統自動啓動
代碼:
/etc/init.d/mailgraph start
/etc/init.d/qmonitor start
代碼:
chmod 755 /var/run/courier/authdaemon
可是重啓以後發現,authdaemon的權限又改會來了
在/etc/rc.local下把這個加了上去
代碼:
chmod 755 /var/run/courier/authdaemon
讓它開機後自動執行,完工
到此,本系統基本上是安裝完畢了。