-
服务端安装与配置
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可以记...