| 導購 | 订阅 | 在线投稿
分享
 
 
 

Postfixadmin ( Web GUI 虛擬郵件伺服器架設)

來源:互聯網  2008-05-31 00:03:16  評論

最後修改日期: 2005/08/09

Description :

Virtual Mail Server

Virtual Mail Server 的優點為多網域使用同一台機器,它可讓一台伺服器不會單獨只服務一個 Domain 而造成浪費,四位之前有使用 vm-pop3 做過這樣的機智,但是因為缺乏好良好的 Web GUI 管理介面而讓系統管理者非常的辛苦,每次有要修改新增資料時就要勞駕系統管理者 Console 到 Server 裡慢慢修改,這真的粉辛苦ㄋㄟ。不過現在四位找到一個新的軟體 Postfixadmin ,這真是個好東西我們可透過它的 Web GUI 介面管理虛擬郵件主機,我們可以開新的網域及增加刪除使用者還可設定管理者,哈哈 ~ 如此一來我這個系統管理者只要負責架設及維護就好,這下可輕鬆了 ^^

除了 squirrelmail 的 pulgin 套件採抓取自行安裝外,其餘所有軟體安裝皆採用 ports 安裝,軟體安裝前已先更新過 ports tree ,虛擬郵件主機的主機名稱( Host name )為:vm ,網域名稱( Domain name )為:ntut.idv.tw、Server IP 為:88.88.88.88 ,DNS 也已指定過 MX 到 88.88.88.88 這個 IP,Server 架設完成後,所有要在虛擬郵件主機上跑的 Domain name DNS 皆需要指定 MX 到 88.88.88.88 這個 IP。

文件配色說明: 紅色粗體:標題 黑色粗體:副標題 藍色粗體:鍵入的指令文字 綠色字體:鍵入的文件內容 深紫字體:系統回應文字 黑色字體:文字說明。

Environment :

Postfix + PostfixAdmin + MySQL + Apache2 + PHP4 + PHP4-Session + Cyrus-sasl + Courier-imap + Maildrop + Squirrelmail

*OS:FreeBSD 5.4 Release

* mysql-server-4.0.25:/usr/ports/database/mysql40-server

* apache-2.0.54:/usr/ports/www/apache2

* php4-4.4.0:/usr/ports/lang/php4

* php4-session-4.4.0:/usr/ports/www/php4-session

* cyrus-sasl-2.1.21:/usr/ports/security/cyrus-sasl2

* postfix-2.2.5,1:/usr/ports/mail/postfix

* courier-imap-4.0.4,1:/usr/ports/mail/courier-imap

* maildrop-1.8.0_3:/usr/ports/mail/maildrop

* squirrelmail-1.4.5:/usr/ports/mail/squirrelmail

Setp 1.

安裝 MySQL40 ( Server/Client )

#cd /usr/ports/databases/mysql40-server/

#make install

#vi /etc/rc.conf # 設定 mysql 重開機自動啟動

mysql_enable="YES"

#reboot # 重開機讓 mysql 啟動

#netstats -na |grep LISTEN # 確認 mysql server 有啟動

tcp4 0 0 *.3306 *.* LISTEN

Setp 2.

安裝 Apache2

#cd /usr/ports/www/apache2

#make install

#vi /etc/rc.conf # 設定 apache2 開機自動 up

apache2_enable="YES"

#vi /usr/local/etc/apache2/httpd.conf

ServerAdmin admin@ntut.idv.tw

ServerName 127.0.0.1

AddDefaultCharset big5

#/usr/local/sbin/apachectl start

#ps -ax |grep http # 確認 apache 有啟動

70558 ?? Ss 0:00.06 /usr/local/sbin/httpd -k start

70559 ?? S 0:00.01 /usr/local/sbin/httpd -k start

70560 ?? S 0:00.01 /usr/local/sbin/httpd -k start

70561 ?? S 0:00.01 /usr/local/sbin/httpd -k start

Setp 3.

安裝 PHP4 + php4-session + cyrus-sasl2

#cd /usr/ports/lang/php4

#make install

Options for php4 4.4.0 # 只選了 apache2

[X] APACHE2 Use apache 2.x instead of apache 1.3.x

#vi /usr/local/etc/apache2/httpd.conf # 修改 apache2 設定讓 php 運行在 apache2

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

DirectoryIndex index.php index.html index.html.var

#cd /usr/local/etc/

#cp php.ini-dist php.ini

#vi php.ini

register_globals =On # 修改 register_globals =Off 變成 On ,squirrelmail 會用得到

#cd /usr/ports/www/php4-session/ # 安裝 php4-session 是 postfixadmin 需要用到的,所以是必須要加裝的

#make install

#apachectl restart # 重新起動 apache

#vi /usr/local/www/data/index.php

開個瀏覽器測試 php4 有無安裝成功: http://88.88.88.88/index.php

# cd /usr/ports/security/cyrus-sasl2 # 安裝 cyrus-sasl

# make install WITH_AUTHDAEMON=yes

#vi /usr/local/lib/sasl2/smtpd.conf # 配置 sasl

pwcheck_method: authdaemond

log_level: 3

mech_list: PLAIN LOGIN

authdaemond_path:/var/run/authdaemond/socket

Setp 4.

安裝 Postfix

#cd /usr/ports/mail/postfix

#make install WITH_AUTHDAEMON=yes

Postfix configuration options # 只選 SASL2 跟 MySQL

[X] SASL2 Cyrus SASLv2 (Simple Authentication and Security Layer)

[X] MySQL MySQL map lookups (choose version with WITH_MYSQL_VER)

Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y # 選 yes

#cd /usr/local/etc/rc.d # 開機自動啟動 postfix

#ln –s /usr/local/sbin/postfix postfix.sh

#chmod 755 postfix.sh

#echo 『postfix: root』 /etc/aliases

#/usr/local/bin/newaliases

#chown postfix:postfix /etc/opiekeys

#vi /usr/local/etc/postfix/main.cf

