rsync


server端

——————————————

chkconfig iptables  off

chkconfig ip6tables off



vim /etc/selinux/config

SELINUX=disabled


yum install -y xinetd rsync

chkconfig xinetd on

chkconfig rsync  on


vim /etc/xinetd.d/rsync

  disable = no

  server_args     = --daemon --config=/etc/rsyncd.conf


useradd -M -s /sbin/nologin rsync


vim /etc/rsyncd.conf

################################

uid = rsync

gid = rsync

user chroot = no

max connections = 200

timeout = 600

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsyncd.pid

log file = /var/run/rsyncd.log

################################

[backup]

path = /backup/

ignore errors

read only = no

list = no

hosts allow = 192.168.200.0/255.255.255.0

auth users = apple

secrets file = /etc/rsyncd.password

###################################

vim /etc/rsyncd.password

apple:apple123

chmod 600 /etc/rsyncd.password



client端

——————————————————

chkconfig iptables  off

chkconfig ip6tables off



vim /etc/selinux/config

SELINUX=disabled


yum install -y  rsync


vim /etc/rsyncd.password

apple123

chmod 600 /etc/rsyncd.password



客戶端使用的命令


1.rsync -avz /local1   /local2

2.rsync -avz -e 'ssh -p 22'  /local [email protected]:/redir

3.rsync -avz /local  [email protected]::backup --password-file=/etc/rsyncd.password 




inotify的配置

###################################

tar -xf inotify-tools-3.14.tar.gz

cd inotify-tools-3.14.tar.gz

./configure --prefix=/usr/local/inotify-tools-3.14

make && make install

ln -s /usr/local/inotify-tools-3.14 /usr/local/inotify-tools




./inotifywait -mrq --timefmt '%F_%H:%M:%S' --format '%T %w %f %e' -e create /tmp

[option]

-m|--monitor    表示一直保持事件監聽狀態。

-r|--recursive  表示遞歸查詢目錄。

-q|--quiet      表示打印出監控事件

-e              可以指定要監控的事件。



   

--timefmt使用的是date時間參數

--format

  %T由timefmt定義的事件格式

  %w表示發生事件的目錄

  %f表示發生事件的文件

  %e表示發生的事件

  


access 讀取文件

modify 修改文件或目錄

attrib 修改文件或目錄的屬性

close_write 文件或目錄內容修改後保存關閉

close_nowrite 文件或目錄內容打開不修改保存關閉

close file or directory closed, regardless of read/write mode

open file or directory opened

moved_to file or directory moved to watched directory

moved_from file or directory moved from watched directory

move file or directory moved to or from watched directory

create file or directory created within watched directory

delete file or directory deleted within watched directory

delete_self file or directory was deleted

unmount file system containing file or directory unmounted


將rsync結合inotify使用

vim /sh/inotify.sh

#!/bin/bash

/usr/local/inotify-tools/bin/inotifywait -mrq --timefmt '%F_%H:%M:%S' --format '%T %w %f %e' -e create,delete,move,close_write  /data  \

|while read file

do

cd /data  &&

rsync -az --delete  ./  [email protected]::backup --password-file=/etc/rsyncd.password  && echo "$file" >>/tmp/rsync.log 2>&1

done



chmod 700 /sh/inotify.sh

echo "/bin/sh /sh/inotify.sh  >/dev/null &"  >>/etc/rc.local


inotify的優化


cd /proc/sys/fs/inotify

修改

max_queued_events="200000000"

#inotify隊列最大長度,如果值太小,會出現"** Event Queue Overflow **"錯誤,導致監控文件不準確


max_user_watches="2000000000" 

#inotifywait命令可以監視文件目錄的數量

可以用:find /home/test -type d | wc -l 統計,必須保證max_user_watches值大於統計結果


max_user_instances="65535"

#每個用戶創建inotify實例最大值



inotify優缺點  


inotify的優點:


1)實時數據同步  


inotify缺點:


1)併發如果大於200個文件,同步就會延時

2)監控到的事件後,調用rsync同步是單進程的,sersync是多進程同步

serysnc 功能多:可以對失敗的文件重傳,真正的守護進程socket,默認多線程同步。

3)如果被監控的目錄文件很多,inotify效率會慢,因爲每次同步都要檢查每一個文件


配置sersync


echo "/usr/local/sersync/sersync2  -d -r -o /usr/local/sersync/confxml.xml &" >>/etc/rc.local





















發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章