<--目录-->
1)Rsync解析
2)Rsync配置
【Rsync解析】
rsync同步操作
-a 归档模式,相当于-rlptgoD
-r:递归,包括目录/子目录及所有文件
-l:保留符号链接文件
-p -t:保留文件的权限、时间标记
-o、-g: 保留设备文件及其他特殊文件
-v 显示同步过程详细信息
-z 传输过程中启用压缩
-H 保留硬连接文件
-A 保留文件的ACL属性信息
- --delete: 删除目标有而源没有的文件
- --checksum:根据校验和来决是否要同步
- --password-file=:指定认证口令文件
- --progress 可以看到传输的进度和速度的,同时也包括余下未同步的文件的数量的
rsync+ssh同步 ->隧道加密传输
- 下行:rsync -avz user@host:源目录 目标目录
- 上行:rsync -avz 源目录 user@host:目标目录
【Rsync配置】
基于本地rsync同步
#mkdir /todir
#rsync -a /boot /todir
#ls /todir
#rm -rf /todir/*
#ls /todir
#rsync -a /boot/ /todir/
#ls /todir
rsync -av /boot/ /todir/ --delete
实验总结
#rsync -a /boot /todir 拷贝目录
#rsync -a /boot/ /todir/ 拷贝目录下的文件
#rsync -av /boot/ /todir/ --delete -v查看过程 --delete删除源没有目标有的文件
基于ssh服务的rsync同步
#mkdir /fromssh
#rsync -az root@192.168.2.1:/boot/ /fromssh/
#rsync -az /etc root@192.168.194.25:/opt/
基于rsync服务的rsync同步
服务器端192.168.2.1
#rpm -q rsync
#vi/ /etc/rsyncd_users.db
ruser:pwd@123
#chmod 600 /etc/rsyncd_users.db
#vi /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
[tools]
path = /usr/src/
read only = yes
dont compress =*.gz *.bz2 *.tgz *.zip
auth users = ruser
secrets file = /etc/rsyncd_users.db
#chkconfig rsync on
#service xinetd restart
#netstat -ln | grep :873
客户端
#rsync ruser@192.168.2.1::tools //浏览共享
#mkdir -p /data/fromrsnc/
#rsync -avz --delete ruser@192.168.2.1::tools /data/fromrsync/ //下行同步
上行同步操作
服务器端
cat /etc/rsyncd.conf
...
path = /usr/src/
read only = no
...
#chown nobody:nobody /usr/src/
客户端
#rsync -avz --delete /data/fromrsync/ ruser@192.168.2.1::tools
出错
#防火墙没关闭
#SElinux没关闭
#文件权限没有修改 chmod 600 /etc/rsyncd_users.db
#/etc/xinetd.d/rsync chkconfig rsync on
disable = yes
生产环境配置:
Rsync IP:192.168.16.1
客户端:192.168.16.2
[yaowan-kingdom3]
path = /ryzc/kingdom3/
auth users = rydfh
uid = root
gid = root
secrets file = /etc/rsyncd.pass
read only = no
启动rsync
法1:
[root@10-8-10-180 log]# cd /etc/xinetd.d/
[root@10-8-10-180 xinetd.d]# rsync -daemon
法2:
[root@10-8-10-180 xinetd.d]# yum -y install xinetd
[root@10-8-10-180 xinetd.d]# service xinetd start
[root@10-8-10-180 xinetd.d]# netstat -tulnp | grep 873
生产环境配置:
Rsync IP:192.168.16.1
客户端:192.168.16.2
Rsync服务器端
rsyncd配置文件
[root@mndg248 opt]# head -11 /etc/rsyncd.conf
hosts allow=192.168.16.2 #只允许这个IP对我进行同步
hosts deny=* #其他拒绝
auth users = ryzc #全局验证用户ryzc
list = no #不能用rsync打印配置文件列表
[wsyht-website]
path = /wsyht/wsyht-website/
auth users = wsyht #局部验证账户
uid = root
gid = root
secrets file = /etc/wsyht.pass #密码文件路径
read only = no
密码文件:
[root@mndg248 opt]# cat /etc/wsyht.pass
wsyht:test-wsyht-Rsyc #前账户,后密码
[root@mndg248 opt]# chmod 600 /etc/wsyht.pass
客户端操作:
[root@ryzc32 ~]# cat /DFH3/script/rsync-dfh-platform-to-114.sh
#!/bin/bash
ip='192.168.16.1'
ryzc_path=$(cd "$(dirname "$0")"; pwd)/
#同步推送
echo 'rsync push....'
rsync -avzP --ignore-errors --delete --exclude=*.svn --exclude=*.war --exclude=u8server/target/ /DFH3/dfh3-platform/interaction wsyht@$ip::wsyht-website --password-file=/wsyht/rsyncd.secrets
[root@ryzc32 ~]# cat /wsyht/rsyncd.secrets
wsyht:test-wsyht-Rsyc #用户密码必须跟Rsync服务器端的一致
[root@ryzc32 ~]# chmod 600 /wsyht/rsyncd.secrets
报错1:
报无法找到主机路由
解决方法:
设置防火墙允许873端口进来
报错2:
没有找到密码文件
觖决方法:
本地密码文件跟rsync机器密码文件内容密码不一致
报错3:
执行同步时提示输入密码
解决方法:
本地和rsync服务器密码文件给600权限
本地和远程服务器的文件所有者所属组权限给的不一致
报错4:
rsync服务器上没有创建同步目录 [root@localhost yaowan-market-ads]# sh /ryzc/scripts/yaowan-market-ads-172.sh
rsync push....
@ERROR: chroot failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
解决方法:在rsync服务器上创建同步目录
SVN结合Rsync做服务器同步,保证线上服务器跟本地代码内容一致
转载于:https://blog.51cto.com/yht1990/1790548