操作系統:RHEL6.2
內核版本:2.6.32-220.el6.x86_64 (確認是否在2.6.13版本以上)
A系統IP:192.168.5.205
B系統IP:192.168.5.206
A系統裏目錄/var/www/html/ 實時同步到B系統/var/www/html/
在B系統安裝rsync 下載地址http://pan.baidu.com/s/1gdd4p5D
[root@B ~]# tar zxvf rsync-3.1.1.tar.gz
[root@B ~]# cd rsync-3.1.1
[root@B rsync-3.1.1]# make && make install
2.在B系統配置rsync
1)創建rsyncd.conf
[root@B ~]# vim /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 0
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[www] #定義模塊名
path = /var/www/html #指定數據同步到哪
comment = update #名稱,自定義
ignore errors
read only = no
write only = no
hosts allow = 192.168.5.205
list = false
uid = root
gid = root
auth users = backup #使用用戶名backp,與系統用戶無關
secrets file = /etc/server.pass #用戶名:密碼的文件
2)創建server.pass
[root@B ~]# vim /etc/server.pass
backup:ixdba123 #用戶名:密碼 格式
3)啓動rsync守護進程,並開機自動啓動
[root@B ~]# /usr/local/bin/rsync --daemon
[root@B ~]# ps -ef | grep rsync
root 22700 1 0 11:40 ? 00:00:00 /usr/local/bin/rsync --daemon
[root@B ~]# echo "/usr/local/bin/rsync --daemon" >>/etc/rc.local
3.在A系統 配置內容發佈節點
1)安裝rsync
[root@B ~]# tar zxvf rsync-3.1.1.tar.gz
[root@B ~]# cd rsync-3.1.1
[root@B rsync-3.1.1]# make && make install
2)安裝inotify-tool 下載地址http://pan.baidu.com/s/1lgcZO
[root@A ~]# tar zxvf inotify-tools-3.14
[root@A ~]# cd inotify-tools-3.14
[root@A inotify-tools-3.14]# make && make install
查看是否已生成inotifywait和inotifywatch文件
[root@A ~]# ll /usr/local/bin/
total 1392
-rwxr-xr-x. 1 root root 44271 Sep 23 01:26 inotifywait
-rwxr-xr-x. 1 root root 41361 Sep 23 01:26 inotifywatch
-rwxr-xr-x. 1 root root 1333770 Sep 22 15:46 rsync
3)配置內容發佈節點的主要工作是將靜態網頁實時同步到B系統,這個過程通過shell完成,腳本如下:
[root@A ~]# vim rsync.sh
注# src=/var/www/html 是A系統要備份的數據路徑
--timeftm:指定時間的輸出格式
--format:指定變化文件的詳細信息
-mrq : m,即monitor表示保持事件監聽狀態
r,即recursive表示遞歸查詢目錄
q,打印出監控事件
-e 即event指定要監控的事件,常見事件有modify,close_write,delete,create,attrib等
modify 可用 close_write 代替,close_write適用於寫入大文件需要一段時間時
給rsync.sh加上x權限
[root@A ~]# chmod a+x rsync.sh
4)在A系統創建/etc/server.pass 內容密碼爲ixdba123,與B系統的backup:ixdba123一致
[root@A ~]# vim /etc/server.pass
ixdba123
5)後臺啓動rsync.sh
[root@A ~]# /root/rsync.sh &
[root@A ~]# ps -ef | grep rsync
root 2274 1 0 13:47 ? 00:00:00 /bin/bash /root/rsync.sh
root 2276 2274 0 13:47 ? 00:00:00 /bin/bash /root/rsync.sh
4.測試在A系統/var/www/html 寫入一個文件或目錄,是否及時同步到B系統/var/www/html