courier是一個開源的mail server,在我們平臺中採用,對於他的升級過程共大家共享,轉載請註明出處.
說明:
[xxx@xxxx]# 表示在linux命令行下的命令,@後爲主機名或主機IP
shell> 表示在linux命令行下的命令
shell@xxxx> 表示在linux命令行下的命令,@後爲主機名或主機IP
mysql> 表示在mysql環境下的執行
mysql:maildb> 表示在mysql環境下,選擇maildb數據庫後執行
1.先在192.168.100.11進行了充分的實驗後,再進行實際運行環境的email的更新操作
針對XXX網的實際環境,做如下email域名更新:
2.用SecureCRT 4.0登錄proxy,從該機登錄其他幾機器
(2.1).登錄email服務器,打開兩個窗口,一個mysql,另外一個shell
shell@proxy> ssh root@courier
shell@courier> /usr/lib/courier/mysqldb/bin/mysql -P3309 -S/usr/lib/courier/mysqldb/var/mysql.sock -udba -pwebmail
mysql> use maildb;
mysql:maildb>
(2.2).登錄WEB服務器
shell@proxy> ssh root@WEB
[root@WEB root]#
3.在mail服務器上mysql窗口中
(3.1).以home中的域名爲線索統計各種不同的域後綴的用戶數目
mysql:maildb> select count(home),lower(substring(home,locate('@',home) + 1)) domain from passwd group by lower(substring(home,locate('@',home) + 1));
+-------------+------------------+------------------+
| count(home) | domain | 變更 |
+-------------+------------------+------------------+
| 3407 | s01.test.net | s01.test.com.cn |
| 587 | demo.test.net | demo.test.com.cn |
| 1844 | s02.test.net | s02.test.com.cn |
| 2105 | s03.test.net | s03.test.com.cn |
| 3 | test.test.net | test.test.com.cn |
| 1 | new1.test.com.cn | new1.test.com.cn |
| 1 | new2.test.com.cn | new2.test.com.cn |
+-------------+------------------+------------------+
7 rows in set (0.21 sec)
(3.2).其中new1.test.com.cn,new2.test.com.cn不做變更
(3.3).統計var目錄下的mail目錄
shell@courier> cd /var
數據總數爲
shell@courier> find mail? -name "*@*" -type d -maxdepth 1 | wc -l
結果爲7944
(3.4).分別統計各域名的mail目錄,結果見上表
shell@courier> find mail? -name "*@s01.test.com.cn" -type d -maxdepth 1 | wc -l
shell@courier> find mail? -name "*@demo.test.com.cn" -type d -maxdepth 1 | wc -l
shell@courier> find mail? -name "*@s02.test.com.cn" -type d -maxdepth 1 | wc -l
shell@courier> find mail? -name "*@s03.test.com.cn" -type d -maxdepth 1 | wc -l
shell@courier> find mail? -name "*@test.test.com.cn" -type d -maxdepth 1 | wc -l
shell@courier> find mail? -name "*@new1.test.com.cn" -type d -maxdepth 1 | wc -l
shell@courier> find mail? -name "*@new2.test.com.cn" -type d -maxdepth 1 | wc -l
4.升級前的準備工作
(4.1).實際更改之前,首先要停止courier服務
shell@courier> /usr/lib/courier/scripts/mscntl stop
(4.2).爲了防止在操作的過程中有創建用戶的現象出現,要關閉web服務中與mail創建有關的功能,當然最好是關閉web服務器
如果兩個單位使用相同的域名,而兩個單位可以存在相同名稱的用戶,則可能導致用戶的mail完全相同,也就是兩個用戶共享一個mail,這是不合適的,所以,請大家在建立測試的單位時,請不要使用正式單位的mail域。
(4.3).對於正式的單位,一定要使用不同的mail後綴。
(4.4).確定腳本位置:/home/courier
(4.5).確定變更順序並書寫腳本
+--------------------+------------------+
| DOMAIN1 | change to |
+--------------------+------------------+
| [s01.test.net] | s01.test.com.cn |
| [demo.test.net] | demo.test.com.cn |
| [s02.test.net] | s02.test.com.cn |
| [s03.test.net] | s03.test.com.cn |
| [test.test.net] | test.test.com.cn |
+--------------------+------------------+
(4.6).更改dns,新建域並設置MX記錄,刪除舊的DNS
(4.7).統一變更域名
5.統一變更域名
更改hostdomains文件,向其中增加新的域名後綴,並刪除舊的域名,執行/usr/lib/courier/share/makehostdomains
shell@courier> vi /usr/lib/courier/etc/hosteddomains
修改s01.test.net爲s01.test.com.cn
修改demo.test.net爲demo.test.com.cn
修改s02.test.net爲s02.test.com.cn
修改s03.test.net爲s03.test.com.cn
修改test.test.net爲test.test.com.cn
shell> /usr/lib/courier/share/makehosteddomains
6.郵件域名變更
mysql> select vdid,description from tbl_VDInfo;
+------------------+------------------+
| vdid | description |
+------------------+------------------+
| s02.test.net | s02.test.net |
| s03.test.net | s03.test.net |
| demo.test.net | demo.test.net |
| s01.test.net | s01.test.net |
| test.test.net | test.test.net |
| new2.test.com.cn | new2.test.com.cn |
| new1.test.com.cn | new1.test.com.cn |
+------------------+------------------+
7 rows in set (0.00 sec)
mysql@courier:maildb> update set vdid=''
update tbl_VDInfo set vdid=concat(left(vdid,locate('.',vdid)),'test.com.cn'),
description=concat(left(description,locate('.',description)),'test.com.cn') where lower(substring(vdid,locate('.',vdid) + 1))='test.net';
7.變更[s01.test.net] ==> s01.test.com.cn,過程如下:
(7.1).更改MAIL的郵箱路徑,利用數據庫生成修改腳本
[email protected]:maildb> select concat('mv ''',home,''' ''',concat(left(home,locate('@',home)),'s01.test.com.cn'),'''') movecmd from passwd where lower(substring(home,locate('@',home) + 1))='s01.test.net' into outfile '/home/courier/s01.test.net.sh';
Query OK, 3411 rows affected (0.04 sec)
shell@courier> cd /home/courier
shell@courier> chmod +x s01.test.net.sh
shell@courier> ./s01.test.net.sh
(7.2).更改MAIL數據庫中的域名後綴
mysql@courier:maildb> update passwd set id=concat(left(id,locate('@',id)),'s01.test.com.cn'),
home=concat(left(home,locate('@',home)),'s01.test.com.cn'),
maildir=concat(left(maildir,locate('@',maildir)),
's01.test.com.cn',
substring(maildir,locate('/',maildir,locate('@',maildir) + 1)))
where lower(substring(id,locate('@',id) + 1))='s01.test.net';
Query OK, 3411 rows affected (0.20 sec)
Rows matched: 3411 Changed: 3411 Warnings: 0
mysql@courier:maildb> commit;
8.變更[demo.test.net] ==> demo.test.com.cn,過程如下:
(8.1).更改MAIL的郵箱路徑,利用數據庫生成修改腳本
mysql@courier:maildb> select concat('mv ''',home,''' ''',concat(left(home,locate('@',home)),'demo.test.com.cn'),'''') movecmd from passwd where lower(substring(home,locate('@',home) + 1))='demo.test.net' into outfile '/home/courier/demo.test.net.sh';
Query OK, 587 rows affected (0.03 sec)
shell> cd /home/courier
shell> chmod +x demo.test.net.sh
shell> ./demo.test.net.sh
(8.2).更改MAIL數據庫中的域名後綴
mysql@courier:maildb> update passwd set id=concat(left(id,locate('@',id)),'demo.test.com.cn'),
home=concat(left(home,locate('@',home)),'demo.test.com.cn'),
maildir=concat(left(maildir,locate('@',maildir)),
'demo.test.com.cn',
substring(maildir,locate('/',maildir,locate('@',maildir) + 1)))
where lower(substring(id,locate('@',id) + 1))='demo.test.net';
Query OK, 587 rows affected (0.05 sec)
Rows matched: 587 Changed: 587 Warnings: 0
mysql@courier:maildb> commit;
9.變更[s02.test.net] ==> s02.test.com.cn,過程如下:
(9.1).更改MAIL的郵箱路徑,利用數據庫生成修改腳本
[email protected]:maildb> select concat('mv ''',home,''' ''',concat(left(home,locate('@',home)),'s02.test.com.cn'),'''') movecmd from passwd where lower(substring(home,locate('@',home) + 1))='s02.test.net' into outfile '/home/courier/s02.test.net.sh';
Query OK, 1844 rows affected (0.02 sec)
shell> cd /home/courier
shell> chmod +x s02.test.net.sh
shell> ./s02.test.net.sh
(9.2).更改MAIL數據庫中的域名後綴
[email protected]:maildb> update passwd set id=concat(left(id,locate('@',id)),'s02.test.com.cn'),
home=concat(left(home,locate('@',home)),'s02.test.com.cn'),
maildir=concat(left(maildir,locate('@',maildir)),
's02.test.com.cn',
substring(maildir,locate('/',maildir,locate('@',maildir) + 1)))
where lower(substring(id,locate('@',id) + 1))='s02.test.net';
Query OK, 1844 rows affected (0.12 sec)
Rows matched: 1844 Changed: 1844 Warnings: 0
[email protected]:maildb> commit;
10.變更[s03.test.net] ==> s03.test.com.cn,過程如下:
(10.1).更改MAIL的郵箱路徑,利用數據庫生成修改腳本
[email protected]:maildb> select concat('mv ''',home,''' ''',concat(left(home,locate('@',home)),'s03.test.com.cn'),'''') movecmd from passwd where lower(substring(home,locate('@',home) + 1))='s03.test.net' into outfile '/home/courier/s03.test.net.sh';
Query OK, 2105 rows affected (0.02 sec)
shell> cd /home/courier
shell> chmod +x s03.test.net.sh
shell> ./s03.test.net.sh
出錯了,大概7個人沒有,其中一個叫wangguohua,但幾他幾個沒有記住
(10.2).更改MAIL數據庫中的域名後綴
[email protected]:maildb> update passwd set id=concat(left(id,locate('@',id)),'s03.test.com.cn'),
home=concat(left(home,locate('@',home)),'s03.test.com.cn'),
maildir=concat(left(maildir,locate('@',maildir)),
's03.test.com.cn',
substring(maildir,locate('/',maildir,locate('@',maildir) + 1)))
where lower(substring(id,locate('@',id) + 1))='s03.test.net';
Query OK, 2105 rows affected (0.12 sec)
Rows matched: 2105 Changed: 2105 Warnings: 0
mysql:maildb> commit;
11.變更[test.test.net] ==> test.test.com.cn,過程如下:
(11.1).更改MAIL的郵箱路徑,利用數據庫生成修改腳本
mysql:maildb> select concat('mv ''',home,''' ''',concat(left(home,locate('@',home)),'test.test.com.cn'),'''') movecmd from passwd where lower(substring(home,locate('@',home) + 1))='test.test.net' into outfile '/home/courier/test.test.net.sh';
Query OK, 3 rows affected (0.02 sec)
shell> cd /home/courier
shell> chmod +x test.test.net.sh
shell> ./test.test.net.sh
(11.2).更改MAIL數據庫中的域名後綴
mysql:maildb> update passwd set id=concat(left(id,locate('@',id)),'test.test.com.cn'),
home=concat(left(home,locate('@',home)),'test.test.com.cn'),
maildir=concat(left(maildir,locate('@',maildir)),
'test.test.com.cn',
substring(maildir,locate('/',maildir,locate('@',maildir) + 1)))
where lower(substring(id,locate('@',id) + 1))='test.test.net';
Query OK, 3 rows affected (0.02 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql:maildb> commit;
12.變更後
(12.1)[email protected]:maildb> commit;
(12.3).啓動courier郵件服務器
(14.4).測試變更後的郵件是否正常
mysql:maildb> select id,left(id,locate('@',id)) user,lower(substring(id,locate('@',id) + 1)) domain from passwd where lower(substring(id,locate('@',id) + 1))='test.test.com.cn';
從該用戶向自己、內部用戶、外部mail帳號發一封mail
接受自己、內部、外部發來的mail
+--------------------------+----------+------------------+
| id | user | domain |
+--------------------------+----------+------------------+
| [email protected] | cam@ | test.test.com.cn |
| [email protected] | gdhw001@ | test.test.com.cn |
| [email protected] | wangtao@ | test.test.com.cn |
+--------------------------+----------+------------------+
3 rows in set (0.03 sec)
select id,left(id,locate('@',id)) user,lower(substring(id,locate('@',id) + 1)) domain from passwd where lower(substring(id,locate('@',id) + 1))='new1.test.com.cn';
+----------------------------------+------------------+------------------+
| id | user | domain |
+----------------------------------+------------------+------------------+
| [email protected] | admin_xdz200410@ | new1.test.com.cn |
+----------------------------------+------------------+------------------+
1 row in set (0.03 sec)
至此,升級現有郵件部分完成。