リモート同期1:rsync


rsyncはオープンソースの高速バックアップツールで、インクリメンタルバックアップをサポートし、接続と権限を維持し、同期アルゴリズムを採用し、転送前に圧縮を実行します.オフサイト・バックアップ、ミラー・サービス
A機器はrsyncサービス端末IP:A機器での操作:192.168.200.101
BマシンはrsyncクライアントIP:Bマシンでの操作:192.168.200.102
A機械の操作:192.168.200.101:
[root@crushlinux1 ~]# rpm -q rsync
rsync-2.6.8-3.1
[root@crushlinux1 ~]# yum -y install httpd
[root@crushlinux1 ~]# useradd rget
[root@crushlinux1 ~]# passwd rget
[root@crushlinux1 ~]# useradd rput
[root@crushlinux1 ~]# passwd rput
[root@crushlinux1 ~]# vi /etc/ssh/sshd_config
109 UseDNS no
110 AllowUsers rget rput
----------------        ----------------
[root@crushlinux1 ~]# service sshd restart
[root@crushlinux1 html]# mkdir upload
[root@crushlinux1 html]# chown -R rput:rput /var/www/html/
[root@crushlinux1 html]# setfacl -R -m user:daemon:rwx /var/www/html/upload
---------------- acl       ----------------
setfacl   acl  
getfacl   acl  
-R    
-m      
-x      
-b    
setfacl -R -b /var/www/html
setfacl -R -x user:daemon /var/www/html/upload
---------------------------------------------
[root@crushlinux1 html]# getfacl /var/www/html/upload/
[root@crushlinux1 html]# ls -ld /var/www/html/upload/
drwxrwxr-x+ 2 rput rput 4096 08-09 09:23 /var/www/html/upload/
    /var/www/html/upload/      ,daemon     rwx  
[root@crushlinux1 html]# setfacl -m default:user:daemon:rwx /var/www/html/upload
[root@crushlinux1 html]# getfacl /var/www/html/upload |grep default
  rsync   
1、  /etc/rsyncd.conf    
[root@crushlinux1 html]# vi /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes
address = A      :192.168.200.101
port = 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.200.0/24
[wwwroot]
        path = /var/www/html
        comment = Document Root os www.crushlinux.com
        read only = yes
        dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
        auth users = backuper
        secrets file = /etc/rsyncd_users.db
              
2、           
[root@crushlinux1 html]# vi /etc/rsyncd_users.db
backuper:pwd123
[root@crushlinux1 html]# chmod 600 /etc/rsyncd_users.db
[root@crushlinux1 html]# chmod o+r /var/www/html/
3、    
[root@crushlinux1 html]# rsync --daemon
[root@crushlinux1 html]# netstat -anpt |grep rsync
tcp        0      0 A      :192.168.200.101:873         0.0.0.0:*                   LISTEN      5243/rsync         
[root@crushlinux1 html]# ps -aux |grep rsync
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root      5243  0.0  0.1   5248   464 ?        Ss   10:02   0:00 rsync --daemon
root      5248  0.0  0.2   5020   680 pts/0    R+   10:02   0:00 grep rsync
4、                (  xinetd  )
[root@crushlinux1 html]# cat /etc/xinetd.d/rsync
     6          disable = no
    11          server_args     = --daemon
----------------        ----------------
[root@crushlinux1 ~]# yum -y install xinetd
[root@crushlinux1 ~]# service xinetd start
---------------------------------------------------------------------------------
    :
[root@crushlinux1 ~]# rsync /etc/fstab /opt/
[root@crushlinux1 opt]# rsync -rl /etc/fstab /boot/grub/ /opt/
    :
B      :192.168.200.102:
---------------------------------------------------------------------------------
[root@crushlinux2 ~]# rsync -avz rget@A      :192.168.200.101:/var/www/html/ /opt/
[root@crushlinux2 ~]# rsync -avz backuper@A      :192.168.200.101::wwwroot /root
[root@crushlinux2 ~]# rsync -avz rsync://backuper@A      :192.168.200.101/wwwroot /root
1、    ssh   
    A      :192.168.200.101 /var/www/html       /wwwroot     (        ,
    ,ACL  ,  /wwwroot     ,        )
[root@crushlinux2 ~]# mkdir -p /wwwroot
[root@crushlinux2 ~]# rsync -avzH --delete rget@A      :192.168.200.101:/var/www/html/ /wwwroot
[root@crushlinux2 ~]# ls /wwwroot/
           ,        
A      :192.168.200.101:
[root@crushlinux1 html]# rm -rf index.html upload/
[root@crushlinux1 html]# for i in {1..10}; do touch $i.txt; done
B      :192.168.200.102:
[root@crushlinux2 ~]# rsync -avzH --delete rget@A      :192.168.200.101:/var/www/html/ /wwwroot
[root@crushlinux2 ~]# ls /wwwroot/
2、    rsync   
B      :192.168.200.102:
[root@crushlinux2 ~]# mkdir /myweb
[root@crushlinux2 ~]# rsync -avzH --delete backuper@A      :192.168.200.101::wwwroot /myweb
3、    ssh   
[root@crushlinux2 ~]# cd /usr/share/doc/HTML/
[root@crushlinux2 HTML]# rsync -rlvz --delete zh-CN/ rput@A      :192.168.200.101:/var/www/html
----------------------------------------------------------------------------------
1、ssh         
B      :192.168.200.102:
[root@crushlinux2 ~]# ssh-keygen -t rsa
[root@crushlinux2 ~]# cd .ssh/
[root@crushlinux2 .ssh]# cat id_rsa.pub >authorized_keys
[root@crushlinux2 .ssh]# cd ../
[root@crushlinux2 ~]# scp -pr .ssh/ rget@A      :192.168.200.101:/home/rget/  
[root@crushlinux2 ~]# ssh rget@A      :192.168.200.101
[root@crushlinux2 ~]# rsync -avzH --delete rget@A      :192.168.200.101:/var/www/html/ /wwwroot
2、rsync         
[root@crushlinux2 ~]# export RSYNC_PASSWORD=pwd123
[root@crushlinux2 ~]# rsync -avzH --delete backuper@A      :192.168.200.101::wwwroot /wwwroot/
[root@crushlinux2 ~]# vi rsync_get_wwwroot.sh
----------------------------
#!/bin/bash
CMD="/usr/bin/rsync"
RSYNC_USER="backuper"
RSYNC_PASSWORD="pwd123"
ARGS="-az --delete"
SRC="192.168.4.200::wwwroot"
DST="/wwwroot"
mkdir -p $DST
$CMD $ARGS $RSYNC_USER@$SRC $DST
----------------------------
[root@crushlinux2 ~]# crontab -e
30 20 * * * /root/rsync_get_wwwroot.sh
[root@crushlinux2 ~]# service crond restart
[root@crushlinux2 ~]# chkconfig crond on

本文は“Crushlinux”のブログから出て、転載して作者と連絡してください!