myhostname = vm.ntut.idv.tw

mydomain = ntut.idv.tw

myorigin = $mydomain

mydestination = $myhostname localhost localhost.$mydomain

mynetworks = 88.88.88.0/24, 127.0.0.0/8

inet_interfaces = all

virtual_mailbox_base = /var/mailbox/

virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf

virtual_mailbox_domains = mysql:/usr/local/etc/postfix/mysql_virtual_domains_maps.cf

virtual_alias_domains =

virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql_virtual_alias_maps.cf

virtual_uid_maps = static:5001

virtual_gid_maps = static:5001

virtual_transport = maildrop

maildrop_destination_recipient_limit = 1

maildrop_destination_concurrency_limit = 1

message_size_limit = 143360000

virtual_mailbox_limit = 209715200

virtual_create_maildirsize = yes

virtual_mailbox_extended = yes

virtual_mailbox_limit_maps = mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_limit_maps.cf

virtual_mailbox_limit_override = yes

virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.

virtual_overquota_bounce = yes

broken_sasl_auth_clients = yes

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

smtpd_sasl_security_options = noanonymous

smtpd_sasl_application_name = smtpd

smtpd_banner=$myhostname ESMTP "Version not Available"

#mkdir /var/mailbox # 建立郵件存放目錄

#pw groupadd vmail -g 5001 # 建立 vmail 這個使用者帳號及群組

#pw useradd vmail -u 5001 -g 5001 -s/sbin/nologin -d/dev/null

#chown -R vmail:vmail /var/mailbox

#chmod -R ug+rwx,o-rwx /var/mailbox

#vi /usr/local/etc/postfix/mysql_virtual_alias_maps.cf # 建立MySQL 跟 postfix 之間的資料對應關聯總共四個檔

user = postfix

password = postfix

hosts = localhost

dbname = postfix

table = alias

select_field = goto

where_field = address

#vi /usr/local/etc/postfix/mysql_virtual_domains_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

table = domain

select_field = description

where_field = domain

#vi /usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

table = mailbox

select_field = maildir

where_field = username

#vi /usr/local/etc/postfix/mysql_virtual_mailbox_limit_maps.cf

user = postfix

password = postfix

hosts = localhost

dbname = postfix

table = mailbox

select_field = quota

where_field = username

#/usr/local/sbin/postfix start # 啟動 postfix

Setp 4.

安裝 Postfixadmin

#cd /usr/ports/mail/postfixadmin/

#make install

#chown -R vmail:vmail /usr/local/www/postfixadmin # 修改所有 postfixadmin 的目錄資料夾權限

#cd /usr/local/www/postfixadmin

#chmod 640 *.php *.css

#cd /usr/local/www/postfixadmin/admin/

#chmod 640 *.php .ht*

#cd /usr/local/www/postfixadmin/images/

#chmod 640 *.gif *.png

#cd /usr/local/www/postfixadmin/languages/

#chmod 640 *.lang

#cd /usr/local/www/postfixadmin/templates/

#chmod 640 *.tpl

#cd /usr/local/www/postfixadmin/users/

#chmod 640 *.php

#cd /usr/local/www/postfixadmin # 建立 Postfixadmin 的 MySQL 資料庫

#mysql -u root

#vi config.inc.php # 修改 postfixadmin 的設定檔,目前只修改下面幾項設定,其他更多設定得自己慢慢研究

$CONF['default_language'] = 'tw';

$CONF['database_type'] = 'mysql';

$CONF['database_host'] = 'localhost';

$CONF['database_user'] = 'postfixadmin';

$CONF['database_password'] = 'postfixadmin';

$CONF['database_name'] = 'postfix';

//$CONF['encrypt'] = 'md5crypt'; # 註解掉md5 加密改用一般明碼

$CONF['encrypt'] = 'cleartext';

$CONF['domain_path'] = 'YES';

$CONF['domain_in_mailbox'] = 'NO';

$CONF['quota'] = 'YES';

$CONF['footer_text'] = 'Return to vm.ntut.idv.tw';

$CONF['footer_link'] = 'http://vm.ntut.idv.tw/postfixadmin/';

#vi /usr/local/etc/apache2/httpd.conf # 修改 apache 的 User 跟 Group

#User www

#Group www

User vmail

Group vmail

#vi /usr/local/etc/apache2/Includes/mine.conf # 增加 apache 對應的 postfixadmin 虛擬目錄

Alias /postfixadmin/ "/usr/local/www/postfixadmin/"

Options Indexes

AllowOverride ALL

Order allow,deny

Allow from all

#apachectl stop # 重新啟動apache

#apachectl start

Setp 5.

安裝Courier-imap+maildrop

#cd /usr/ports/mail/courier-imap

#make WITHOUT_OPENSSL=yes WITH_MYSQL=yes install clean

Options for courier-imap 4.0.4,1 # 只選了 AUTH_MYSQL

[X] AUTH_MYSQL MySQL support

#chmod +x /var/run/authdaemond

#cd /usr/local/etc/courier-imap

#cp imapd.cnf.dist imapd.cnf

#cp pop3d.cnf.dist pop3d.cnf

#vi /usr/local/etc/authlib/authdaemonrc # 刪除其他的 authxxxx 只留下 authmysql

authmodulelist="authmysql"

authmodulelistorig="authmysql"

#vi /usr/local/etc/authlib/authmysqlrc # 注意:在這個文件中不能使用空白鍵,只能用 tab 鍵,localhost 也不能使用單引號。

MYSQL_SERVER localhost

MYSQL_SOCKET /tmp/mysql.sock

MYSQL_DATABASE postfix

MYSQL_USERNAME postfix

MYSQL_PASSWORD postfix

MYSQL_USER_TABLE mailbox

MYSQL_LOGIN_FIELD username

#MYSQL_CRYPT_PWFIELD password # 這邊採用明碼所以註解掉改成下面那行

MYSQL_CLEAR_PWFIELD password

MYSQL_UID_FIELD '5001'

