拓扑:

rsync传输查看进度_网络

服务端配置:rsync的配置文件是/etc/rsyncd.conf。注意这个文件默认是不存在的,需要手动创建。

下面是一个配置好的rsyncd.conf
######rsyncd.conf#######
uid = rsync    ----à非系统虚拟用户
gid = rsync
use chroot =no  -à防止出现安全问题
maxconnections = 200   --à最大连接数
timeout = 300           --à超时时间
pid file =/var/run/rsyncd.pid  --à进程pid所在的文件
lock file =/var/run/rsync.lock  -à锁
log file =/var/log/rsyncd.log    -à出错的日志文件
[zhaofan]    --à模块
path = /zhaofan/   à可以理解为共享目录
ignore errors   --à忽略错误
read only =false
list = false     -à是否允许列表
hosts allow =192.168.1.0/24  --à允许的主机
hosts deny =0.0.0.0/32
auth users =rsync_backup      -à虚拟用户
secrets file= /etc/rsync.password    -à用户对应的密码文件
#######rsyncd.config########
以上是对配置文件的配置
启动rsync服务进程:rsync –daemon
Rsync的端口是:873
[root@A ~]#rsync --daemon
[root@A ~]#netstat -lntup|grep 873
tcp        0     0 0.0.0.0:873                0.0.0.0:*                   LISTEN      27933/rsync         
tcp        0     0 :::873                     :::*                        LISTEN      27933/rsync     
 
 
[root@A ~]#cat /var/log/rsyncd.log 
2016/01/0912:03:39 [27933] rsyncd version 3.0.6 starting, listening on port 873
[root@A ~]#     
[root@A ~]#
 
服务启动后需要的操作:
[root@A /]#ls -dl zhaofan
drwxr-xr-x. 2root root 4096 Jan  9 12:06 zhaofan
[root@A /]# useradd rsync -s /sbin/nologin
[root@A /]# chown -R rsync.rsync /zhaofan
 [root@A /]# ls -dl zhaofan
drwxr-xr-x. 2rsync rsync 4096 Jan  9 12:06 zhaofan
[root@A /]#
 
[root@A /]#echo "rsync_backup:zhaofan">/etc/rsync.password
[root@A /]# 
这里 rsync_backup rsync的虚拟用户名,zhaofan
[root@A /]#chmod 600/etc/rsync.password 
[root@A /]#ls -dl /etc/rsync.password 
-rw-------. 1root root 21 Jan  9 12:10/etc/rsync.password
同时需要关掉selinx和防火墙
以上所有的服务端的配置都配置好了
下面是客户端配置
echo"zhaofan">/etc/rsync.password
[root@B ~]#chmod 600/etc/rsync.password
到现在为止,所有的配置都配置好了
注意:rsync的命令一定是在客户端进行操作的。
       Access via remote shell:
         Pull: rsync [OPTION...][USER@]HOST:SRC... [DEST]
         Push: rsync [OPTION...] SRC...[USER@]HOST:DEST
 
       Access via rsync daemon:
         Pull: rsync [OPTION...][USER@]HOST::SRC... [DEST]
               rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC...[DEST]
         Push: rsync [OPTION...] SRC...[USER@]HOST::DEST
               rsync [OPTION...] SRC...rsync://[USER@]HOST[:PORT]/DEST
 
 
在客户端上验证拉结果
[root@ru /]#rsync -avz rsync_backup@192.168.1.100::zhaofan /data
Password: 
receivingincremental file list
./
a
b
c
d
e
f
g
 
sent 207bytes  received 413 bytes  248.00 bytes/sec
total size is7  speedup is 0.01
[root@ru /]#
 
下面是推到服务器上
[root@rudata]# touch {1..10}
[root@rudata]# ls
1  10 2  3  4 5  6  7 8  9  a b  c  d e  f  g
[root@rudata]# rsync -avz /data/ rsync_backup@192.168.1.100::zhaofan 
Password: 
sendingincremental file list
./
1
10
2
3
4
5
6
7
8
9
 
sent 536bytes  received 201 bytes  294.80 bytes/sec
total size is7  speedup is 0.01
[root@rudata]#
如果想在过程中不用输入密码的方法:
[root@rudata]# rsync -avz rsync_backup@192.168.1.100::zhaofan /data --password-file=/etc/rsync.password
receivingincremental file list
./
10
11
12
13
14
15
 
sent 182bytes  received 590 bytes  1544.00 bytes/sec
total size is7  speedup is 0.01
[root@rudata]#
这样在过程中就不需要输入密码了


https://blog.51cto.com/8713732/1733650