使用rsync服务通过inotify实现触发式自动同步数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用rsync服务通过inotify实现触发式自动同步数据相关的知识,希望对你有一定的参考价值。
实验拓扑:HK36(Server 192.168.2.102)====HK46(Client 192.168.2.190)
实验要求:对HK46 /data/目录备份到HK36的/backup/下
(1) rsync服务依赖于xinetd超级服务管理,首先安装xinetd服务
[[email protected] ~]# yum -y install xinetd
(2) 进入rsync修改配置文件信息,将disable = yes改为no,重启服务,查看873端口是否起来
[[email protected] ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
[[email protected] ~]# netstat -anptu | grep 873
tcp 0 0 :::873 :::* LISTEN 2729/xinetd
(3) 创建非系统测试用户,并对目录/backup赋予用户nobody权限
[[email protected] backup]# vim /etc/rsyncd.conf
uid = nobody
gid = nobody
address = 192.168.2.102
pid = 873
host allow = 192.168.2.190
use chroot = yes
max_connetion = 5
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
motd file = /etc/rsyncd.motd
[backup]
path = /backup/
comment = data for backup
read only = no
auth users = gz
list = yes
[[email protected] backup]# chown nobody:nobody /backup/
[[email protected] backup]# vim /etc/rsyncd.motd 创建登入模板文件
welcome to backup data!
[[email protected] backup]# vim /etc/rs.passwd 创建密码
gz:ggrr50152412
(4) 测试,HK46下创建备份目录测试:
[[email protected] /]# mkdir /backup/
[[email protected] /]# mkdir /data/
[[email protected] data]# ls
22 55 a aaaaa erer kd s test
[[email protected] data]# rsync -avz ./ --delete [email protected]::backup
(5) 上传inotify并解压安装
[[email protected] ~]# tar -xvf inotify-tools-3.14.tar.gz -C /usr/local/src/
[[email protected] inotify-tools-3.14]#./configure --prefix=/usr/local/inotify-tools;make;make install
(6) 直接调用命令
[[email protected] ~]# ln -s /usr/local/inotify-tools/bin/* /usr/bin/
[[email protected] ~]# vim /root/passfile 创建密码文件
ggrr50152412
[[email protected] data]# chmod 600 /root/passfile并赋予600权限
(7) 测试
(8) 编辑脚本,并赋予执行权限
#!/bin/bash
backup_Server=192.168.2.102
/usr/bin/inotifywait -mrq --format '%w%f' -e create,close_write,delete /data/ | while read line
do
cd /data/
rsync -az ./ --delete [email protected]$backup_Server::backup --password-file=/root/ passfile
done
[[email protected] ~]# vim inotify.sh
(9) 测试成功
使用LAMP环境搭建wordpress论坛 :http://blog.51cto.com/13719714/2108415
以上是关于使用rsync服务通过inotify实现触发式自动同步数据的主要内容,如果未能解决你的问题,请参考以下文章
Sersync实现触发式文件同步 替代inotify和rsync