MYSQL_GID_FIELD '5001'

MYSQL_HOME_FIELD '/var/mailbox/'

MYSQL_MAILDIR_FIELD maildir

MYSQL_NAME_FIELD name

MYSQL_QUOTA_FIELD quota

MYSQL_WHERE_CLAUSE active='1'

#vi /etc/rc.conf # 建立開機自動啟動

courier_authdaemond_enable="YES"

courier_imap_pop3d_enable="YES"

courier_imap_imapd_enable="YES"

#cd /usr/ports/mail/maildrop # 安裝 maildrop

#make WITH_AUTHLIB=yes install clean

Options for maildrop 1.8.0_3 # 只選了 AUTH_MYSQL

[X] AUTH_MYSQL MySQL support

#vi /etc/maildroprc # 建立新的文件 /etc/maildroprc

logfile "/var/mailbox/maildrop.log"

to "$HOME$DEFAULT"

#chmod a+r /etc/maildroprc # 更改 maildroprc 的權限

#vi /usr/local/etc/postfix/main.cf # 再次配置 Postfix 檢察下面兩組設定再配置 master.cf

virtual_transport = maildrop

maildrop_destination_recipient_limit = 1

#vi /usr/local/etc/postfix/master.cf

maildrop unix - n n - - pipe

flags=DRhu user=vmail:vmail argv=/usr/local/bin/maildrop -w 90 -d ${recipient}

#cd /usr/ports/security/sudo # 因為 maildrop 沒有建立 maildir 的功能,所以要透過 maildirmake.sh 這支 shell script 來運作(如果你的系統沒有裝 sudo,請先安裝 sudo)

#make install

#vi /usr/local/etc/sudoers

vmail ALL = NOPASSWD: /usr/sbin/maildirmake.sh

#vi /usr/sbin/maildirmake.sh # 建立新的 /usr/sbin/maildirmake.sh 文件

#!/usr/local/bin/bash

set -e

if [ ! -d /var/mailbox/$1 ]

then

mkdir /var/mailbox/$1

fi

chown -R vmail:vmail /var/mailbox/$1

cd "/var/mailbox/$1"

/usr/local/bin/maildirmake $2

chown -R 5001:postfix /var/mailbox/$1/$2

chmod -R g=s /var/mailbox/$1/$2

#chmod 755 /usr/sbin/maildirmake.sh

#vi /var/www/postfixadmin/admin/create-mailbox.php # 更改 create-mailbox.php 文件,在此文件的第 200 行後加入下面這一行:

system("sudo /usr/sbin/maildirmake.sh $fDomain ".$_POST['fUsername']);

#vi /var/www/postfixadmin/create-mailbox.php # 同樣也必須要更改 postfixadmin 目錄下的這一份 create-mailbox.php 文件,於 210 行後加入下面這行,其作用為讓網域管理員也可新增使用者。

system("sudo /usr/sbin/maildirmake.sh $fDomain ".$_POST['fUsername']);

#/usr/local/sbin/authdaemond start # 手動啟動 authdaemond

#ps -ax |grep authdaemond # 確認 authdaemond 有 up

55665 p0 S 0:00.03 /usr/local/libexec/courier-authlib/authdaemond

55666 p0 S 0:00.00 /usr/local/libexec/courier-authlib/authdaemond

#/usr/local/libexec/courier-imap/imapd.rc start # 手動啟動 imap 服務

#/usr/local/libexec/courier-imap/pop3d.rc start # 手動啟動 pop3 服務

#netstat -na |grep LISTEN # 確認 110 跟 143 port 有 up

tcp4 0 0 *.110 *.* LISTEN

tcp4 0 0 *.143 *.* LISTEN

Setp 6.

初步完成測試驗收 Postfixadmin + Postfix + MySQL

※ 其實安裝到這個階段我們的 Virtual Mail 已經大至完成可正常收發信,只缺松鼠WebMail 尚未加裝,因此我們可透過 telnet 及 Browse 來驗收成果。

http://88.88.88.88/postfixadmin/setup.php # 查看 Postfixadmin 在我們安裝的 php 環境有無 ok

Postfix Admin Setup Checker 1.0.0

Running software:

- PHP version 4.4.0

- Apache/2.0.54 (FreeBSD) PHP/4.4.0

Checking for dependencies:

- Magic Quotes: ON

- Depends on: presence config.inc.php - OK

- Depends on: MySQL 3.23, 4.0 - OK

- Depends on: session - OK

- Depends on: pcre - OK

#cd /usr/local/www/postfixadmin/

#mv setup.php setup_backup.php # 將 setup.php 刪除或改名稱

http://88.88.88.88/postfixadmin/admin/ # 預設帳號密碼為 admin /admin,進入後即可建立新網域及帳號來測試,小弟建了 ms2.ntut.idv.tw 網域及 jim@ms2.ntut.idv.tw 帳號

#telnet 127.0.0.1 25 # 測試 25 port 看看 postfix 運行有無正常

Trying 127.0.0.1...

Connected to localhost.ntut.idv.tw.

Escape character is '^]'.

220 vm.ntut.idv.tw ESMTP "Version not Available"

mail from:jim@ntut.idv.tw

250 Ok

rcpt to:jim@ms2.ntut.idv.tw

250 Ok

data

354 End data with .

Subject:test

1234

.

250 Ok: queued as 4ED91C5124

quit

221 Bye

Connection closed by foreign host.

#telnet 127.0.0.1 110 # 測試 110 port 看看 pop3 有無正常運作

Trying 127.0.0.1...

Connected to localhost.ntut.idv.tw.

Escape character is '^]'.

+OK Hello there.

user jim@ms2.ntut.idv.tw

+OK Password required.

pass xxxxx

+OK logged in.

list

+OK POP3 clients that break here, they violate STD53.

.

quit

+OK Bye-bye.

Connection closed by foreign host.

※ 檢查 MySQL 資料庫內容,可讓自己更加了解整體 Virtual Mail 資料架構型態。

