rsync 简介
rsync 是一个远程数据同步工具,Rsync算法只传送两个文件的不同部分,而不是每次都整份传送。
rsync 安装:
- 下载:rsync.samba.org/
- 解压:tar zxvf rsync-3.1.3.tar.gz
- cd rsync-3.1.3
- ./configure --prefix=/usr/local/rsync
- make && make install (需 root 权限下运行)

rsync 配置
查看 rsync 是否存活
ps -ef | grep rsync
启动 rsync
rsync --daemon --config=/etc/rsyncd.conf
rsync 配置文件位置
vim /etc/rsyncd.conf
rsync 配置内容
port = 888 #监听TCP888 端口
uid = root
gid = root #必须是系统存在的组名
max connections = 200 #最大连接数
timeout = 600 #超时时间,客户端 300 秒之内连不上,则不再等待
use chroot = no
read only = yes #如果为 ture,则不允许上传
pid file =/var/run/rsyncd.pid
hosts allow = * #192.168.92.129,192.168.92.131 * 表示所有,可以指定网段或者一个 ip
[rsync_id] # 模块名
comment = rain 的空间
list = no
read only = no
path = /home/rain #该模块访问的路径
免密备份
如果不配置下面两行,可以免密码备份文件
#auth users = nomanno #随便起名
#secrets file = /home/noman/rsyncd.secrets
rsyncd.secrets 的权限改为 600 存放密码地方格式一行一个 用户名:密码,如 rain:123456
如果配置了下面两行,在客户端的 /usr/local/rsync/etc/rsyncd.pass 文件里的内容与上面 rsyncd.secrets 的内容一样,rsyncd.pass 权限需改为 600
rsync 使用
同步命令
上传 push
rsync -vzrtopg --progress ./test.tar.gz root@10.10.11.11::rsync_id
下载 pull
rsync -vzrtopg --progress root@10.10.11.11::rsync_id/test.tar.gz ./
附压缩解压命令
压缩
tar –cvf jpg.tar *.jpg //将目录里所有jpg文件打包成tar.jpg
tar –czf jpg.tar.gz *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩,生成一个gzip压缩过的包,命名为jpg.tar.gz
tar –cjf jpg.tar.bz2 *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用bzip2压缩,生成一个bzip2压缩过的包,命名为jpg.tar.bz2
tar –cZf jpg.tar.Z *.jpg //将目录里所有jpg文件打包成jpg.tar后,并且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg.tar.Z
解压缩
tar –xvf file.tar //解压 tar包
tar -xzvf file.tar.gz //解压tar.gz
tar -xjvf file.tar.bz2 //解压 tar.bz2
tar –xZvf file.tar.Z //解压tar.Z
unrar e file.rar //解压rar
unzip file.zip //解压zip