一、项目描述
Linux 文件级实时复制技术
二、系统环境(linux)天翼云
原机(/opt/david) |
目标机(/opt/david) |
|
弹性IP |
49.75.185.142 837 |
14.18.106.217 837 |
操作系统用户名 |
root |
Root |
操作系统密码 |
Jiangs |
P@ssw0rd |
登录方式 |
ssh |
|
账号/密码 |
N/A |
N/A |
三、迁移步骤
服务端:
linux下检查rsync是否安装命令:
rpm -qa|grep rsync
a. 编辑配置文件
# vi /etc /rsyncd.conf
[root@ecs-c2c4 etc]# cd /etc
[root@ecs-c2c4 etc]# vi rsyncd.conf
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
# GLOBAL OPTIONS
uid = root
gid = root
use chroot = no
read only = yes
#limit access to private LANs
hosts allow=49.75.185.142
hosts deny=*
max connections = 5
pid file = /var/run/rsyncd.pid
secrets file = /etc/rsyncd/rsyncd.secrets
# GLOBAL OPTIONS
uid = root
gid = root
use chroot = no
read only = yes
#limit access to private LANs
hosts allow=49.75.185.142
hosts deny=*
max connections = 5
pid file = /var/run/rsyncd.pid
secrets file = /etc/rsyncd.secrets
# Minimal configuration file for rsync daemon
uid = root
gid = root
use chroot = no
read only = yes
#limit access to private LANs
hosts allow=49.75.185.142
pid file = /var/run/rsyncd.pid
secrets file = /etc/rsyncd.secrets
#lock file = /var/run/rsync.lock
motd file = /etc/rsyncd.motd
#This will give you a separate log file
log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
# MODULE OPTIONS
[davidhome]
path = /opt/david/
list=yes
ignore errors
auth users = rsync
comment = David home
exclude = important/
[chinatmp]
path = /opt/china/
list=no
ignore errors
auth users =
comment = tmp_china
b. 建立/etc/ rsyncd.secrets文件
#cat /etc/ rsyncd.secrets
rsync:123456
c. 为了密码的安全性,我们必须把权限设为600
# chown root:root /etc/ rsyncd.secrets
# chmod 600 /etc/rsyncd.secrets
d. 建立连接到服务器的客户端看到的欢迎信息文件/etc/rsyncd.motd
# vim /etc/rsyncd.motd
[root@ecs-c2c4 rsyncd]# more rsyncd.motd
+++++++++++++++++++++++++++ + wuzy Camp
服务启动方式
对于负荷较重的 rsync 服务器应该使用独立运行方式
# yum install rsync xinetd --服务安装
# /usr/bin/rsync –daemon(service xinetd restart)
# chkconfig rsync on
# netstat -ntpl | grep 873 --查看服务是否启动
测试
1、客户端
环境:14.18.106.217
# yum -y install rsync
# mkdir /opt/davie /opt/china
# [root@ecs-4c54-0001 david]#
rsync -avzP --delete rsync@14.18.106.217::davidhome /opt/david/--让客户端与服务器保持完全一致, --delete
-a --参数,相当于-rlptgoD,
-r --是递归
-l --是链接文件,意思是拷贝链接文件
-i --列出 rsync 服务器中的文件
-p --表示保持文件原有权限
-t --保持文件原有时间
-g --保持文件原有用户组
-o --保持文件原有属主
-D --相当于块设备文件
-z --传输时压缩
-P --传输进度
-v --传输时的进度等信息,和-P有点关系
3、通过密码文件同步
# echo "123456"> /etc/rsync.password
# chmod 600 /etc/rsync.password
# rsync -avzP --delete --password-file=/etc/rsync.password rsync@14.18.106.217::davidhome /opt/david/ --调用密码文件
4、客户端自动同步
# crontab -e
10 0 * * * rsync -avzP --delete --password-file=/etc/rsync.password rsync@14.18.106.217::davidhome /opt/david/
# crontab -l