-
服務端安裝與配置
192.168.2.10
1. 安裝rsync
[root@localhost ~]# yum -y install rsync
2. 建立密碼認證文件,并且賦權限
[root@localhost ~]# cd /etc/ [root@localhost etc]# vi rsyncd.password wbc@wodata [root@localhost etc]# chmod 600 rsyncd.password
3 修改配置文件
[root@localhost ~]# cd /etc/ [root@localhost etc]# vi rsyncd.conf uid = root gid = root use chroot = no max connections = 3 timeout = 800 pid file = /var/run/rsyncd.pid lockfile = /var/run/rsyncd.lock log file = /var/log/rsyncd.log [uploads] path = /home/wbc/webroot/ROOT/upload ignore errors = yes host allow = 192.168.0.0/255.255.0.0 #hosts deny = * read only = no write only = no list = yes auth users = wbc secrets file = /etc/rsyncd.password
4. 安裝inotify-tools,安裝在etc下
需要有編譯環境
yum install make gcc gcc-c++
[root@localhost ~]# cd /etc/ [root@localhost etc]# wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz [root@localhost etc]# tar zxvf inotify-tools-3.14.tar.gz [root@localhost etc]# rm -rf inotify-tools-3.14.tar.gz [root@localhost ~]# cd /etc/inotify-tools-3.14/ [root@localhost inotify-tools-3.14]# ./configure --prefix=/etc/inotify [root@localhost inotify-tools-3.14]# make [root@localhost inotify-tools-3.14]# make install
5. 創建rsync復制腳本
將服務端的/home/wbc/webapps/ROOT/upload/同步到備份端的/home/wbc/webapps/ROOT/uploads/,進行冗余備份,不做刪除同步
[root@localhost etc]# vi rs-upload.sh #!/bin/bash src='/home/wbc/webapps/ROOT/upload/' passwordfile='/etc/rsyncd.password' user='wbc' host0='192.168.2.11' rsync_module='uploads' if [ ! -d "${src}" ]; then mkdir -p ${src} fi /etc/inotify/bin/inotifywait -mrq --timefmt '%Y%m%d %H%M%S' --format '%T %w %f' -e modify,delete,create,attrib ${src} | while read DATE TIME DIR file do /usr/bin/rsync -vzrtopg --progress ${src} ${user}@${host0}::${rsync_module} --password-file=${passwordfile} echo "${file} was rsynced at ${DATE}_${TIME} in ${DIR}" >> /var/log/rsync-upload.log 2>&1 done
6. 后臺執行腳本
[root@localhost etc]# sh rs-upload.sh &
如果有報錯 inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directory 解決方法: 32位系統:ln -s /etc/inotify/lib/libinotifytools.so.0 /usr/lib/libinotifytools.so.0 64位系統:ln -s /etc/inotify/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0
-
備份端安裝與配置
192.168.2.11
1. 安裝rsync
[root@localhost ~]# yum -y install rsync
2. 建立密碼認證文件,并且賦權限
[root@localhost ~]# cd /etc/ [root@localhost etc]# vi rsyncd.password wbc@wodata [root@localhost etc]# chmod 600 rsyncd.password
3 修改配置文件
[root@localhost ~]# cd /etc/ [root@localhost etc]# vi rsyncd.conf uid = root gid = root use chroot = no max connections = 3 timeout = 800 pid file = /var/run/rsyncd.pid lockfile = /var/run/rsyncd.lock log file = /var/log/rsyncd.log [uploads] path = /home/wbc/webapps/uploads ignore errors = yes host allow = 192.168.0.0/255.255.0.0 #hosts deny = * read only = no write only = no list = yes auth users = wbc secrets file = /etc/rsyncd.password
4. 新增自定義服務文件
[root@localhost etc]# vi /init.d/rsync #!/bin/sh #whoami #root #chkconfig: 345 51 49 #description: starts the rsync deamons # case "$1" in start) echo "Starting Rsync ..." rsync --daemon --config=/etc/rsyncd.conf ;; stop) echo "Stop Rsync ..." pkill rsync > /dev/null 2>/dev/null ;; restart) echo "Restart Rsync ..." $0 stop $0 start ;; *) echo "Usage: $1 {start|stop|restart}" ;; esac exit 0
5. 啟動服務
[root@localhost etc]# cd /init.d [root@localhost etc]# vi rsync #!/bin/sh #whoami #root #chkconfig: 345 51 49 #description: starts the rsync deamons # case "$1" in start) echo "Starting Rsync ..." rsync --daemon --config=/etc/rsyncd.conf ;; stop) echo "Stop Rsync ..." pkill rsync > /dev/null 2>/dev/null ;; restart) echo "Restart Rsync ..." $0 stop $0 start ;; *) echo "Usage: $1 {start|stop|restart}" ;; esac exit 0
6. 為自定義服務賦權限
[root@localhost init.d]# chmod +x rsync
7. 啟動服務
[root@localhost init.d]# service rsync start
-
目前為止已經安裝配置好了
1. 在服務端測試
[root@localhost upload]# mkdir test
正常情況會輸出以下信息 [root@localhost upload]# sending incremental file list ./ test/ sent 107 bytes received 19 bytes 252.00 bytes/sec total size is 0 speedup is 0.00
2. 在備份端做檢查
查看該目錄下是否有test文件夾 [root@localhost ~]# ll /home/wbc/webapps/uploads
-
引文
搭建文件同步服務:rsync+inotify
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
推薦閱讀更多精彩內容
- 隨著應用系統規模的不斷擴大,對數據的安全性和可靠性也提出的更好的要求,rsync在高端業務系統中也逐漸暴露出了很多...
- 1.1 inotify介紹 inotify是一種強大的、細粒度的、異步的文件系統事件控制機制。linux內核從2....
- 說明: 操作系統:CentOS 5.X 源服務器:192.168.21.129 目標服務器:192.168.21....
- 一、簡介 sersync是基于Inotify開發的,類似于Inotify-tools的工具。 sersync可以記...