首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >rsync 服务方式连接

rsync 服务方式连接

作者头像
老七Linux
发布于 2018-05-09 15:32:45
发布于 2018-05-09 15:32:45
2K0
举报
rsync扩展 :
通过后台服务的方式:

在远程主机上建立一个rsync服务器,将本机作为rsync的客户端。(通常的表现方式为在后面添加 :: )

rsync 通过服务的方式同步:

要编辑配置文件/etc/rsyncd.conf 启动服务rsync –daemon 格式:rsync -av test1/ 192.168.133.130::module/dir/

(1.)编辑配置文件– # vim /etc/rsyncd.conf 由于centos 7 默认对配置文件全部都是注释掉的,最简单的方式我们在最后另起一行;输入咱们的策略进行编辑:

rsyncd.conf样例:
代码语言:javascript
复制
port=873
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
address=192.168.133.130
[test]
path=/tmp/rsync
use chroot=true
max connections=4
read only=no
list=true
uid=root
gid=root
auth users=test
secrets file=/etc/rsyncd.passwd
hosts allow=192.168.133.132 1.1.1.1 2.2.2.2  192.168.133.0/24

# cat /var/log/rsync.log //查看日志
# mkdir /tmp/rsync //创建一个目录匹配咱们创建的[test]模块名
# chmod 777 /tmp/rysnc //为了测试方便,暂时先给777,工作当中咱们需要看具体的情况。
# rsync –daemon //然后我们启动一下服务
# ps aux | grep rsync //检查一下是否有此服务
# netstat -lntp //检查服务是否启动 -t:列出 TCP 协议的连接
代码语言:javascript
复制
[[email protected] ~]# rsync -avP /tmp/asd.ipt 192.168.159.129::test/asdbak.ipt 
rsync: failed to connect to 192.168.159.129 (192.168.159.129): No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(122) [sender=3.0.9]

当我们测试时,发现了如上错误↑

  • 首先我们先检查网络是否可以ping通。
  • telnet一下服务器的IP地址

我们发现网络是通的,但是没有路由↓

代码语言:javascript
复制
[[email protected]02 ~]# telnet 192.168.159.129 873
Trying 192.168.159.129...
telnet: connect to address 192.168.159.129: No route to host

其原因就是因为firewall阻挡了我们。两端都需停掉firewall服务:(# systemctl stop firewalld)


rsyncd.conf配置文件详解 :

port:指定在哪个端口启动rsyncd服务,默认是873端口。

# vim /etc/rsyncd.conf 把端口更改为8730,
# killall rsync //杀死所有rsync相关的服务
# ps aux | grep rsync
# netstat -lntp //查看端口已经改成8730

然后我们需要添加 –port 8730

代码语言:javascript
复制
[[email protected]02 ~]# rsync -avPL --port 8730 192.168.159.129::test/ /tmp/test/
receiving incremental file list
symlink has no referent: "/123.txt" (in test)
./

sent 29 bytes  received 131 bytes  320.00 bytes/sec
total size is 4868  speedup is 30.43
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1518) [generator=3.0.9]

log file:指定日志文件。

pid file:指定pid文件,这个文件的作用涉及服务的启动、停止等进程管理操作。

address:指定启动rsyncd服务的IP。假如你的机器有多个IP,就可以指定由其中一个启动rsyncd服务,如果不指定该参数,默认是在全部IP上启动。

[]:指定模块名,里面内容自定义。


path:指定数据存放的路径。 一旦我们制定了目录,例如我们创建一个超链接/etc/passwd .如果我们在同步的时候 -L就会出现问题!我们可以查看日志,查看具体错误信息!

代码语言:javascript
复制
[[email protected]02 ~]# rsync -avPL 192.168.159.129::test/ /tmp/test/
receiving incremental file list
symlink has no referent: "/123.txt" (in test)

sent 26 bytes  received 128 bytes  102.67 bytes/sec
total size is 4868  speedup is 31.61
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1518) [generator=3.0.9]

当我们把下面设置成false,即可解决↓

use chroot true|false:表示在传输文件前首先chroot到path参数所指定的目录下。这样做的原因是实现额外的安全防护,但缺点是需要以roots权限,并且不能备份指向外部的符号连接所指向的目录文件。默认情况下chroot值为true,如果你的数据当中有软连接文件,建议设置成false。


