1. centos5.8 server: 192.168.1.201 hostname:centos001
centos5.8 client: 192.168.1.202 hostname:centos002
install package:
(server):
- yum install rsync -y
- mkdir -p /data/html #如果要同步的不是此目录,可以根据实际需要添加目录
- #wget
- tar xzvf inotify-tools-3.14.tar.gz
- cd inotify-tools-3.14
- ./configure
- make
- make install
(client):
- yum install rsync -y
- mkdir -p /data/html
2. server shell:
[root@centos001 html]# cat /etc/rsyncd.conf
uid = root
gid = root
user chroot = no
max connecton = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[backup]
path =/script/
ignore errors
read only = no
list = no
hosts allow =192.168.1.0/255.255.255.0
auth users = root
secrets file = /etc/rsyncd.password
[root@centos001 html]#
[root@centos001 home]# cat /etc/rsyncd.secrets
123456789
root:123456789
[root@centos001 home]#
[root@centos001 home]# cat rsync.sh
#!/bin/bash
src=/data/html/
des=www
host="192.168.1.202"
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e modify,delete,create,attrib $src | while read files
do
for hostip in $host
do
rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd.secrets $src
done
echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
[root@centos001 home]#
3.client shell
[root@centos002 html]# cat /etc/rsyncd.conf
uid = root
gid = root
user chroot = no
max connecton = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /var/log/rsyncd.log
[www]
path =/data/html/
ignore errors
read only = no
list = no
hosts allow =192.168.1.0/255.255.255.0
auth users = root
uid = root
gid = root
secrets file = /etc/rsyncd.secrets
[root@centos002 html]#
[root@centos002 html]# cat /etc/rsyncd.secrets
123456789
root:123456789
[root@centos002 html]#
4.check
阅读(232) | 评论(0) | 转发(0) |