- 论坛徽章:
- 0
|
SUSE与RedHat间数据同步实练
server(SUSE 10):192.168.1.113
client(RedHat 4 AS):192.168.1.106
目的:实现106的/www/study目录下的文件每隔20分钟与113的/www/study目录下的文件同步
一、配置服务端(192.168.1.113)
tian:/etc # vi rsyncd.conf
uid = users
gid = users
read only = true
use chroot = true
transfer logging = true
log format = %h %o %f %l %b
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
hosts allow = 192.168.1.106
hosts deny = 192.168.1.117
slp refresh = 300
#[Example]
# path = /home/Example
# comment = An Example
# auth users = user
# secrets file = /etc/rsyncd.secrets
[www]
comment = web directory rsync
path = /www
auth users = root
secrets file = /etc/rsyncd.secrets
tian:/etc/init.d # ./rsyncd restart
Shutting down rsync daemon done
Starting rsync daemon done
tian:/etc/init.d #
二、客户端只需要安装rsync即可
三、在客户端配置SSH
[root@shanghai ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ---直接回车,下同
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
a6:1d:98:be:ff:85:36:8f:9e:53:58:57:8a:1a:1e:d2
root@shanghai.test.com
[root@shanghai ~]#
[root@shanghai .ssh]# scp id_rsa.pub
root@192.168.1.113
:
Password:
id_rsa.pub 100% 232 0.2KB/s 00:00
[root@shanghai .ssh]#
tian:~ # cat id_rsa.pub >> .ssh/authorized_keys
四、在客户端上建立任务脚本
[root@shanghai ~]# vi /usr/bin/wwwrsync.sh
#!/bin/bash
rsync -vazu --progress --delete /www/study
[email=root@192.168.1.113:/www]root@192.168.1.113:/www[/email]
[root@shanghai ~]# cd /www/study/
[root@shanghai study]# ls
[root@shanghai study]# touch aa bb cc dd
[root@shanghai study]# ls
aa bb cc dd
[root@shanghai study]# cd
[root@shanghai ~]# cd /usr/bin/
五、在客户端自动同步测试
[root@shanghai bin]# ./wwwrsync.sh
building file list ...
5 files to consider
study/
study/aa
study/bb
study/cc
study/dd
sent 237 bytes received 100 bytes 674.00 bytes/sec
total size is 0 speedup is 0.00
六、在服务端检查测试是否成功
tian:/www/study # ls
aa bb cc dd
tian:/www/study #
七、在客户端使用crontab来定时调用该脚本
[root@shanghai ~]# crontab -e
no crontab for root - using an empty one
*/20 * * * * /usr/bin/wwwrsync.sh
~
[root@shanghai init.d]# ./crond restart
Stopping crond: [ OK ]
Starting crond: [ OK ]
[root@shanghai init.d]#
八、测试
在客户端
[root@shanghai ~]# cd /www/study/
[root@shanghai study]# ls
aa bb cc dd
[root@shanghai study]# rm aa
rm: remove regular empty file `aa'? y
[root@shanghai study]# ls
bb cc dd
[root@shanghai study]# touch ee ff kk
[root@shanghai study]# ls
bb cc dd ee ff kk
十分钟后,在服务端
tian:/www/study # ls
bb cc dd ee ff kk
这个时候会在客户端上收到一封邮件如下
You have mail in /var/spool/mail/root
[root@shanghai study]# mail -u root
Mail version 8.1 6/6/93. Type ? for help.
"/var/mail/root": 1 message 1 new
>N 1
root@shanghai.test.c
Mon Jul 13 16:30 31/990 "Cron "
& 1
Message 1:
From
root@shanghai.test.com
Mon Jul 13 16:30:02 2009
Date: Mon, 13 Jul 2009 16:30:02 +0800
From:
root@shanghai.test.com
(Cron Daemon)
To:
root@shanghai.test.com
Subject: Cron /usr/bin/wwwrsync.sh
Content-Type: text/plain; charset=UTF-8
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
building file list ...
7 files to consider
deleting study/aa
study/
study/ee
study/ff
study/kk
sent 230 bytes received 80 bytes 620.00 bytes/sec
total size is 0 speedup is 0.00
& quit
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93765/showart_2030043.html |
|