courier邮件服务器域名变更

来源:互联网 发布:网络创世纪版本介绍 编辑:程序博客网 时间:2024/04/29 11:34

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的邮箱路径,利用数据库生成修改脚本
mysql@211.68.29.200: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的邮箱路径,利用数据库生成修改脚本
mysql@211.68.29.200: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数据库中的域名后缀
mysql@211.68.29.200: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
mysql@211.68.29.200:maildb> commit;

 

10.变更[s03.test.net] ==> s03.test.com.cn,过程如下:
(10.1).更改MAIL的邮箱路径,利用数据库生成修改脚本
mysql@211.68.29.200: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数据库中的域名后缀
mysql@211.68.29.200: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).mysql@211.68.29.200: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           |
+--------------------------+----------+------------------+
| cam@test.test.com.cn     | cam@     | test.test.com.cn |
| gdhw001@test.test.com.cn | gdhw001@ | test.test.com.cn |
| wangtao@test.test.com.cn | 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           |
+----------------------------------+------------------+------------------+
| admin_xdz200410@new1.test.com.cn | admin_xdz200410@ | new1.test.com.cn |
+----------------------------------+------------------+------------------+
1 row in set (0.03 sec)

至此,升级现有邮件部分完成。

 

原创粉丝点击