max connections:指定最大的连接数,默认是0,即没有限制。

read only ture|false:如果为true,则不能上传到该模块指定的路径下。

list:表示当用户查询该服务器上的可用模块时,该模块是否被列出,设定为true则列出,false则隐藏。

列出远程服务端的list:
代码语言:javascript
复制
[[email protected]02 ~]# rsync --port 8730 192.168.159.129::
test

如果改成false,我们就不可以查看服务器中的list。(安全选项,如果可见的,没有限制IP,黑客就可以直接列出来,然后在你模块里面写数据,导入木马等)


uid/gid:指定传输文件时以哪个用户/组的身份传输。

如果把uid=nobody;gid=nobody;我们则会没有任何权限去上传和下载:

代码语言:javascript
复制
[[email protected]02 ~]# rsync -avPL --port 8730 /tmp/test/  192.168.159.129::test/ 
sending incremental file list
123.txt
        1296 100%    0.00kB/s    0:00:00 (xfer#1, to-check=1/3)

sent 1400 bytes  received 27 bytes  2854.00 bytes/sec
total size is 6164  speedup is 4.32
[[email protected]02 ~]# rsync -avP --port 8730 /tmp/test/  192.168.159.129::test/ 
sending incremental file list
./
rsync: failed to set times on "/." (in test): Operation not permitted (1)

auth users:指定传输时要使用的用户名。

# vim /etc/rsyncd.passwd 写入 test:asd9577 用户名+密码
# chmod /etc/rsyncd.passwd

如下↓:

代码语言:javascript
复制
[[email protected]02 ~]# rsync -avP --port 8730 /tmp/test/  [email protected]192.168.159.129::test/ 
Password: 
sending incremental file list
./

sent 83 bytes  received 14 bytes  27.71 bytes/sec
total size is 4879  speedup is 50.30

secrets file:指定密码文件,该参数连同上面的参数如果不指定,则不使用密码验证。注意该密码文件的权限一定要是600。格式:用户名:密码

有时候我们同步一些文件几乎都是使用脚本在凌晨完成的动作,如果需要我们输入密码肯定不行的,所以我们需要在客户端也要创建一个密码文件与之匹配!

# vim /etc/rsync_pass.txt 只需要增加密码即可 ASD9577
# chmod 600 /etc/rsync_pass.txt

这样就算不输入密码也是可以的!!

代码语言:javascript
复制
[[email protected]02 ~]# rsync -avP --port 8730 /tmp/test/ --password-file=/etc/rsync_pass.txt  [email protected]192.168.159.129::test/ 
sending incremental file list

sent 77 bytes  received 8 bytes  170.00 bytes/sec
total size is 4879  speedup is 57.40

hosts allow:表示被允许连接该模块的主机,可以是IP或者网段,如果是多个,中间用空格隔开。

代码语言:javascript
复制
hosts allow=192.168.159.130  1.1.1.1 2.2.2.2  192.168.159.0/24

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016/07/20,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • rsync扩展 :
    • 通过后台服务的方式:
    • rsync 通过服务的方式同步:
    • rsyncd.conf样例:
    • # cat /var/log/rsync.log //查看日志
    • # mkdir /tmp/rsync //创建一个目录匹配咱们创建的[test]模块名
    • # chmod 777 /tmp/rysnc //为了测试方便,暂时先给777,工作当中咱们需要看具体的情况。
    • # rsync –daemon //然后我们启动一下服务
    • # ps aux | grep rsync //检查一下是否有此服务
    • # netstat -lntp //检查服务是否启动 -t:列出 TCP 协议的连接
  • rsyncd.conf配置文件详解 :
    • # vim /etc/rsyncd.conf 把端口更改为8730,
    • # killall rsync //杀死所有rsync相关的服务
    • # ps aux | grep rsync
    • # netstat -lntp //查看端口已经改成8730
    • 列出远程服务端的list:
    • # vim /etc/rsyncd.passwd 写入 test:asd9577 用户名+密码
    • # chmod /etc/rsyncd.passwd
    • # vim /etc/rsync_pass.txt 只需要增加密码即可 ASD9577
    • # chmod 600 /etc/rsync_pass.txt
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档