rsync远程同步

1、挂载光盘安装rsync
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# yum -y install rsync
2、编辑rsync主配置文件
[root@centos01 ~]# cp /etc/rsyncd.conf /etc/rsyncd.conf.bak
[root@centos01 ~]# vim /etc/rsyncd.conf

在这里插入图片描述
编辑身份验证账户密码
在这里插入图片描述
4、开启并监听服务
[root@centos01 ~]# rsync --daemon
[root@centos01 ~]# netstat -anptu | grep rsync
tcp 0 0 192.168.100.10:873 0.0.0.0:* LISTEN 1296/rsync
5.创建同步目录并录入数据
[root@centos01 ~]# mkdir /bdqn
[root@centos01 ~]# echo “qqq” > /bdqn/bdqn.txt
6.将远程服务器100.10的bdqn数据同步到当前位置的accp目录
[root@centos01 ~]# rsync -a bob@192.168.100.10::bdqn ./accp/
[root@centos01 ~]# ls accp/
bdqn.txt

切换光盘安装inotify
[root@centos01 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos01 ~]# tar zxvf /mnt/inotify-tools-3.14.tar.gz -C /usr/src/
2、配置编译安装inotify
[root@centos01 inotify-tools-3.14]# ./configure && make && make install
配置实时数据同步
[root@centos01 ~]# vim /etc/sysctl.conf
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 128
fs.inotify.max_queued_watches = 8192
更新内核
[root@centos01 ~]# sysctl -p
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 128
fs.inotify.max_user_watches = 8192
编写监控脚本
[root@centos01 ~]# vim rsync.sh
#!/bin/bash
INW=“inotifywait -mrq -e modify,create,delete,move,attrib /var/www/html/”
RSYNC=“rsync -avzH /var/www/html/ root@192.168.100.20:/var/www/html/ --delete”
$INW | while read DIRECTORY EVENT FILE;do
$RSYNC &> /dev/null
done

[root@centos01 ~]# chmod +x rsync.sh

录入数据客户端验证
[root@centos01 ~]# ./rsync.sh &
[1] 5083

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值