Centos-7 rsync的简单的搭建

目的拉取或者推送到httpd网站根目录的文件
配置环境为两台机器要能ping通,关闭防火墙

服务端客户端
192.168.124.177192.168.124.178

在192.168.124.177的主机用yum安装rsync

yum -y install rsync

然后修改配置文件

vim /etc/rsyncd.conf

内容为

uid = root
gid = root
max connections = 4
exclude = lost+found/
transfer logging = yes
timeout = 900
motd file = /etc/rsyncd/rsyncd.motd
log file = /var/log/rsyncd.log
lock file = /var/run/rsyncd.loc
ignore nonreadable = yes
 dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz
[ha]
path = /var/www/html
comment = ha
ignore errors
read only = no
write only = no
list = no
auth users = heng
secrets file = /etc/rsyncd.passwd
hosts allow = 192.168.124.178
~

解释
uid = root
gid = root
max connections = 4 # 最大连接数为4
exclude = lost+found/ #排除文件
transfer logging = yes #记录下载和上载操作在自己单独的日志中
timeout = 900 #该选项可以覆盖客户指定的IP超时时间
motd file = /etc/rsyncd/rsyncd.motd #可有可无
log file = /var/log/rsyncd.log #日志记录文件的存放位置
lock file = /var/run/rsyncd.loc #锁文件的存放位置
ignore nonreadable = yes #指定rysnc服务器完全忽略那些用户没有访问权限的文件
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 #指定那些不进行>压缩处理再传输的文件
[ha] # 模块名
path = /var/www/html ## 需要做镜像的目录
comment = ha #这个模块的注释信息
ignore errors # 可以忽略一些无关的IO错误
read only = no #是否可以pull
write only = no #是否可以push
list = no # 不允许列文件
auth users = heng #授权用户,虚拟用户
secrets file = /etc/rsyncd.passwd #用户密码的文件路径
hosts allow = 192.168.124.178 # 允许所有主机连接

然后创建用户密码文件密码是123456

echo 'heng:123456'>/etc/rsyncd.passwd

给密码文件授权

chmod 600 /etc/rsyncd.passwd

启动

systemctl start rsyncd

查看一下启动了没有873端口

[root@localhost ~]# ss -nlt
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port     
LISTEN     0      5            *:873                      *:*

安装一个httpd测试用

yum -y install httpd

在根目录下创建一个文件

echo "rsync" > /var/www/html/index.html

然后在192.168.124.178机器上
安装rsync目的是用rsync的命令

yum -y install rsync

开始拉取

[root@localhost ~]# rsync -avzP heng@192.168.124.177::ha /

Password:
receiving incremental file list
./
index.html
              6 100%    5.86kB/s    0:00:00 (xfr#1, to-chk=0/2)

sent 50 bytes  received 130 bytes  72.00 bytes/sec
total size is 6  speedup is 0.03

各式说明命令 -参数 用户@ip::模块 拉去到本地的位置
在这里插入图片描述

在测试推送在根下创建一个文件

echo "rsync" >  /xiaobing.html

测试

[root@localhost ~]# rsync -azvP /xiaobing.html heng@192.168.124.177::ha

Password:
sending incremental file list
xiaobing.html
              6 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=0/1)

sent 106 bytes  received 43 bytes  42.57 bytes/sec
total size is 6  speedup is 0.04

查看177主机的网站根目录下有没有这个文件

root@localhost ~]# ll /var/www/html/
总用量 8
-rw-r--r-- 1 root root 6 12月 25 14:03 index.html
-rw-r--r-- 1 root root 6 12月 25 14:18 xiaobing.html

成功

然后说一下我遇到的报错
在这里插入图片描述
这个报错的原因可能是你的密码配置文件没给权限600的权限auth users、secrets file 对应信息是否存在疏忽,确认你登录用户的密码无误,密码文件各式不对,格式为 :用户名:密码
报错参考https://blog.csdn.net/u011415782/article/details/78727911
到此实验结束了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值