#mysql -u root -p # 查看 MySQL 資料庫

Enter password: xxxxx

mysqlSHOW DATABASES; # 查看 MySQL 有那些資料庫

+ ---------- +

| Database |

+ ---------- +

| mysql |

| postfix |

| test |

+ ---------- +

mysqlUSE mysql; # 進入 mysql 資料庫

Database changed

mysqlSHOW TABLES; # 查看 mysql 這個資料庫裡有多少個資料表

+ ----------------- +

| Tables_in_mysql |

+ ----------------- +

| columns_priv |

| db |

| func |

| host |

| tables_priv |

| user |

+ ----------------- +

mysqlDESC db; # 可查看 db 資料表型態

mysqlSELECT * FROM db; # 可查看 db 資料表內所插入的所有內容

mysqlSELECT * FROM user; # 可查看 user 資料表內所插入的所有內容

mysqlUSE postfix; # 切換到 postfix 資料庫

Database changed

mysqlSHOW TABLES; # 查看 postfix 資料庫中的所有資料表

+ ------------------- +

| Tables_in_postfix |

+ ------------------- +

| admin |

| alias |

| domain |

| domain_admins |

| log |

| mailbox |

| vacation |

+ ------------------- +

mysqlSELECT * FROM domain; # 查看 domain 資料表內的資料

Setp 7.

再加裝 Squirrelmail 之 WebMail

#cd /usr/ports/mail/squirrelmail/ # 安裝松鼠 webmail 的主程式,外掛程式需獨立抓取套件安裝

#make install

Options for php4-mbstring 4.4.0

[X] REGEX Enable multibyte regex support

#vi /usr/local/etc/php.ini # 修改 php.ini

file_uploads = On

session.auto_start = 1

#vi /usr/local/etc/apache2/Includes/mine.conf # 再加入 squirrelmail 的路徑到 apache 網頁目錄

Alias /squirrelmail/ "/usr/local/www/squirrelmail/"

squirrelmail"

Options Indexes

AllowOverride AuthConfig

Order allow,deny

Allow from all

#apachectl restart # 重新啟動 apache

#chown -R vmail:vmail /var/spool/squirrelmail # 因為 apache 的 User Group 都改 vmail 所以 /var/spool/squirrelmail 也必須跟進

#cd /usr/local/www/squirrelmail # 修改 configure 設定值

#./configure

選 10. Languages

1. Default Language : 的 en_US 改成 zh_TW。

2. Default Charset : 改成 big5

Command Q

You have not saved your data.

Save? [Y/n]: Y

#vi /usr/local/www/squirrelmail/config/config.php # 再次手動修改 config.php 檔,調整到最符合你的需求我只修改 $domain

$domain = 'vm.ntut.idv.tw';

※ Plugins

至官網的 Plugins 頁面 http://www.squirrelmail.org/plugins.php 中抓取三個 plugin 套件,Plugins 安裝套件路徑如下:我將它們放入 Virtual Mail Server 中的 /home/jim 個人目錄下

Visual Additions Quota Usage Download 1.3 quota_usage-1.3-1.2.7.tar.gz

Change password Change MySQL Password Download 2.7-1.4.x change_mysqlpass-3.2-1.2.8.tar.gz

Miscellaneous Compatibility Download 2.0.1 compatibility-2.0.1.tar.gz

#tar -xzvf quota_usage-1.3-1.2.7.tar.gz -C /usr/local/www/squirrelmail/plugins/ # 開始安裝 Quota Usage

#cd /usr/local/www/squirrelmail/plugins/quota_usage # 配置 Quota Usage

#cp config.php.sample config.php

#tar -xzvf compatibility-1.3.tar.gz -C /usr/local/www/squirrelmail/plugins/

#tar -xzvf change_mysqlpass-3.2-1.2.8.tar.gz -C /usr/local/www/squirrelmail/plugins/

#cd /usr/local/www/squirrelmail/plugins/change_mysqlpass

#cp config.php.sample config.php

#vi config.php # 配置 change_mypass 修改如下

$mysql_database = 'postfix';

$mysql_table = 'mailbox';

$mysql_userid_field = 'username';

$mysql_password_field ='password';

$mysql_manager_id = 'postfix';

$mysql_manager_pw = 'postfix';

$mysql_unixcrypt = 0;

//$mysql_MD5crypt = 1; # 如果你的密碼是 MD5 加密的,就把$mysql_MD5crypt = 0;改成$mysql_MD5crypt = 1;

$mysql_MD5crypt = 0;

$use_ssl_for_password_change = 0;

#cd /usr/local/www/squirrelmail

#./configure # 啟動 plugins 套件

選擇 8. Plugins 再挑選我們剛剛所添加的三個套件即可

安裝參考資料:

http://www.xuki.org/bbs/showthread.php?t=125

http://www.xs4all.nl/~jaspersl/quota/

To Add:

1%26#8231;裝了 change_mysqlpass plugin 套件後, login 到松鼠 WebMail 後出現錯誤,這是由於數據結構不一至所造成的,只要將 /usr/local/www/squirrelmail/plugins/change_mysqlpass/functions.php 的第 129 行 \\註解掉就行了。

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/local/www/squirrelmail/plugins/change_mysqlpass/functions.php on line 129

2%26#8231;修改 Squirrelmail 中的 Quota Usage 容量方式有兩種:

方式 (一)、用瀏覽器登入 Postfixadmin 的管理頁面,虛擬用戶清單 (限制 (MB)) 10M 修改為:200M

※ 注意:網域名稱清單 =最大容量限制 (MB) 必須要大於 虛擬用戶清單 = 限制 (MB) 才可修改 虛擬用戶清單 的容量限制

如:網域名稱清單 (最大容量限制 300 (MB)) 虛擬用戶清單 (限制 200 (MB))

方式 (二)、也可手動調整 Console 進去 server 的 mysql 資料表修改

#mysql -uroot -p

mysqluse postfix;

mysqlupdate mailbox set quota='204800000S' where username='jim@ms2.ntut.idv.tw';

