一、实现bak-server

1.1安装rsync

# yum -y install rsync

1.2修改配置文件

# vi /etc/rsyncd.conf
#添加下面内容
uid=test
gid=test
reverse lookup = no [www]
path=/www
read only=no
auth users=rsyncuser
secrets file=/etc/rsync.pas

1.3 创建同步目录,生成密码文件

# mkdir /www
# echo "rsyncuser:magedu" > /etc/rsync.pas
# chmod 600 /etc/rsync.pas

1.4 启动服务

# systemctl enable --now rsyncd
# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*

二、实现data-server

2.1安装相关包

# wget -O  /etc/yum.repos.d/epel.repo  http://mirrors.aliyun.com/repo/epel-7.repo
# yum install inotify-tools --enablerepo=epel -y
# yum -y install rsync

2.2创建密码文件

# mkdir /www
# echo "rsyncuser:magedu" > /etc/rsync.pas
# chmod 600 /etc/rsync.pa

三、使用脚本实现实时同步

# cat inotify_rsync.sh
#!/bin/bash
SRC='/www'
DEST='rsyncuser@10.0.0.17::www' rpm -q rsync &> /dev/null || yum -y install rsync
inotifywait -mrq --exclude=".*\.swp" --timefmt '%Y-%m-%d %H:%M:%S' --format '%T %w %f' -e create,delete,moved_to,close_write,attrib ${SRC} | while read DATE TIME DIR FILE;
do
FILEPATH=${DIR}${FILE}
rsync -az --delete --password-file=/etc/rsync.pas $SRC $DEST && echo "At ${TIME} on ${DATE}, file $FILEPATH was backuped up via rsync" >> /var/log/changelist.log
done

四、测试

#在客户端测试
[root@data-sever www]# rm -rf test.txt
[root@data-sever www]# dd if=/dev/zero of=f1.img bs=1M count=1000
[root@data-sever www]# dd if=/dev/zero of=f2.img bs=1M count=10
[root@data-sever www]# rm -rf f1.img #在服务端观察实时同步情况
[root@bak-sever www]# watch -n0.5 ls -l .

实时同步情况如下:



最新文章

  1. 【代码笔记】iOS-3个section,每个都有header.
  2. 【JAVA】Quartz中时间表达式的设置
  3. PHP删除符合条件的整个目录
  4. GBin1插件推荐之马可波罗(Marco Polo),jQuery的自动补齐插件 - Autocomplete Plugin
  5. [Math]Reverse Integer
  6. java 正则表达式抽取
  7. ASP.NET Web API下的HttpController激活:程序集的解析
  8. seo步骤
  9. 转:常用的iOS开源库和第三方组件
  10. HTML DOM元素关系与操作
  11. 【性能测试工具】- Http_Load
  12. 学习 javascript (一)javascript 简介
  13. iOS 打包.framework(包括第三方、图片、xib、plist文件)详细步骤及需要注意的地方
  14. idea 的一些基本的配置
  15. 可视化n次贝塞尔曲线及过程动画演示--大宝剑
  16. [转帖]tar高级教程:增量备份、定时备份、网络备份
  17. RabbitMQ入门-发布订阅模式
  18. Linux 配置SFTP,配置用户访问权限
  19. centos6.6 安装MariaDB
  20. 介绍Collection框架的结构;Collection 和 Collections的区别

热门文章

  1. CSS基础 阴影相关属性设置
  2. Selenium_获取浏览器名称和版本(5)
  3. 查看磁盘I/O命令iostat详解
  4. spring boot 打包war后 部署到外部 tomcat 的具体正确操作【包括修改端口 与 去除请求路径的工程名】
  5. Linux上天之路(一)之Linux前世今生
  6. Centos6.9虚拟机环境搭建
  7. SYCOJ157乘二加一
  8. 查询并导出表结构为Excel
  9. 云计算实验二 Docker实验-docker安装
  10. 【记录一个问题】在goland中的_test.go文件中,点右键点run,无法执行测试用例