-
服务端安装与配置
192.168.2.101. 安装rsync
[root@localhost ~]# yum -y install rsync2. 建立密码认证文件,并且赋权限
[root@localhost ~]# cd /etc/ [root@localhost etc]# vi rsyncd.password wbc@wodata [root@localhost etc]# chmod 600 rsyncd.password3 修改配置文件
[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.password4. 安装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 install5. 创建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 done6. 后台执行脚本
[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.111. 安装rsync
[root@localhost ~]# yum -y install rsync2. 建立密码认证文件,并且赋权限
[root@localhost ~]# cd /etc/ [root@localhost etc]# vi rsyncd.password wbc@wodata [root@localhost etc]# chmod 600 rsyncd.password3 修改配置文件
[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.password4. 新增自定义服务文件
[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 05. 启动服务
[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 06. 为自定义服务赋权限
[root@localhost init.d]# chmod +x rsync7. 启动服务
[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.002. 在备份端做检查
查看该目录下是否有test文件夹 [root@localhost ~]# ll /home/wbc/webapps/uploads -
引文
搭建文件同步服务:rsync+inotify
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐渐暴露出了很多...
- 1.1 inotify介绍 inotify是一种强大的、细粒度的、异步的文件系统事件控制机制。linux内核从2....
- 说明: 操作系统:CentOS 5.X 源服务器:192.168.21.129 目标服务器:192.168.21....
- 一、简介 sersync是基于Inotify开发的,类似于Inotify-tools的工具。 sersync可以记...