Rsync + Inotify 实现文件自动同步
2014-12-05 14:47
246 查看
Rsync Server1:10.10.10.78 RHEL5.9
Rsync Server1:10.10.10.40 RHEL5.9
Rsync Client + Inotify server:10.10.10.201 RHEL5.9
一、在10.10.10.78 配置
useradd tomcat
mkdir /root/hunk
chown -R tomcat.tomcat /root/hunk
yum install -y rsync
vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
read only = no #是否允许客户端上传数据,这里设置为允许
address=10.10.10.78 #Rsync server ip
port=873 #设置服务器监听端口号
max connections = 10
timeout = 300
motd file =/etc/rsyncd/rsyncd.motd
pid file = /var/run/rsyncd/rsyncd.pid
log file = /var/log/rsyncd/rsyncd.log
lock file = /var/run/rsyncd/rsyncd.lock
hosts allow = 10.10.10.201 #允许客户端同步的IP
hosts deny=*
list = yes
auth users = hunk
[test]
uid = tomcat
gid = tomcat
read only = no
path = /root/hunk
auth users = hunk
secrets file = /etc/rsyncd/rsyncd.secrets
comment = test rsync
mkdir /etc/rsyncd/
vim /etc/rsyncd/rsyncd.secrets
hunk:123456
vim /etc/rsyncd/rsyncd.motd
#########this is a 78 rsync test!#############
二、在10.10.10.40配置
useradd tomcat
mkdir /root/hunk
chown -R tomcat.tomcat /root/hunk
yum install -y rsync
vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
read only = no #是否允许客户端上传数据,这里设置为允许
address=10.10.10.40 #Rsync server ip
port=873 #设置服务器监听端口号
max connections = 10
timeout = 300
motd file =/etc/rsyncd/rsyncd.motd
pid file = /var/run/rsyncd/rsyncd.pid
log file = /var/log/rsyncd/rsyncd.log
lock file = /var/run/rsyncd/rsyncd.lock
hosts allow = 10.10.10.201 #允许客户端同步的IP
hosts deny=*
list = yes
auth users = hunk
[test]
uid = tomcat
gid = tomcat
read only = no
path = /root/hunk
auth users = hunk
secrets file = /etc/rsyncd/rsyncd.secrets
comment = test rsync
mkdir /etc/rsyncd/
vim /etc/rsyncd/rsyncd.secrets
hunk:123456
vim /etc/rsyncd/rsyncd.motd
#########this is a 40 rsync test!#############
三、在10.10.10.201上配置
useradd tomcat
1、yum install -y rsync
mkdir /test/hunk
mkdir /test/log
2、vim /test/rsync.pw
123456
3、解压inotify-tools-3.14.tar.gz
[root@localhost inotify]# cd /data/inotify/
[root@localhost inotify]# tar zxvf inotify-tools-3.14.tar.gz
4、安装
[root@localhost inotify]# cd inotify-tools-3.14
[root@localhost inotify-tools-3.14]# ./configure
[root@localhost inotify-tools-3.14]# make
[root@localhost inotify-tools-3.14]# make install
5、编写脚本,当监控到数据发生改变时,自动进行数据同步操作。
并将该脚本放到 /etc/rc.local ,让其开机就运行。
vim /test/notify_rsync.sh
#!/bin/bash
#this is rsync script based on inotify.
#date:2014-08-25
#
#
export PATH=/bin:/usr/bin:/usr/local/bin
SRC=/test/hunk/
DEST1=test
DEST2=test
Client1=10.10.10.78
Client2=10.10.10.40
User=hunk
#password file must not be other-accessible.
Passfile=/test/rsync.pw
123456
[ ! -e $Passfile ] && exit 2
#wait for change
inotifywait -mrq --timefmt '%y-%m%d %H:%M' --format '%T %w%f %e' --event modify,create,move,delete,attrib $SRC|while read line
do
echo "$line" > /test/log/inotify_log 2>&1
/usr/bin/rsync -avz --delete --progress --password-file=${Passfile} ${SRC} ${User}@${Client1}::${DEST1} >> /test/log/sync_78 2>&1
/usr/bin/rsync -avz --delete --progress --password-file=${Passfile} ${SRC} ${User}@${Client2}::${DEST2} >> /test/log/sync_40 2>&1
done &
四、测试
在10.10.10.201上的/test/hunk 创建文件
cd /test/hunk
touch 1 2 3
在10.10.10.78和10.10.10.40上的/root/hunk
cd /root/hunk
ls
Rsync Server1:10.10.10.40 RHEL5.9
Rsync Client + Inotify server:10.10.10.201 RHEL5.9
一、在10.10.10.78 配置
useradd tomcat
mkdir /root/hunk
chown -R tomcat.tomcat /root/hunk
yum install -y rsync
vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
read only = no #是否允许客户端上传数据,这里设置为允许
address=10.10.10.78 #Rsync server ip
port=873 #设置服务器监听端口号
max connections = 10
timeout = 300
motd file =/etc/rsyncd/rsyncd.motd
pid file = /var/run/rsyncd/rsyncd.pid
log file = /var/log/rsyncd/rsyncd.log
lock file = /var/run/rsyncd/rsyncd.lock
hosts allow = 10.10.10.201 #允许客户端同步的IP
hosts deny=*
list = yes
auth users = hunk
[test]
uid = tomcat
gid = tomcat
read only = no
path = /root/hunk
auth users = hunk
secrets file = /etc/rsyncd/rsyncd.secrets
comment = test rsync
mkdir /etc/rsyncd/
vim /etc/rsyncd/rsyncd.secrets
hunk:123456
vim /etc/rsyncd/rsyncd.motd
#########this is a 78 rsync test!#############
二、在10.10.10.40配置
useradd tomcat
mkdir /root/hunk
chown -R tomcat.tomcat /root/hunk
yum install -y rsync
vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
read only = no #是否允许客户端上传数据,这里设置为允许
address=10.10.10.40 #Rsync server ip
port=873 #设置服务器监听端口号
max connections = 10
timeout = 300
motd file =/etc/rsyncd/rsyncd.motd
pid file = /var/run/rsyncd/rsyncd.pid
log file = /var/log/rsyncd/rsyncd.log
lock file = /var/run/rsyncd/rsyncd.lock
hosts allow = 10.10.10.201 #允许客户端同步的IP
hosts deny=*
list = yes
auth users = hunk
[test]
uid = tomcat
gid = tomcat
read only = no
path = /root/hunk
auth users = hunk
secrets file = /etc/rsyncd/rsyncd.secrets
comment = test rsync
mkdir /etc/rsyncd/
vim /etc/rsyncd/rsyncd.secrets
hunk:123456
vim /etc/rsyncd/rsyncd.motd
#########this is a 40 rsync test!#############
三、在10.10.10.201上配置
useradd tomcat
1、yum install -y rsync
mkdir /test/hunk
mkdir /test/log
2、vim /test/rsync.pw
123456
3、解压inotify-tools-3.14.tar.gz
[root@localhost inotify]# cd /data/inotify/
[root@localhost inotify]# tar zxvf inotify-tools-3.14.tar.gz
4、安装
[root@localhost inotify]# cd inotify-tools-3.14
[root@localhost inotify-tools-3.14]# ./configure
[root@localhost inotify-tools-3.14]# make
[root@localhost inotify-tools-3.14]# make install
5、编写脚本,当监控到数据发生改变时,自动进行数据同步操作。
并将该脚本放到 /etc/rc.local ,让其开机就运行。
vim /test/notify_rsync.sh
#!/bin/bash
#this is rsync script based on inotify.
#date:2014-08-25
#
#
export PATH=/bin:/usr/bin:/usr/local/bin
SRC=/test/hunk/
DEST1=test
DEST2=test
Client1=10.10.10.78
Client2=10.10.10.40
User=hunk
#password file must not be other-accessible.
Passfile=/test/rsync.pw
123456
[ ! -e $Passfile ] && exit 2
#wait for change
inotifywait -mrq --timefmt '%y-%m%d %H:%M' --format '%T %w%f %e' --event modify,create,move,delete,attrib $SRC|while read line
do
echo "$line" > /test/log/inotify_log 2>&1
/usr/bin/rsync -avz --delete --progress --password-file=${Passfile} ${SRC} ${User}@${Client1}::${DEST1} >> /test/log/sync_78 2>&1
/usr/bin/rsync -avz --delete --progress --password-file=${Passfile} ${SRC} ${User}@${Client2}::${DEST2} >> /test/log/sync_40 2>&1
done &
四、测试
在10.10.10.201上的/test/hunk 创建文件
cd /test/hunk
touch 1 2 3
在10.10.10.78和10.10.10.40上的/root/hunk
cd /root/hunk
ls
相关文章推荐
- [转]CENTOS 使用RSYNC+INOTIFY实现文件实时自动同步
- inotify+rsync实现文件同步
- Inotify+Rsync实现linux文件实时同步
- Linux 文件同步工具——inotify+rsync实现实时同步
- inotify+rsync实现Linux服务器文件同步
- Linux 文件同步工具——inotify+rsync实现实时同步
- Rsync+Inotify基础配置 以及 Rsync+Inotify配置实现文件自动同步
- Rsync+inotify 实现文件自动同步
- inotify + rsync实现linux文件实时同步
- inotify + rsync实现linux文件实时同步
- inotify + rsync 实现 linux 文件实时同步
- 使用rsync + inotify 实现多台游戏服代码自动实时同步
- rsync + inotify-tools实现文件的实时同步
- [转]inotify + rsync实现linux文件实时同步
- inotify + rsync 使用触发同步机制 实现文件 "实时同步"
- Inotify+Rsync实现linux文件实时同步
- Rsync + inotify 实现文件实时同步
- rsync+inotify实现对web服务器上的文件自动同步
- rsync + inotify 实现文件目录的实时单向同步
- inotify + rsync实现linux文件实时同步,使用触发同步机制