rsync有关的配置

Rsync基本配置

基于本地rsync同步:

[root@localhost ~]# mkdir /todir

[root@localhost ~]# rsync -a /boot /todir/

[root@localhost ~]# ls /todir/

boot

[root@localhost ~]# rm -rf /todir/*

[root@localhost ~]# ls /todir/

[root@localhost ~]# rsync -a /boot/ /todir/

[root@localhost ~]# ls /todir/

config-2.6.18-348.el5      symvers-2.6.18-348.el5.gz

grub                       System.map-2.6.18-348.el5

initrd-2.6.18-348.el5.img  vmlinuz-2.6.18-348.el5

lost+found

[root@localhost boot]# rsync -av /boot/ /todir/ --deletewKiom1OqwOCxaTnZAAI1gPmWVjQ941.jpg

删除目标有而源没有的文件(好像不对目录检查)

[root@dns1 todir]# mkdir /fromssh

[root@dns1 todir]# cd /

[root@dns1 /]# rsync -az [email protected]:/boot/ /fromssh/  

下行要对目录有读的权限            

The authenticity of host '192.168.150.110 (192.168.150.110)' can't be established.

RSA key fingerprint is 78:f9:23:4e:9d:a9:90:4c:c6:21:5e:60:44:22:d9:91.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.150.110' (RSA) to the list of known hosts.

[email protected]'s password: 

[root@dns1 /]# ls /fromssh/

config-2.6.18-371.el5      lost+found                 vmlinuz-2.6.18-371.el5

grub                       symvers-2.6.18-371.el5.gz

initrd-2.6.18-371.el5.img  System.map-2.6.18-371.el5

[root@dns1 /]# rsync -az /etc [email protected]:/tmp/

上行要对目录有写入的权限


基于RSYNC服务

[root@localhost ~]# rpm -q rsync

rsync-3.0.6-4.el5_7.1

[root@localhost ~]# cat /etc/rsyncd_users.db

ruser:pwd@123

[root@localhost ~]# chmod 600 /etc/rsyncd_users.db 

 加权限安全,和ftp一样的匿名用户一样,不可对/修改否则拒绝访问

[root@localhost ~]# cat /etc/rsyncd.conf 

uid = nobody

gid = nobody

use chroot = yes

log file = /var/log/rsyncd.log

pid file = /var/run/rsyncd.pid

[tools]

        path = /usr/src

        read only = yes

        dont compress =*.gz *.bz2 *.tgz *.zip

        auth users = ruser

        secrets file = /etc/rsyncd_users.db

[root@localhost ~]# chkconfig rsync on

[root@localhost ~]# service xinetd restart

[root@localhost ~]# netstat -ln | grep :873

tcp        0      0 0.0.0.0:873                 0.0.0.0:*           LISTEN      

客户端:

[root@test1 ~]# rsync [email protected]::tools

Password: 

drwxr-xr-x        4096 2014/06/24 20:54:13 .

drwxr-xr-x        4096 2009/10/01 22:58:39 debug

drwxr-xr-x        4096 2014/06/24 20:47:40 kernels

drwxr-xr-x        4096 2014/06/24 20:54:13 redhat

[root@test1 ~]# mkdir -p /data/fromrsync

[root@test1 ~]# rsync -avz --delete [email protected]::tools /data/fromrsync/

出错的原因

# iptables -L

# getenforce

# chmod 600 /etc/rsyncd_users.db

# service xinetd restart

# netstat -ln | grep :873

# /etc/xinetd.d/rsync

disable = yes


扩展实验: 实验目的是在目标主机修改时,本地实时备份


配置远程的备份目标主机

[root@node2 ~]# yum -y install  httpd

[root@node2 ~]# mkdir -p /webbak/www1

[root@node2 ~]# cat /etc/exports 

/webbak/www1 *(rw,no_root_squash)

[root@node2 ~]# service portmap restart

[root@node2 ~]# service nfs restart

[root@node2 ~]# chkconfig portmap on

[root@node2 ~]# chkconfig nfs on


配置本地的备份源主机

[root@node1 ~]# yum -y install gcc* httpd

[root@node1 ~]# tar -zxvf inotify-tools-3.14.tar.gz -C /usr/src/

[root@node1 ~]# cd /usr/src/inotify-tools-3.14/

[root@node1 inotify-tools-3.14]# ./configure 

[root@node1 inotify-tools-3.14]# make

[root@node1 inotify-tools-3.14]# make install

[root@node1 inotify-tools-3.14]# service portmap restart

[root@node1 inotify-tools-3.14]# chkconfig portmap on

[root@node1 inotify-tools-3.14]# mkdir -p /data/nfsdir

[root@node1 inotify-tools-3.14]# grep nfs /etc/fstab 

192.168.100.20:/webbak/www1     /data/nfsdir    nfs     defaults        0 0

[root@node1 inotify-tools-3.14]# mount -a

[root@node1 inotify-tools-3.14]# df -hT | grep nfs

               nfs    7.6G  1.1G  6.1G  16% /data/nfsdir

[root@node1 ~]# cat /usr/bin/in_rsync.sh

#!/bin/bash

/usr/local/bin/inotifywait -mrq -e modify,create,move,delete /var/www/html | while read DIR EVENT FILE

do

/usr/bin/rsync -aHvz --delete /var/www/html/ /data/nfsdir

done

[root@node1 ~]# chmod 700 /usr/bin/in_rsync.sh

[root@node1 ~]# echo "/usr/bin/in_rsync.sh" >> /etc/rc.local



[root@node1 ~]# /usr/bin/in_rsync.sh 

in_rsync.sh  &


&

echo $?显示上次行为是否成功,成功显示0










你可能感兴趣的:(配置,rsync)