在C/S 模式下,rsync client连接rsync server的时候通常会卡住一段时间,然后才会开始文件传输,这是为什么呢?
1、问题描述:
发现每次rsync同步文件的时候,rsync client端执行时长偏大,
2、原因分析:
- 服务分布:
IP地址 | 角色 | rsync版本 |
---|---|---|
192.168.0.188 | rsync server | rsync 3.0.6 |
192.168.210.39 | rsync client | rsync 3.0.6 |
- rsync server 端配置:
#Rsync configuration file: /etc/rsyncd.conf
port = 8082
max connections = 300
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
# Remote sync configuration module
[log_dir]
comment = the test file path
path = /tmp/test_logs
use chroot = false
max verbosity = 1
read only = false
list = false
uid = root
gid = root
outgoing chmod = o-w
transfer logging = true
log format = "%o %h [%a] %m (%u) %f %l"
dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
hosts allow = *
- rsync client 连接:
shell> time /usr/bin/rsync -vvv -i -H -S -z -A -a --port=8082 \
./test.log rsync://192.168.0.188/log_dir/
opening tcp connection to 192.168.0.188 port 8082
sending daemon args: --server -vvvlHogDtpArSze.iLs "--log-format=%i" . log_dir/
sending incremental file list
[sender] make_file(test.log,*,0)
send_file_list done
send_files starting
send_files(1, ./test.log)
send_files mapped ./test.log of size 4
calling match_sums ./test.log
<f+++++++++ test.log
sending file_sum
false_alarms=0 hash_hits=0 matches=0
sender finished ./test.log
send_files phase=1
send_files phase=2
send files finished
total: matches=0 hash_hits=0 false_alarms=0 data=4
sent 75 bytes received 27 bytes 3.58 bytes/sec
total size is 4 speedup is 0.04
_exit_cleanup(code=0, file=main.c, line=1039): about to call exit(0)
real 0m28.163s
user 0m0.002s
sys 0m0.003s
- rsync server 端的日志显示:
2016/07/21 09:49:38 [16353] name lookup failed for 192.168.210.39: Temporary failure in name resolution
2016/07/21 09:49:38 [16353] connect from UNKNOWN (192.168.210.39)
2016/07/21 09:49:38 [16353] rsync to log_dir/ from unknown (192.168.210.39)
2016/07/21 09:49:38 [16353] receiving file list
2016/07/21 09:49:38 [16353] "recv unknown [192.168.210.39] log_dir () test.log 4"
2016/07/21 09:49:38 [16353] sent 54 bytes received 97 bytes total size 4
从rsync server端的日志输出我们可以看出来,耗时最长的是“name lookup……”,Google之后发现,rsync server 对连接进来的client ip进行域名反差,这一步导致了延时,在rsync 3.10的版本以后rsync提供了禁用反向搜索的配置项(Disable reverse lookup in rsync daemon):
reverse lookup = no
但是对于早期的版本,由于rsync本身不支持禁用reverse lookup,所以我们可以通过在rsync server段绑定client的IP地址来解决上述问题:
### rsync server 添加 hosts
echo -e "192.168.210.39\tclient" >> /etc/hosts
然后重新运行rsync命令:
- client 连接:
shell> opening tcp connection to 192.168.0.188 port 8082
sending daemon args: --server -vvvlHogDtpArSze.iLs "--log-format=%i" . log_dir/
sending incremental file list
[sender] make_file(test.log,*,0)
send_file_list done
send_files starting
send_files phase=1
send_files phase=2
send files finished
total: matches=0 hash_hits=0 false_alarms=0 data=0
sent 31 bytes received 8 bytes 78.00 bytes/sec
total size is 4 speedup is 0.10
_exit_cleanup(code=0, file=main.c, line=1039): about to call exit(0)
real 0m0.137s
user 0m0.002s
sys 0m0.002s
- server 端日志显示:
2016/07/21 10:05:01 [16360] connect from client (192.168.210.39)
2016/07/21 10:05:01 [16360] rsync to log_dir/ from client (192.168.210.39)
2016/07/21 10:05:01 [16360] receiving file list
2016/07/21 10:05:01 [16360] sent 35 bytes received 53 bytes total size 4
可以看出,此时rsync client传输文件的时长从28s降到了0.1s。
暂无评论