rsync通过服务同步(下)

前面都有输入密码,这样同样也不能写入脚本中自动执行,其实这种方式也是可以不用手动输入密码的,它有两种实现方式。

第一种,指定密码文件
  • 在客户端上,也就是dl-002上,编辑一个密码文件:
[root@dl-002 ~]# vim /etc/pass
  • 加入test用户的密码:
[root@dl-002 ~]# cat /etc/pass
test123
  • 修改密码文件的权限:
[root@dl-002 ~]# chmod 600 /etc/pass
  • 在同步的时候,指定一下密码文件,就可以省去输入密码的步骤了:
[root@dl-002 ~]# rsync -avL test@192.168.197.128::test/test1/ /tmp/test8/ --password-file=/etc/pass
receiving incremental file list
created directory /tmp/test8
./
1
1.txt
2
2.txt
3
4
test.txt

sent 190 bytes  received 451 bytes  1282.00 bytes/sec
total size is 0  speedup is 0.00

第二种:在rsync服务器端不指定用户
  • 在服务端也就是dl-001上修改配置文件rsyncd.conf, 去掉关于认证账户的配置项(auth user 和 secrets file这两行)
sed -i 's/auth users/#auth users/;s/secrets file/#secrets file/' /etc/rsyncd.conf

上面的这个命令是把 “auth users” 和 “secrets file” 两行的最前面加一个 “#”, 这样就把这两行注释掉,使其失去意义。其实也不难弄明白,只是用分号把两个替换的子命令块给替换了而已。然后我们再到客户端dl-002测试:

[root@dl-002 ~]# rsync -avL 192.168.197.128::test/test1/ /tmp/test9/
receiving incremental file list
created directory /tmp/test9
./
1
1.txt
2
2.txt
3
4
test.txt

sent 162 bytes  received 410 bytes  1144.00 bytes/sec
total size is 0  speedup is 0.00
注意,这里不用再加test这个用户了,默认是以root的身份拷贝的,现在已经不需要输入密码了。

更改端口873为8730

1.编辑rsync配置文件(/etc/rsyncd.conf),将端口改为port=8730
2.重启rsync服务
3.安装killall工具:yum install -y psmisc

4.杀死所有rsync进程:


[root@dl-001 ~]# killall rsync

5.启动:

[root@dl-001 ~]# rsync --daemon

6.检测:

[root@dl-001 ~]# !ps
ps aux |grep rsync
root      3161  0.0  0.0 114644   548 ?        Ss   09:09   0:00 rsync --daemon
[root@dl-001 ~]# !netstat
netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 192.168.8.125:8730      0.0.0.0:*               LISTEN      3161/rsync 
进行同步
[root@dl-002 ~]# rsync -avP 192.168.197.128::test/adai002 /tmp/123.txt
rsync: failed to connect to 192.168.197.128 (192.168.197.128): Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(122) [Receiver=3.0.9]

说明: 因未开放873端口,所以此时同步数据会报错!那么如何进行同步呢?方法如下:

[root@dl-002 ~]# rsync -avP --port 8730 192.168.8.125::test/adai002 /tmp/123.txt
receiving incremental file list

sent 26 bytes  received 59 bytes  170.00 bytes/sec
total size is 1148  speedup is 13.51

说明: 使用–port选项指定端口号。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值