转载http://blog.chinaunix.net/uid-23354495-id-3111498.html
#源码包存放目录
cd /usr/local/src
#下载源码包
wget -c http://rsync.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz
#解压缩及配置,编译,安装
tar -xzvf rsync-3.0.9.tar.gz
cd rsync-3.0.9
./configure
make
make install
使用举例:
ex1: copy rsync-3.0.9 to aa (localhost)
[root@Monitor01 src]# mkdir -p aa
[root@Monitor01 src]# rsync -av rsync-3.0.9 aa
sending incremental file list
rsync-3.0.9/
rsync-3.0.9/.gitignore
rsync-3.0.9/COPYING
rsync-3.0.9/Doxyfile
rsync-3.0.9/INSTALL
rsync-3.0.9/Makefile
......
[root@Monitor01 src]# rsync -av rsync-3.0.9/ aa
[root@Monitor01 src]# ll aa
total 5320
-rw-rw-r-- 1 root root 5142 Jan 18 2009 access.c
-rw-r--r-- 1 root root 20808 Feb 27 11:52 access.o
-rw-rw-r-- 1 root root 3174 Nov 3 2007 aclocal.m4
-rw-rw-r-- 1 root root 30756 May 30 2011 acls.c
-rw-r--r-- 1 root root 4480 Feb 27 11:52 acls.o
......
ex2:copy rsync-3.0.9 to host--Monitor02(from localhost to remote host)
[root@Monitor02 src]# rsync -av rsync-3.0.9 aa
rsync: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
遇到以上错误,解决方法如下:
找到libiconv.so.2的路径
[root@Monitor02 src]# find / -name libiconv.so*
/usr/local/lib/libiconv.so
/usr/local/lib/libiconv.so.2.5.1
/usr/local/lib/libiconv.so.2
/usr/local/src/libiconv-1.14/lib/.libs/libiconv.so
/usr/local/src/libiconv-1.14/lib/.libs/libiconv.so.2.5.1
/usr/local/src/libiconv-1.14/lib/.libs/libiconv.so.2
…….
把相关路径添加到动态链接库配置文件
[root@Monitor02 src]# echo "/usr/local/lib/">>/etc/ld.so.conf
更新相关库文件
[root@Monitor02 src]# /sbin/ldconfig
[root@Monitor01 src]# rsync -av rsync-3.0.9 192.168.164.131:/usr/local/src/aa
root@192.168.164.131's password:
sending incremental file list
rsync-3.0.9/
rsync-3.0.9/.gitignore
rsync-3.0.9/COPYING
......
sent 6278442 bytes received 5228 bytes 837822.67 bytes/sec
total size is 6260141 speedup is 1.00
[root@Monitor01 src]#
ex3: C/S module
server: Monitor01 192.168.164.129
client:Monitor02 192.168.164.131
server:
[root@Monitor01 rsync-3.0.9]# vim /etc/rsyncd.conf
#FileName:rsync.conf
#Desc:An example for rsync configuration
#Created By:fedoracle
#Date:2012/02/27
uid=nobody
gid=nobody
use chroot=no
max connections=10
strict modes=yes
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
log file=/var/log/rsyncd.log
[efast]
path=/usr/local/apache/htdocs/efast/program #要备份目录
comment=test efast
ignore errors
read only=no
write only=no
hosts allow=*
hosts deny=192.168.111.111
list=true
uid=root
gid=root
auth users=backup #用于C/S间连接的用户
secrets file=/etc/rsync.secrets #auth users参数中指定的用户的用户名及密码,格式为user:pw
[root@Monitor01 rsync-3.0.9]# vim /etc/rsync.secrets
backup:backup
[root@Monitor02 src]# chmod 600 /etc/rsync.secrets #权限一定要设置好!
client:
[root@Monitor02 src]# vim /etc/rsync.secrets
backup
[root@Monitor02 src]# chmod 600 /etc/rsync.secrets #权限一定要设置好!
测试:
[root@Monitor02 src]# rsync -vzrtopg --delete --progress --exclude "*access*" --exclude "*debug*" backup@192.168.164.129::efast /test --password-file=/etc/rsync.secrets
......
[root@Monitor02 src]# rsync -vzrtopg --delete --progress --exclude "*access*" --exclude "*debug*" backup@192.168.164.129::efast /test --password-file=/etc/rsync.secrets
receiving incremental file list
sent 405 bytes received 102610 bytes 68676.67 bytes/sec
total size is 47611598 speedup is 462.18
[root@Monitor02 src]#
……
成功!
备份策略:每天一点进行同步
crontab -e
00 1 * * * /usr/bin/rsync -vzrtopg --delete --progress --exclude "*access*" --exclude "*debug*" backup@192.168.164.129::efast /test --password-file=/etc/rsync.secrets
错误1:
[root@MySql02 src]# rsync -vzrtopg --delete --progress --exclude "*access*" --exclude "*debug*" backup@192.168.164.129::test /usr/local/src/aa --password-
file=/etc/rsync.secret
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Receiver=3.0.9]
查看server日志
[root@MySql01 src]# cat /var/log/rsyncd.log
2012/03/05 13:57:22 [8051] rsyncd version 3.0.9 starting, listening on port 873
2012/03/05 13:57:38 [8058] name lookup failed for 192.168.164.133: Name or service not known
2012/03/05 13:57:38 [8058] connect from UNKNOWN (192.168.164.133)
2012/03/05 13:57:38 [8058] rsync: chdir /usr/local/apache/htdocs/efast failed
: No such file or directory (2)
2012/03/05 14:06:05 [8072] name lookup failed for 192.168.164.133: Name or service not known
2012/03/05 14:06:05 [8072] connect from UNKNOWN (192.168.164.133)
2012/03/05 14:06:05 [8072] rsync: chdir /usr/local/apache/htdocs/efast failed
: No such file or directory (2)
由错误日志可知,没有/usr/lcoal/apache/htdocs/efast这个目录。知道为啥错了,就好想办法解决了,哈哈!!!
错误2:
[root@MySql01 inotify-tools-3.14]# rsync -vzrtopg --delete --progress --exclude "*access*" --exclude "*debug*" backup@192.168.164.129::test /usr/local/src/aa
--password-file=/etc/rsync.secret
@ERROR: auth failed on module test
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Receiver=3.0.9]
[root@MySql01 inotify-tools-3.14]# cat /var/log/rsyncd.log | tail -n 5
2012/03/05 14:12:49 [8096] building file list
2012/03/05 14:12:49 [8096] sent 211 bytes received 106 bytes total size 44
2012/03/05 14:47:38 [10667] name lookup failed for 192.168.164.129: Name or service not known
2012/03/05 14:47:38 [10667] connect from UNKNOWN (192.168.164.129)
2012/03/05 14:47:38 [10667] auth failed on module test from unknown (192.168.164.129): password mismatch
看到错误信息了么?password mismatch!!!检查一下你的密码配置文件吧,嘿嘿~~~
rsync+inotify
实时备份:
Inotify
不需要对被监视的目标打开文件描述符,而且如果被监视目标在可移动介质上,那么在 umount 该介质上的文件系统后,被监视目标对应的 watch 将被自动删除,并且会产生一个 umount 事件。
Inotify 既可以监视文件,也可以监视目录。
Inotify 使用系统调用而非 SIGIO 来通知文件系统事件。
Inotify 使用文件描述符作为接口,因而可以使用通常的文件 I/O 操作select 和 poll 来监视文件系统的变化。
Inotify 可以监视的文件系统事件包括:
IN_ACCESS,即文件被访问
IN_MODIFY,文件被 write
IN_ATTRIB,文件属性被修改,如 chmod、chown、touch 等
IN_CLOSE_WRITE,可写文件被 close
IN_CLOSE_NOWRITE,不可写文件被 close
IN_OPEN,文件被 open
IN_MOVED_FROM,文件被移走,如 mv
IN_MOVED_TO,文件被移来,如 mv、cp
IN_CREATE,创建新文件
IN_DELETE,文件被删除,如 rm
IN_DELETE_SELF,自删除,即一个可执行文件在执行时删除自己
IN_MOVE_SELF,自移动,即一个可执行文件在执行时移动自己
IN_UNMOUNT,宿主文件系统被 umount
IN_CLOSE,文件被关闭,等同于(IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
IN_MOVE,文件被移动,等同于(IN_MOVED_FROM | IN_MOVED_TO)
注:上面所说的文件也包括目录。
在系统中执行如下命令,如果能看到相关结果,说明你当前的系统对inotify支持良好,如果没有相关信息,请自行编译内核使其支持inotify机制。
[root@MySql01 src]# uname -r
2.6.18-274.el5
[root@MySql01 src]# ll /proc/sys/fs/inotify
total 0
-rw-r--r-- 1 root root 0 Mar 5 14:18 max_queued_events
-rw-r--r-- 1 root root 0 Mar 5 14:18 max_user_instances
-rw-r--r-- 1 root root 0 Mar 5 14:18 max_user_watches
有了以上信息后就可以下载安装inotify-tools了:
[root@MySql01 src]# wget -c http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.g
[root@MySql01 src]# tar -xvf inotify-tools-3.14.tar.gz
[root@MySql01 src]# ./configure
[root@MySql01 src]# make && make install
安装好后,便可以通过相关shell脚本利用inotify的实时监控来同步server的文件到backup机器上
例:把mysql01上/usr/local/test/下的东东实时同步到mysql02上的/usr/local/test下
MySql01:
1.安装rsync,略过
2.安装inotify,略过
3.编写inotify脚本
[root@MySql01 src]# cat inotify_test.sh
#!/bin/bash
#FileName:inotify_test.sh
#Desc:test inotify+rsync
#Created By:xiaozhenggang(fedoracle)
#Date:2012/03/05
HOST=192.168.164.133
SRC=/usr/local/test/
DST=test1
USER=backup
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y/ %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $SRC | while read files
do
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/etc/rsync.secret1 $SRC $USER@$HOST::$DST
echo "${files} was rsynced">>/tmp/rsync.log 2>&1
done
4.把3的脚本添加到启动后台运行
[root@MySql01 src]# chmod +x inotify_test.sh
[root@MySql01 src]# ./inotify_test.sh &
[root@MySql01 src]# echo "inotify-test.sh &">>/etc/rc.d/rc.local
MySql02:
1.安装、配置rsync
安装略过
编辑配置文件:
[root@MySql02 src]# cat /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log
[test1]
path = /usr/local/test/
comment = test
ignore errors
read only = no
write only = no
hosts allow = *
hosts deny = 1.1.1.1
list = yes
uid = root
gid = root
auth users = backup
secrets file = /etc/rsync.secret1
编辑密码相关文件:权限一定要为600
[root@MySql02 src]# cat /etc/rsync.secret1
backup:backup
另须在MySql01上的/etc/下也建立一个rsync.secret1文件存放密码,这里权限也要是600
[root@MySql01 src]# cat /etc/rsync.secret1
backup
以daemon 启动并加到开机启动
[root@MySql02 src]# /usr/bin/rsync --daemon
[root@MySql02 src]# echo "/usr/bin/rsync --daemon" >> /etc/rc.d/rc.local
3.等待MySql01更新
测试:
1.
[root@MySql02 test]# pwd
/usr/local/test
[root@MySql02 test]# ll
total 0
[root@MySql01 src]# cd /usr/local/test
[root@MySql01 test]# pwd
/usr/local/test
[root@MySql01 test]# ll
total 0
[root@MySql01 test]# echo "HHHHHHHHHHHHHHHHHHHHHHH" > test.txt
[root@MySql01 test]# sending incremental file list
./
test.txt
24 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2)
sent 91 bytes received 30 bytes 242.00 bytes/sec
total size is 24 speedup is 0.20
sending incremental file list
sent 43 bytes received 8 bytes 102.00 bytes/sec
total size is 24 speedup is 0.47
[root@MySql02 test]# ll
total 4
-rw-r--r-- 1 root root 24 Mar 5 16:45 test.txt
2.
[root@MySql01 test]# mkdir test
[root@MySql01 test]# sending incremental file list
./
test/
sent 75 bytes received 15 bytes 60.00 bytes/sec
total size is 24 speedup is 0.27
[root@MySql02 test]# ll
total 8
drwxr-xr-x 2 root root 4096 Mar 5 16:46 test
-rw-r--r-- 1 root root 24 Mar 5 16:45 test.txt
[root@MySql01 test]# rm -rf test
[root@MySql01 test]# sending incremental file list
./
deleting test/
sent 50 bytes received 11 bytes 122.00 bytes/sec
total size is 24 speedup is 0.39
[root@MySql02 test]# ll
total 4
-rw-r--r-- 1 root root 24 Mar 5 16:45 test.txt
分享到:
相关推荐
执行rsync同步时出现以下报错 [root@client abc]# rsync -azH --delete --password-file=/etc/server.pass /opt/abc/ backuper@192.168.5.129::wwwroot rsync: failed to set times on /. (in wwwroot): Operation ...
rsync error: error starting client-server protocol (code 5) at main.c(1516) [Receiver=3.0.9] rsync服务器配置如下 [root@localhost ~]# cat /etc/rsyncd.conf # /etc/rsyncd: configuration
rsync常见错误及解决方法rsync常见错误及解决方法rsync常见错误及解决方法
什么是RSYNC? Rsync是一种用于远程和本地文件的快速且用途广泛的文件复制工具。 Rsync使用增量传输算法,该算法提供了一种非常快速的方法来使远程文件同步。 它通过仅通过链接发送文件中的差异来做到这一点,而无需...
rsnapshot:使用rsync备份数据的工具(如果要获取帮助,请使用https:lists.sourceforge.netlistslistinforsnapshot-discuss)
Rsync+ssh双机同步测试及问题解决 Rsync+ssh双机同步测试及问题解决是指使用Rsync和ssh协议实现双机之间的文件同步和备份。本文将详细介绍如何配置ssh的自动登录、rsync的配置、同步问题和解决方案。 一、配置ssh...
适用于Centos7.9的rsync 工具安装包 rsync-3.1.2-10.el7.x86_64.rpm
rsync-3.1.2-4.el7.x86_64.rpm linux系统下rsync安装包
在配置中,需要在安装目录中找到 rsync.conf 文件,并进行配置。Rsync.conf 文件的内容包括: * pid file = /var/run/rsyncd.pid * lock file = /var/run/rsync.lock * log file = /var/log/rsyncd.log * uid = ...
rsync 的最新版本可以从 http://rsync.samba.org/rsync/获得。 rsync 的特性如下: 1、可以镜像保存整个目录树和文件系统。 2、可以很容易做到保持原来文件的权限、时间、软硬链接等等。 3、无须特殊权限即可安装...
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3] 原因: 服务器端的目录不存在或无权限,创建目录并修正权限可解决问题。 问题二: @ERROR: auth failed on ...
下载最新的rsync 2.4.3源文件编译,看rsync.samba.org ,据我所知, 只有2.4.3才支持 镜像时的排除选项 –include and –exclude, 编译后得到一个执行文件rsync,仅需这个执行文件即可 2. 编辑配置文件/etc...
rsync参数详解 rsync [OPTION]... SRC DEST rsync [OPTION]... SRC [USER@]HOST:DEST rsync [OPTION]... [USER@]HOST:SRC DEST rsync [OPTION]... [USER@]HOST::SRC DEST rsync [OPTION]... SRC [USER@]HOST::...
今天在帮客户配置机器的时候提示cwrsync rsync error rsync error: some files/attrs were not transferred,最终发现原来是用mcafee设置了文件权限不可写导致,特整理下方便需要的朋友
文章目录HYPERLINK"http://www.centos.bz/2011/06/rsync-server-setup/"\l"什么是rsync"\o"什么是rsync"什么是rsyncHYPERLINK"http://www.centos.bz/2011/06/rsync-server-setup/"\l"rsync的安装"\o"rsync的安装...
示意图:Rsync 版本 [root@mail video]# rsync –version ... Web site: rsync.samba.org Capabilities: 64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints, socketpairs, hardlinks, symlinks, IPv
C:Program FilescwRsyncbin>rsync.exe -av rsync://192.168.0.211:52326/test /cygdrive/e/www.01314.cn/rsync @ERROR: invalid uid nobody rsync error: error starting client-server protocol (code 5) at main.c...
rsync 数据实时同步实现方案 rsync 是一个 Unix/Linux 系统下的文件同步和传输工具,能够快速、安全、压缩地复制和同步文件。rsync 通过“rsync 算法”提供了一个客户机和远程服务器的文件同步的快速方法。 rsync ...
2. rsync [OPTION]... SRC [USER@]HOST:DEST 3. rsync [OPTION]... [USER@]HOST:SRC DEST 4. rsync [OPTION]... [USER@]HOST::SRC DEST 5. rsync [OPTION]... SRC [USER@]HOST::DEST 6. rsync [OPTION]... rsync://...
Rsync 详解及 Linux 和 Windows 下的配置 Rsync 是一个远程数据同步工具,通过 LAN/WAN 快速同步多台主机间的文件。Rsync 使用所谓的“Rsync 算法”来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个...