rsync 应用总结
rysnc server端
1、vim /etcrsyncd.conf (用户rsync,目录,模块,非系统虚拟用户及密码文件)
2、创建共享目录 /data/www/{www,bbs,blog}
3、创建rsync用户,并授权访问/data/www/
4、创建密码文件,复制配置文件里的路径,然后添加密码内容:‘’虚拟用户名:密码‘’
5、密码文件权限600 chmod 600 /etc/rsync.password
6、rsync --daemon 启动rysnc进程,然后放入/etc/rc.local 开机自启
7、tail /var/log/rsyncd.log 查看rsync运行log
服务器端rsync重启服务
1、 pkill rsync
2、 kill `cat /var/run/rsyncd.pid`
rsync --daemon
查看是否是启动rsync服务
ps -ef|grep rsync
netstat -lnt |grep 873
lsof -i:873
rsync client端
1、密码文件和服务端没有任何关系。命令是--password-file=/etc/rsync.password
2、密码文件内容:‘’密码‘’
3、密码文件权限600 chmod 600 /etc/rsync.password
语法:
pull:
rysnc -avz rsync_backup@10.0.0.11::www /data --password-file=/etc/rsync.password
push
rsync -avz /data/ rsync_backup@10.0.0.11::www --password-file=/etc/rsync.password
排错:
1、防火墙和selinux
2、/var/log/rsyncd.log
3、整个部署流程整体考虑排查
4、操作习惯当做一个大事。如rsyncd.conf的内容都复制一份,部署时直接复制粘贴使用;定位文件时尽可能使用tab补全;使用命令脚本时,先测试脚本本地单独运行没有问题,然后再复制粘贴到脚本中,尽量减少手打。
/etc/rsyncd.conf
##rsyncd.conf start## uid = rsync gid = rsync use chroot = no max connections = 2000 timeout = 600 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log ignore errors read only = false list = false hosts allow = 10.0.0.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password ## Module 1 ## [www] comment = www added by jp at 2019/5/10 9:39 path = /data/www/www/ ## Module 2 ## [bbs] comment = www added by jp at 2019/5/10 9:40 path = /data/www/bbs/ ##################################### [blog] comment = blog added by jp at 2019/5/10 9:41 path = /data/www/blog/
排错
1、rsync: chgrp ".passwd.DKh65W" (in backup) failed: Operation not permitted (1)
[root@nfs01-31 tmp]# rsync -avz /etc/passwd rsync_backup@172.16.1.41::backup
Password:
sending incremental file list
passwd
rsync: chgrp ".passwd.DKh65W" (in backup) failed: Operation not
permitted (1)
sent 524 bytes received 125 bytes 432.67 bytes/sec
total size is 1,022 speedup is 1.57
rsync error: some files/attrs were not transferred (see previous errors) (code
23) at main.c(1178) [sender=3.1.2]
这个可能是配置文件里面没有加fake super = yes
在以前的版本里面不需要,现在版本需要
2、sending incremental file list
rsync: failed to write xattr user.rsync.%stat for "." (in server10): Permission denied (13)
rsync: failed to set times on "." (in server10): Operation not permitted (1)
原因:在rsync服务器端,rsync在模块的目标文件夹中没有权限
3、@ERROR: Unknown module 'sipbackup'
rsync error: error starting client-server protocol (code 5) at main.c(1648) [sender=3.1.2]
原因:
这个报错是因为hosts allow配置的有问题
检查了一下发现把192.168.40.0/24 写成了192.168.40.0\24
4、elastixbackup-20191215105901-ab.tar
42,352,640 100% 17.16MB/s 0:00:02 (xfr#1, to-chk=0/1)
rsync: mkstemp "/NC/.elastixbackup-20191215105901-ab.tar.FcBWez" (in sipbackup) failed: Permission denied (13)
原因:服务器端的文件夹没有权限。
解决方法:drwxr-xr-x 2 rsync rsync 48 Dec 20 13:58 DMZ
drwxr-xr-x 2 root root 6 Dec 19 15:47 NC
drwxr-xr-x 2 rsync rsync 48 Dec 18 00:16 ALG
drwxr-xr-x 2 rsync rsync 48 Dec 18 00:02 XA
drwxr-xr-x 2 rsync rsync 48 Dec 18 00:02 SZ
drwxr-xr-x 2 rsync rsync 48 Dec 18 00:02 SUZ
drwxr-xr-x 2 rsync rsync 48 Dec 18 00:00 SH
chmod -R rsync.rsync /NC