传统弱校HFUT的蒟蒻,真相只有一个

rsync服务器同步到接收端、反向传输

一、前提需求:

服务器IP:a.b.c.d

接收机IP:w.x.y.z

设置端口:29000

设置模块名:oc_file(一个模块名对应一个同步目录,可指定多个)

设置模块名:op_file(一个模块名对应一个同步目录,可指定多个)

设置传输用户名:oc_pub(一个用户对应一个密码,可以有多个用户)

设置传输密码:oc_12345

设置传输用户名:op_pub(一个用户对应一个密码,可以有多个用户)

设置传输密码:op_56789

设置服务器同步目录:/data/oc

设置服务器同步目录:/data/op

设置接收机接收目录:/root

服务器\接收机安装rsync,确保以上目录都是存在可访问的

二、服务器创建目录树

/data目录下创建rsynced文件夹,cd rsynced

文件夹内包括log目录(必要)、conf目录(必要)

三、创建配置文件./conf/oc_rsyncd.conf

uid = root
gid = root
use chroot = yes
max connections = 1000
timeout = 3000
syslog facility = local5
pid file = ./log/channel_server_rsyncd.pid
lock file = ./log/channel_server_rsync.lock
log file = ./log/channel_server_rsyncd.log
transfer logging = yes
log format = [transfer info] %t %a %u %m %f %o %b
[oc_file]
    path = /data/oc
    comment = op system
    ignore errors = no
    read only = no  
        write only = no
    auth users = oc_pub 
    secrets file = ./conf/channel_server_rsyncd.pwd

[op_file]
     path = /data/op
     comment = op_file
     ignore errors = no
     read only = no
     auth users = op_pub
     secrets file = ./conf/channel_server_rsyncd.pwd

四、创建密码文件./conf/channel_server_rsyncd.pwd

oc_pub:oc_12345
op_pub:op_56789

chmod 600 ./conf/channel_server_rsyncd.pwd 修改密码文件的权限为600

五、创建运行脚本./restart.sh

#!/bin/sh

ps aux | grep rsync | grep daemon | grep '/data/rsynced'  | awk '{print $2}' | xargs -r kill -9
rm -f log/channel_server_rsyncd.pid
/usr/bin/rsync --daemon --config='/data/rsynced/conf/oc_rsyncd.conf'  --port=29000

sh ./restart.sh 启动服务

 

六、接收端服务器上配置

/root下创建文件oc.pwd

oc_12345

/root下创建文件op.pwd

op_56789

chmod 600 oc.pwd

chmod 600 op.pwd

七、接收端从服务器上拉取文件

/*--progress 显示传输进度
--ignore-existing 只传输目标机没有的文件
--remove-source-files 删除服务器上已经传输完毕的文件
--port=21000 指定端口
--password-file 一个文件只写一个密码
rsync://osc_pub@... osc_pub用户名 ...服务器ip*/

rsync -avztopg --progress --ignore-existing --remove-source-files --port=29000 rsync://oc_pub@a.b.c.d/oc_file /root/ --password-file=/root/oc.pwd
rsync -avztopg --progress --ignore-existing --remove-source-files --port=29000 rsync://op_pub@
a.b.c.d/op_file /root/ --password-file=/root/op.pwd

 八、接收端反向推文件到服务器

rsync -avztopg --progress --ignore-existing --remove-source-files --port=29000 /root/test.zip rsync://oc_pub@a.b.c.d/oc_file --password-file=/root/oc.pwd
rsync -avztopg --progress --ignore-existing --remove-source-files --port=29000 /root/test.zip rsync://op_pub@
a.b.c.d/op_file --password-file=/root/op.pwd

 

 发现七比八速度要快几倍,传输完毕。

 

posted @ 2021-09-29 14:22  未名亚柳  阅读(309)  评论(0编辑  收藏  举报