多台阿里云的机器,只有一台跳板机有外网地址,所以在跳板机上pull代码, 而后用 rsync 同步到其余内网的机器。此处用跳板机作rsync客户端, 其余机器作rsync服务端, 从跳板机往内网机上推文件。html
基本用法shell
从本地传输到远程 rsync source host:destination rsync source host::destination 从远程传输到本地 rsync host:source destination rsync host::source destination
rsync有2种不一样的工做模式:vim
rsync --daemon
使用独立进程的方式,或者经过xinetd超级进程来管理rsync后台进程。
将source目录下的内容复制到destination目录下 rsync -r source/ destination rsync -r source/. destination 若是source后不跟斜线,则会在destination下新建一个名为source的目录. destination后有无斜线结果不受影响 使用时二者后都加上斜线,便于记忆
$ tree a a ├── b │ ├── c │ └── cc.data ├── b.data └── bb.data $ rsync -r a a1 $ tree a1 a1 └── a ├── b │ ├── c │ └── cc.data ├── b.data └── bb.data $ rsync -r a/ a2 #(或 rsync -r a/. a2) $ tree a2 a2 ├── b │ ├── c │ └── cc.data ├── b.data └── bb.data
经常使用选项:segmentfault
-a 等于 -rlptgoD -r 是递归 -l 是连接文件,意思是拷贝连接文件; -p 表示保持文件原有权限 -t 保持文件原有时间; -g 保持文件原有用户组 -o 保持文件原有属主; -D 至关于块设备文件 -z 传输时压缩; -P 等于 --partial --progress --partial 保留那些因故没有彻底传输的文件,以是加快随后的再次传输 --progress 进度 -v 详细输出信息
rsync 服务端配置bash
vim /etc/rsyncd.confssh
uid=用户名user1 gid=用户组group1 use chroot=yes max connections=10 timeout=600 strict modes=yes port=873 pid file=/var/run/rsyncd.pid lock file=/var/run/rsyncd.lock log file=/var/log/rsyncd.log [模块名mod1] path=/home/user1/code/ comment=注释 code file needed sync read only=no hosts allow=10.0.3.2 hosts deny=0.0.0.0/32 [模块名mod2] path=/home/user1/pypi/ comment=pip source file read only=no hosts allow=10.0.3.2 hosts deny=0.0.0.0/32
vim /etc/rsyncd.secrets, 密码和用户的系统密码没有关系socket
user1:password
vim /etc/xinetd.d/rsync, 用xinetd 管理 rsync 服务ui
service rsync { disable = no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID }
chkconfig rsync on阿里云
service xinetd restartrest
客户端配置
vim /etc/rsync_client.pwd
填入rsync服务端的密码
手动同步
rsync -avzP --delete --password-file=/etc/rsync_client.pwd /home/user1/code/ user1@10.0.3.3::mod1 rsync -avzP --delete --password-file=/etc/rsync_client.pwd /home/user1/pypi/ user1@10.0.3.3::mod2
参考文章:
http://seanlook.com/2014/12/12/rsync_inotify_setup/
https://download.samba.org/pub/rsync/rsyncd.conf.html
http://ltblog.blog.51cto.com/1263616/859216
https://segmentfault.com/a/1190000000444614