3,开始安装rsync软件
在192.168.0.51,192.168.0.50,192.168.0.53按照如下顺序安装rsync软件
3.1,查看线上rsync版本
通过rsync -h找到查看帮助,找到 --version参数。
[root@localhost ~]# rsync --version
rsync version 3.0.6 protocol version 30
Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.
Web site:
…
[root@localhost ~]#
3.2,下载
wget
3.3,编译安装
# 解压缩
[root@localhost root]# tar -xvf rsync-3.0.6.tar.gz
[root@localhost rsync-3.0.6]# cd rsync-3.0.6
# 通过./configure --help查看编译参数,这里选取--prefix参数
[root@localhost rsync-3.0.6]# ./configure --prefix=/usr/local/rsync-3.0.6/
......
config.status: creating lib/dummy
config.status: creating zlib/dummy
config.status: creating popt/dummy
config.status: creating shconfig
config.status: creating config.h
rsync 3.0.6 configuration successful
[root@localhost rsync-3.0.6]# make
......
gcc -std=gnu99 -I. -I. -g -O2 -DHAVE_CONFIG_H -Wall -W -I./popt -c popt/poptparse.c -o popt/poptparse.o
gcc -std=gnu99 -g -O2 -DHAVE_CONFIG_H -Wall -W -I./popt -o rsync flist.o rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o main.o checksum.o match.o syscall.o log.o backup.o options.o io.o compat.o hlink.o token.o uidlist.o socket.o hashtable.o fileio.o batch.o clientname.o chmod.o acls.o xattrs.o progress.o pipe.o params.o loadparm.o clientserver.o access.o connection.o authenticate.o lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o lib/md5.o lib/permstring.o lib/pool_alloc.o lib/sysacls.o lib/sysxattrs.o zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o popt/findme.o popt/popt.o popt/poptconfig.o popt/popthelp.o popt/poptparse.o
[root@localhost rsync-3.0.6]#
[root@localhost rsync-3.0.6]# make install
mkdir -p /usr/local/rsync-3.0.6/bin
/usr/bin/install -c -m 755 rsync /usr/local/rsync-3.0.6/bin
mkdir -p /usr/local/rsync-3.0.6/share/man/man1
mkdir -p /usr/local/rsync-3.0.6/share/man/man5
if test -f rsync.1; then /usr/bin/install -c -m 644 rsync.1 /usr/local/rsync-3.0.6/share/man/man1; fi
if test -f rsyncd.conf.5; then /usr/bin/install -c -m 644 rsyncd.conf.5 /usr/local/rsync-3.0.6/share/man/man5; fi
[root@localhost rsync-3.0.6]#
3.3,check命令
[root@localhost ~]# rsync -h
rsync version 3.0.6 protocol version 30
Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.
Web site:
看来已经安装好,命令可以直接使用。
3.4,配置rsyncd.conf启动参数文件
[root@localhost ~]# vim /etc/rsyncd.conf
uid=nginx #用户id名称
gid=nginx #用户所属组ID
use chroot=no
max connections=10
strict modes=yes
port=873
address=192.168.0.50 #本机地址,3台IP地址都填写自己的IP地址
#ignore erros
read only=no
list=no
auth users=nginx
secrets file=/etc/rsync.pas #密码认证文件地址
hosts allow=192.168.0.51,192.168.0.53 #允许rsync同步的ip地址,除了本机地址的其它2个ip地址。
pid file=/home/nginx/rsync/rsyncd.pid
lock file=/home/nginx/rsync/rsync.lock
log file=/home/nginx/rsync/rsyncd.log
[web]
path=/usr/local/nginx/ # 这里的web就是rsync同步的参数名字,path就是同步的目录
comment=mirror for web
3.5,添加认证文件
# 创建认证文件
[root@localhost ~]# vim /etc/rsync.pas
nginxpasspd #密码
nginx:nginxpasswd #用户名:密码
【PS】:不这样设置两行就会用户验证失败。
# 赋予权限
[root@localhost ~]# chmod 600 /etc/rsync.pas
3.6,创建目录并赋予权限
# 创建目录
mkdir -p /usr/local/nginx
mkdir -p /home/nginx/rsync
mkdir -p /usr/local/nginx/web
# 赋予权限
chown -R nginx.nginx /usr/local/nginx /home/nginx/rsync/ /usr/local/nginx/web
3.7,启动rsync服务
[root@localhost ~]# rsync --daemon --config=/etc/rsyncd.conf
[root@localhost ~]# ps -eaf|grep rsync
root 1387 1 0 Jun28 ? 00:00:00 rsync --daemon --config=/etc/rsyncd.conf
root 3201 3136 0 00:50 pts/0 00:00:00 grep rsync
[root@localhost ~]#
启动成功
3.8,测试rsync功能
一些调试报错经历:
[root@localhost ]#
rsync -vzrt --delete --progress --itemize-changes --exclude-from=/home/nginx/exclude_fastdfs.txt /data/fastdfs/data nginx@192.168.0.53::web --password-file=/etc/rsync.pas
password file must not be other-accessible
continuing without password file
Password:
@ERROR: auth failed on module web
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
[root@localhost ]#
说明:这是因为/etc/rsync.pas的权限不对,应该设置为600。如:chmod 600 /etc/rsync.pas
[root@localhost inotify-tools-3.14]#
rsync -vzrt --delete --progress --itemize-changes --exclude-from=/home/nginx/exclude_fastdfs.txt /data/fastdfs/data nginx@192.168.0.53::fastdfs --password-file=/home/nginx/rsync.pas
@ERROR: auth failed on module fastdfs
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
[root@localhost inotify-tools-3.14]# ll
去查看192.168.0.53的log信息
[root@localhost inotify-tools-3.14]# tail -f /home/nginx/rsync/rsyncd.log
2014/06/28 17:24:14 [19031] auth failed on module web from unknown (192.168.0.50): missing secret for user "nginx"
2014/06/28 17:28:21 [19198] name lookup failed for 192.168.0.50: Name or service not known
2014/06/28 17:28:21 [19198] connect from UNKNOWN (192.168.0.50)
2014/06/28 17:28:21 [19198] auth failed on module web from unknown (192.168.0.50): missing secret for user "nginx"
2014/06/28 17:28:48 [19488] name lookup failed for 192.168.0.50: Name or service not known
去192.168.0.53上面修改认证文件
[root@localhost data]# vim /etc/rsync.pas
nginxpasswd
nginx: nginxpasswd
将原来只有一行密码的改成如此2行,就好使了,能使用rsync功能了。
测试验证,在192.168.0.50的空目录下,建立测试文件 1.txt,2.txt
[root@localhost data]# cd /usr/local/nginx/web
[root@localhost web]# ll
总用量 0
[root@localhost web]# vim 1.txt
[root@localhost web]# vim 2.txt
[root@localhost web]# mkdir test
[root@localhost web]# vim ./test/3.txt
[root@localhost web]# ll /usr/local/nginx/web
总用量 12
-rw-r--r--. 1 nginx nginx 6 6月 28 19:18 1.txt
-rw-r--r--. 1 nginx nginx 6 6月 28 19:18 2.txt
drwxr-xr-x. 2 nginx nginx 4096 6月 28 19:22 test
[root@localhost web]#
在rsync同步之前,先去53上面check下目标目录,为空目录,如下所示:
[root@localhost web]# ll /usr/local/nginx/web
总用量 0
[root@localhost web]#
在192.168.0.50上执行rsync命令,同步目录
[root@localhost web]# /usr/bin/rsync -auzv --progress --delete /usr/local/nginx/web nginx@192.168.0.53::webroot --password-file=/etc/rsync.pas
sending incremental file list
web/
web/1.txt
6 100% 0.00kB/s 0:00:00 (xfer#1, to-check=3/5)
web/2.txt
6 100% 5.86kB/s 0:00:00 (xfer#2, to-check=2/5)
web/test/
web/test/3.txt
3 100% 2.93kB/s 0:00:00 (xfer#3, to-check=0/5)
sent 264 bytes received 73 bytes 224.67 bytes/sec
total size is 15 speedup is 0.04
[root@localhost web]#
再去192.168.0.53上check下,看到文件已经同步过来,测试成功,如下所示:
[root@localhost web]# ll
总用量 12
-rw-r--r--. 1 nginx nginx 6 6月 28 19:18 1.txt
-rw-r--r--. 1 nginx nginx 6 6月 28 19:18 2.txt
drwxr-xr-x. 2 nginx nginx 4096 6月 28 19:22 test
[root@localhost web]#