rsync+inotify實現差量同步

安裝和配置rsync
http://rsync.samba.org/bash

yum remove rsync

安裝:tcp

tar -zxvf rsync-3.1.1.tar.gzcode

cd rsync-3.1.1
./configure --prefix=/usr/local/rsync --disable-ipv6
make
make installserver

ln -s /usr/local/rsync/bin/rsync /usr/bin/rsynccrontab

server端配置ip

vi /usr/local/rsync/rsyncd.conf

pid file = /var/run/rsyncd.pid
port = 873
pid = root
gid = root
use chroot = no
max connections = 200
timeout 600
lock file = /var/run/rsyncd.lock
log file = /var/run/rsyncd.log
secrets file = /usr/local/rsync/rsyncd.passwd
motd file = /etc/rsyncd.motdrem

[test]
path = /test/
ignore errors
read only = true
list = false
hosts allow = *get

hosts deny = 0.0.0.0/32

auth users = rsync #該用戶系統中存在且對後面指定的備份目錄擁有權限
comment = rsync from qklin同步

vi /usr/local/rsync/rsyncd.motd

++++++++++++++++++++++++++++++++++++
Wlecome to qklin rsync services
++++++++++++++++++++++++++++++++++++io

--指定rsync訪問的密碼,密碼不須要和系統帳號密碼相同

vi /usr/local/rsync/rsyncd.passwd

rsync:rsyncpass

ln -s /usr/local/rsync/rsyncd.conf /etc/rsyncd.conf
ln -s /usr/local/rsync/rsyncd.motd /etc/rsyncd.motd
ln -s /usr/local/rsync/rsyncd.passwd /etc/rsyncd.passwd

chmod 600 /usr/local/rsync/rsyncd.passwd

chown root:root /usr/local/rsync/rsyncd.passwd

啓動rsync

/usr/bin/rsync --daemon --config=/etc/rsyncd.conf

加入開機啓動

echo "/usr/bin/rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.d/rc.local

檢查是否加入成功開機啓動

cat /etc/rc.d/rc.local

/usr/bin/rsync --daemon

netstat -lntp | grep 873

tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 10689/rsync
tcp 0 0 :::873 :::* LISTEN 10689/rsync

客戶端配置

(1).新建客戶端密碼文件(客戶端不帶用戶名)

vi /etc/rsyncd.passwd

rsyncpass

chmod 600 /etc/rsyncd.passwd

rsync -vzrtopg --progress --delete root@192.168.5.189::test /ocpyang/ --password-file=/etc/rsyncd.passwd

(3).新建同步腳本

vi /rsync.sh

#!/bin/bash
rsync -vzrtopg --progress --delete  root@192.168.5.189::test /testbak/ --password-file=/etc/rsyncd.passwd

(4).手動同步文件

cd /

./rsync.sh

(5).自動同步:每隔五分鐘同步一次

crontab -e

0,5 /rsync.sh

相關文章
相關標籤/搜索