Query OK, 1 row affected (0.10 sec)

Rows matched: 1 Changed: 1 Warnings: 1

mysql select username,quota from mailbox;

+ --------------------- + ----------- +

| username | quota |

+ --------------------- + ----------- +

| jim@ms2.ntut.idv.tw | 204800000 |

| jim@smtp.4wei.us | 10240000 |

+ --------------------- + ----------- +

2 rows in set (0.00 sec)

最後修改日期: 2005/08/09 Description : Virtual Mail Server Virtual Mail Server 的優點為多網域使用同一台機器,它可讓一台伺服器不會單獨只服務一個 Domain 而造成浪費,四位之前有使用 vm-pop3 做過這樣的機智,但是因為缺乏好良好的 Web GUI 管理介面而讓系統管理者非常的辛苦,每次有要修改新增資料時就要勞駕系統管理者 Console 到 Server 裡慢慢修改,這真的粉辛苦ㄋㄟ。不過現在四位找到一個新的軟體 Postfixadmin ,這真是個好東西我們可透過它的 Web GUI 介面管理虛擬郵件主機,我們可以開新的網域及增加刪除使用者還可設定管理者,哈哈 ~ 如此一來我這個系統管理者只要負責架設及維護就好,這下可輕鬆了 ^^ 除了 squirrelmail 的 pulgin 套件採抓取自行安裝外,其餘所有軟體安裝皆採用 ports 安裝,軟體安裝前已先更新過 ports tree ,虛擬郵件主機的主機名稱( Host name )為:vm ,網域名稱( Domain name )為:ntut.idv.tw、Server IP 為:88.88.88.88 ,DNS 也已指定過 MX 到 88.88.88.88 這個 IP,Server 架設完成後,所有要在虛擬郵件主機上跑的 Domain name DNS 皆需要指定 MX 到 88.88.88.88 這個 IP。 文件配色說明: 紅色粗體:標題 黑色粗體:副標題 藍色粗體:鍵入的指令文字 綠色字體:鍵入的文件內容 深紫字體:系統回應文字 黑色字體:文字說明。 Environment : Postfix + PostfixAdmin + MySQL + Apache2 + PHP4 + PHP4-Session + Cyrus-sasl + Courier-imap + Maildrop + Squirrelmail *OS:FreeBSD 5.4 Release * mysql-server-4.0.25:/usr/ports/database/mysql40-server * apache-2.0.54:/usr/ports/www/apache2 * php4-4.4.0:/usr/ports/lang/php4 * php4-session-4.4.0:/usr/ports/www/php4-session * cyrus-sasl-2.1.21:/usr/ports/security/cyrus-sasl2 * postfix-2.2.5,1:/usr/ports/mail/postfix * courier-imap-4.0.4,1:/usr/ports/mail/courier-imap * maildrop-1.8.0_3:/usr/ports/mail/maildrop * squirrelmail-1.4.5:/usr/ports/mail/squirrelmail Setp 1. 安裝 MySQL40 ( Server/Client ) #cd /usr/ports/databases/mysql40-server/ #make install #vi /etc/rc.conf # 設定 mysql 重開機自動啟動 mysql_enable="YES" #reboot # 重開機讓 mysql 啟動 #netstats -na |grep LISTEN # 確認 mysql server 有啟動 tcp4 0 0 *.3306 *.* LISTEN Setp 2. 安裝 Apache2 #cd /usr/ports/www/apache2 #make install #vi /etc/rc.conf # 設定 apache2 開機自動 up apache2_enable="YES" #vi /usr/local/etc/apache2/httpd.conf ServerAdmin admin@ntut.idv.tw ServerName 127.0.0.1 AddDefaultCharset big5 #/usr/local/sbin/apachectl start #ps -ax |grep http # 確認 apache 有啟動 70558 ?? Ss 0:00.06 /usr/local/sbin/httpd -k start 70559 ?? S 0:00.01 /usr/local/sbin/httpd -k start 70560 ?? S 0:00.01 /usr/local/sbin/httpd -k start 70561 ?? S 0:00.01 /usr/local/sbin/httpd -k start Setp 3. 安裝 PHP4 + php4-session + cyrus-sasl2 #cd /usr/ports/lang/php4 #make install Options for php4 4.4.0 # 只選了 apache2 [X] APACHE2 Use apache 2.x instead of apache 1.3.x #vi /usr/local/etc/apache2/httpd.conf # 修改 apache2 設定讓 php 運行在 apache2 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps DirectoryIndex index.php index.html index.html.var #cd /usr/local/etc/ #cp php.ini-dist php.ini #vi php.ini register_globals =On # 修改 register_globals =Off 變成 On ,squirrelmail 會用得到 #cd /usr/ports/www/php4-session/ # 安裝 php4-session 是 postfixadmin 需要用到的,所以是必須要加裝的 #make install #apachectl restart # 重新起動 apache #vi /usr/local/www/data/index.php 開個瀏覽器測試 php4 有無安裝成功: http://88.88.88.88/index.php # cd /usr/ports/security/cyrus-sasl2 # 安裝 cyrus-sasl # make install WITH_AUTHDAEMON=yes #vi /usr/local/lib/sasl2/smtpd.conf # 配置 sasl pwcheck_method: authdaemond log_level: 3 mech_list: PLAIN LOGIN authdaemond_path:/var/run/authdaemond/socket Setp 4. 安裝 Postfix #cd /usr/ports/mail/postfix #make install WITH_AUTHDAEMON=yes Postfix configuration options # 只選 SASL2 跟 MySQL [X] SASL2 Cyrus SASLv2 (Simple Authentication and Security Layer) [X] MySQL MySQL map lookups (choose version with WITH_MYSQL_VER) Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y # 選 yes #cd /usr/local/etc/rc.d # 開機自動啟動 postfix #ln –s /usr/local/sbin/postfix postfix.sh #chmod 755 postfix.sh #echo 『postfix: root』 /etc/aliases #/usr/local/bin/newaliases #chown postfix:postfix /etc/opiekeys #vi /usr/local/etc/postfix/main.cf myhostname = vm.ntut.idv.tw mydomain = ntut.idv.tw myorigin = $mydomain mydestination = $myhostname localhost localhost.$mydomain mynetworks = 88.88.88.0/24, 127.0.0.0/8 inet_interfaces = all virtual_mailbox_base = /var/mailbox/ virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_mailbox_domains = mysql:/usr/local/etc/postfix/mysql_virtual_domains_maps.cf virtual_alias_domains = virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql_virtual_alias_maps.cf virtual_uid_maps = static:5001 virtual_gid_maps = static:5001 virtual_transport = maildrop maildrop_destination_recipient_limit = 1 maildrop_destination_concurrency_limit = 1 message_size_limit = 143360000 virtual_mailbox_limit = 209715200 virtual_create_maildirsize = yes virtual_mailbox_extended = yes virtual_mailbox_limit_maps = mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_limit_maps.cf virtual_mailbox_limit_override = yes virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later. virtual_overquota_bounce = yes broken_sasl_auth_clients = yes smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous smtpd_sasl_application_name = smtpd smtpd_banner=$myhostname ESMTP "Version not Available" #mkdir /var/mailbox # 建立郵件存放目錄 #pw groupadd vmail -g 5001 # 建立 vmail 這個使用者帳號及群組 #pw useradd vmail -u 5001 -g 5001 -s/sbin/nologin -d/dev/null #chown -R vmail:vmail /var/mailbox #chmod -R ug+rwx,o-rwx /var/mailbox #vi /usr/local/etc/postfix/mysql_virtual_alias_maps.cf # 建立MySQL 跟 postfix 之間的資料對應關聯總共四個檔 user = postfix password = postfix hosts = localhost dbname = postfix table = alias select_field = goto where_field = address #vi /usr/local/etc/postfix/mysql_virtual_domains_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = domain select_field = description where_field = domain #vi /usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = mailbox select_field = maildir where_field = username #vi /usr/local/etc/postfix/mysql_virtual_mailbox_limit_maps.cf user = postfix password = postfix hosts = localhost dbname = postfix table = mailbox select_field = quota where_field = username #/usr/local/sbin/postfix start # 啟動 postfix Setp 4. 安裝 Postfixadmin #cd /usr/ports/mail/postfixadmin/ #make install #chown -R vmail:vmail /usr/local/www/postfixadmin # 修改所有 postfixadmin 的目錄資料夾權限 #cd /usr/local/www/postfixadmin #chmod 640 *.php *.css #cd /usr/local/www/postfixadmin/admin/ #chmod 640 *.php .ht* #cd /usr/local/www/postfixadmin/images/ #chmod 640 *.gif *.png #cd /usr/local/www/postfixadmin/languages/ #chmod 640 *.lang #cd /usr/local/www/postfixadmin/templates/ #chmod 640 *.tpl #cd /usr/local/www/postfixadmin/users/ #chmod 640 *.php #cd /usr/local/www/postfixadmin # 建立 Postfixadmin 的 MySQL 資料庫 #mysql -u root #vi config.inc.php # 修改 postfixadmin 的設定檔,目前只修改下面幾項設定,其他更多設定得自己慢慢研究 $CONF['default_language'] = 'tw'; $CONF['database_type'] = 'mysql'; $CONF['database_host'] = 'localhost'; $CONF['database_user'] = 'postfixadmin'; $CONF['database_password'] = 'postfixadmin'; $CONF['database_name'] = 'postfix'; //$CONF['encrypt'] = 'md5crypt'; # 註解掉md5 加密改用一般明碼 $CONF['encrypt'] = 'cleartext'; $CONF['domain_path'] = 'YES'; $CONF['domain_in_mailbox'] = 'NO'; $CONF['quota'] = 'YES'; $CONF['footer_text'] = 'Return to vm.ntut.idv.tw'; $CONF['footer_link'] = 'http://vm.ntut.idv.tw/postfixadmin/'; #vi /usr/local/etc/apache2/httpd.conf # 修改 apache 的 User 跟 Group #User www #Group www User vmail Group vmail #vi /usr/local/etc/apache2/Includes/mine.conf # 增加 apache 對應的 postfixadmin 虛擬目錄 Alias /postfixadmin/ "/usr/local/www/postfixadmin/" Options Indexes AllowOverride ALL Order allow,deny Allow from all #apachectl stop # 重新啟動apache #apachectl start Setp 5. 安裝Courier-imap+maildrop #cd /usr/ports/mail/courier-imap #make WITHOUT_OPENSSL=yes WITH_MYSQL=yes install clean Options for courier-imap 4.0.4,1 # 只選了 AUTH_MYSQL [X] AUTH_MYSQL MySQL support #chmod +x /var/run/authdaemond #cd /usr/local/etc/courier-imap #cp imapd.cnf.dist imapd.cnf #cp pop3d.cnf.dist pop3d.cnf #vi /usr/local/etc/authlib/authdaemonrc # 刪除其他的 authxxxx 只留下 authmysql authmodulelist="authmysql" authmodulelistorig="authmysql" #vi /usr/local/etc/authlib/authmysqlrc # 注意:在這個文件中不能使用空白鍵,只能用 tab 鍵,localhost 也不能使用單引號。 MYSQL_SERVER localhost MYSQL_SOCKET /tmp/mysql.sock MYSQL_DATABASE postfix MYSQL_USERNAME postfix MYSQL_PASSWORD postfix MYSQL_USER_TABLE mailbox MYSQL_LOGIN_FIELD username #MYSQL_CRYPT_PWFIELD password # 這邊採用明碼所以註解掉改成下面那行 MYSQL_CLEAR_PWFIELD password MYSQL_UID_FIELD '5001' MYSQL_GID_FIELD '5001' MYSQL_HOME_FIELD '/var/mailbox/' MYSQL_MAILDIR_FIELD maildir MYSQL_NAME_FIELD name MYSQL_QUOTA_FIELD quota MYSQL_WHERE_CLAUSE active='1' #vi /etc/rc.conf # 建立開機自動啟動 courier_authdaemond_enable="YES" courier_imap_pop3d_enable="YES" courier_imap_imapd_enable="YES" #cd /usr/ports/mail/maildrop # 安裝 maildrop #make WITH_AUTHLIB=yes install clean Options for maildrop 1.8.0_3 # 只選了 AUTH_MYSQL [X] AUTH_MYSQL MySQL support #vi /etc/maildroprc # 建立新的文件 /etc/maildroprc logfile "/var/mailbox/maildrop.log" to "$HOME$DEFAULT" #chmod a+r /etc/maildroprc # 更改 maildroprc 的權限 #vi /usr/local/etc/postfix/main.cf # 再次配置 Postfix 檢察下面兩組設定再配置 master.cf virtual_transport = maildrop maildrop_destination_recipient_limit = 1 #vi /usr/local/etc/postfix/master.cf maildrop unix - n n - - pipe flags=DRhu user=vmail:vmail argv=/usr/local/bin/maildrop -w 90 -d ${recipient} #cd /usr/ports/security/sudo # 因為 maildrop 沒有建立 maildir 的功能,所以要透過 maildirmake.sh 這支 shell script 來運作(如果你的系統沒有裝 sudo,請先安裝 sudo) #make install #vi /usr/local/etc/sudoers vmail ALL = NOPASSWD: /usr/sbin/maildirmake.sh #vi /usr/sbin/maildirmake.sh # 建立新的 /usr/sbin/maildirmake.sh 文件 #!/usr/local/bin/bash set -e if [ ! -d /var/mailbox/$1 ] then mkdir /var/mailbox/$1 fi chown -R vmail:vmail /var/mailbox/$1 cd "/var/mailbox/$1" /usr/local/bin/maildirmake $2 chown -R 5001:postfix /var/mailbox/$1/$2 chmod -R g=s /var/mailbox/$1/$2 #chmod 755 /usr/sbin/maildirmake.sh #vi /var/www/postfixadmin/admin/create-mailbox.php # 更改 create-mailbox.php 文件,在此文件的第 200 行後加入下面這一行: system("sudo /usr/sbin/maildirmake.sh $fDomain ".$_POST['fUsername']); #vi /var/www/postfixadmin/create-mailbox.php # 同樣也必須要更改 postfixadmin 目錄下的這一份 create-mailbox.php 文件,於 210 行後加入下面這行,其作用為讓網域管理員也可新增使用者。 system("sudo /usr/sbin/maildirmake.sh $fDomain ".$_POST['fUsername']); #/usr/local/sbin/authdaemond start # 手動啟動 authdaemond #ps -ax |grep authdaemond # 確認 authdaemond 有 up 55665 p0 S 0:00.03 /usr/local/libexec/courier-authlib/authdaemond 55666 p0 S 0:00.00 /usr/local/libexec/courier-authlib/authdaemond 、 #/usr/local/libexec/courier-imap/imapd.rc start # 手動啟動 imap 服務 #/usr/local/libexec/courier-imap/pop3d.rc start # 手動啟動 pop3 服務 #netstat -na |grep LISTEN # 確認 110 跟 143 port 有 up tcp4 0 0 *.110 *.* LISTEN tcp4 0 0 *.143 *.* LISTEN Setp 6. 初步完成測試驗收 Postfixadmin + Postfix + MySQL ※ 其實安裝到這個階段我們的 Virtual Mail 已經大至完成可正常收發信,只缺松鼠WebMail 尚未加裝,因此我們可透過 telnet 及 Browse 來驗收成果。 http://88.88.88.88/postfixadmin/setup.php # 查看 Postfixadmin 在我們安裝的 php 環境有無 ok Postfix Admin Setup Checker 1.0.0 Running software: - PHP version 4.4.0 - Apache/2.0.54 (FreeBSD) PHP/4.4.0 Checking for dependencies: - Magic Quotes: ON - Depends on: presence config.inc.php - OK - Depends on: MySQL 3.23, 4.0 - OK - Depends on: session - OK - Depends on: pcre - OK #cd /usr/local/www/postfixadmin/ #mv setup.php setup_backup.php # 將 setup.php 刪除或改名稱 http://88.88.88.88/postfixadmin/admin/ # 預設帳號密碼為 admin /admin,進入後即可建立新網域及帳號來測試,小弟建了 ms2.ntut.idv.tw 網域及 jim@ms2.ntut.idv.tw 帳號 #telnet 127.0.0.1 25 # 測試 25 port 看看 postfix 運行有無正常 Trying 127.0.0.1... Connected to localhost.ntut.idv.tw. Escape character is '^]'. 220 vm.ntut.idv.tw ESMTP "Version not Available" mail from:jim@ntut.idv.tw 250 Ok rcpt to:jim@ms2.ntut.idv.tw 250 Ok data 354 End data with . Subject:test 1234 . 250 Ok: queued as 4ED91C5124 quit 221 Bye Connection closed by foreign host. #telnet 127.0.0.1 110 # 測試 110 port 看看 pop3 有無正常運作 Trying 127.0.0.1... Connected to localhost.ntut.idv.tw. Escape character is '^]'. +OK Hello there. user jim@ms2.ntut.idv.tw +OK Password required. pass xxxxx +OK logged in. list +OK POP3 clients that break here, they violate STD53. . quit +OK Bye-bye. Connection closed by foreign host. ※ 檢查 MySQL 資料庫內容,可讓自己更加了解整體 Virtual Mail 資料架構型態。 #mysql -u root -p # 查看 MySQL 資料庫 Enter password: xxxxx mysqlSHOW DATABASES; # 查看 MySQL 有那些資料庫 + ---------- + | Database | + ---------- + | mysql | | postfix | | test | + ---------- + mysqlUSE mysql; # 進入 mysql 資料庫 Database changed mysqlSHOW TABLES; # 查看 mysql 這個資料庫裡有多少個資料表 + ----------------- + | Tables_in_mysql | + ----------------- + | columns_priv | | db | | func | | host | | tables_priv | | user | + ----------------- + mysqlDESC db; # 可查看 db 資料表型態 mysqlSELECT * FROM db; # 可查看 db 資料表內所插入的所有內容 mysqlSELECT * FROM user; # 可查看 user 資料表內所插入的所有內容 mysqlUSE postfix; # 切換到 postfix 資料庫 Database changed mysqlSHOW TABLES; # 查看 postfix 資料庫中的所有資料表 + ------------------- + | Tables_in_postfix | + ------------------- + | admin | | alias | | domain | | domain_admins | | log | | mailbox | | vacation | + ------------------- + mysqlSELECT * FROM domain; # 查看 domain 資料表內的資料 Setp 7. 再加裝 Squirrelmail 之 WebMail #cd /usr/ports/mail/squirrelmail/ # 安裝松鼠 webmail 的主程式,外掛程式需獨立抓取套件安裝 #make install Options for php4-mbstring 4.4.0 [X] REGEX Enable multibyte regex support #vi /usr/local/etc/php.ini # 修改 php.ini file_uploads = On session.auto_start = 1 #vi /usr/local/etc/apache2/Includes/mine.conf # 再加入 squirrelmail 的路徑到 apache 網頁目錄 Alias /squirrelmail/ "/usr/local/www/squirrelmail/" squirrelmail" Options Indexes AllowOverride AuthConfig Order allow,deny Allow from all #apachectl restart # 重新啟動 apache #chown -R vmail:vmail /var/spool/squirrelmail # 因為 apache 的 User Group 都改 vmail 所以 /var/spool/squirrelmail 也必須跟進 #cd /usr/local/www/squirrelmail # 修改 configure 設定值 #./configure 選 10. Languages 1. Default Language : 的 en_US 改成 zh_TW。 2. Default Charset : 改成 big5 Command Q You have not saved your data. Save? [Y/n]: Y #vi /usr/local/www/squirrelmail/config/config.php # 再次手動修改 config.php 檔,調整到最符合你的需求我只修改 $domain $domain = 'vm.ntut.idv.tw'; ※ Plugins 至官網的 Plugins 頁面 http://www.squirrelmail.org/plugins.php 中抓取三個 plugin 套件,Plugins 安裝套件路徑如下:我將它們放入 Virtual Mail Server 中的 /home/jim 個人目錄下 Visual Additions Quota Usage Download 1.3 quota_usage-1.3-1.2.7.tar.gz Change password Change MySQL Password Download 2.7-1.4.x change_mysqlpass-3.2-1.2.8.tar.gz Miscellaneous Compatibility Download 2.0.1 compatibility-2.0.1.tar.gz #tar -xzvf quota_usage-1.3-1.2.7.tar.gz -C /usr/local/www/squirrelmail/plugins/ # 開始安裝 Quota Usage #cd /usr/local/www/squirrelmail/plugins/quota_usage # 配置 Quota Usage #cp config.php.sample config.php #tar -xzvf compatibility-1.3.tar.gz -C /usr/local/www/squirrelmail/plugins/ #tar -xzvf change_mysqlpass-3.2-1.2.8.tar.gz -C /usr/local/www/squirrelmail/plugins/ #cd /usr/local/www/squirrelmail/plugins/change_mysqlpass #cp config.php.sample config.php #vi config.php # 配置 change_mypass 修改如下 $mysql_database = 'postfix'; $mysql_table = 'mailbox'; $mysql_userid_field = 'username'; $mysql_password_field ='password'; $mysql_manager_id = 'postfix'; $mysql_manager_pw = 'postfix'; $mysql_unixcrypt = 0; //$mysql_MD5crypt = 1; # 如果你的密碼是 MD5 加密的,就把$mysql_MD5crypt = 0;改成$mysql_MD5crypt = 1; $mysql_MD5crypt = 0; $use_ssl_for_password_change = 0; #cd /usr/local/www/squirrelmail #./configure # 啟動 plugins 套件 選擇 8. Plugins 再挑選我們剛剛所添加的三個套件即可 安裝參考資料: http://www.xuki.org/bbs/showthread.php?t=125 http://www.xs4all.nl/~jaspersl/quota/ To Add: 1%26#8231;裝了 change_mysqlpass plugin 套件後, login 到松鼠 WebMail 後出現錯誤,這是由於數據結構不一至所造成的,只要將 /usr/local/www/squirrelmail/plugins/change_mysqlpass/functions.php 的第 129 行 \\註解掉就行了。 Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/local/www/squirrelmail/plugins/change_mysqlpass/functions.php on line 129 2%26#8231;修改 Squirrelmail 中的 Quota Usage 容量方式有兩種: 方式 (一)、用瀏覽器登入 Postfixadmin 的管理頁面,虛擬用戶清單 (限制 (MB)) 10M 修改為:200M ※ 注意:網域名稱清單 =最大容量限制 (MB) 必須要大於 虛擬用戶清單 = 限制 (MB) 才可修改 虛擬用戶清單 的容量限制 如:網域名稱清單 (最大容量限制 300 (MB)) 虛擬用戶清單 (限制 200 (MB)) 方式 (二)、也可手動調整 Console 進去 server 的 mysql 資料表修改 #mysql -uroot -p mysqluse postfix; mysqlupdate mailbox set quota='204800000S' where username='jim@ms2.ntut.idv.tw'; Query OK, 1 row affected (0.10 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql select username,quota from mailbox; + --------------------- + ----------- + | username | quota | + --------------------- + ----------- + | jim@ms2.ntut.idv.tw | 204800000 | | jim@smtp.4wei.us | 10240000 | + --------------------- + ----------- + 2 rows in set (0.00 sec)
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
王朝網路微信公眾號
微信掃碼關註本站公眾號 wangchaonetcn
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有