Rsync Data Synchronization on Linux in Three Steps

Test Environment Description

Server : 192.168.1.147
Client : 192.168.1.190
server and Client for directory all is /data/test/
: in directory operation , data to server for directory
 
1.0: use rsyncimplement data Sync
    :RsyncIntroduction

     rsync, remote synchronize is implement function , in file simultaneously , can file Permission, , information . rsyncis “rsync ”provide a and file server file Sync , and can via sshmethod file , very , is .

     

:server and all need Installationrsync

  1: system (system already ,method , system )

    yum install rsync

2:

    tar  zxvf  rsync-3.0.7.tar.gz

    cd rsync-3.0.7 

    ./configure –prefix=/usr/local/rsync  

    &make &&make install

: server configuration (configuration file )

 1: configuration file . /etcno rsyncd.confthis file , not we can
   Vim  /etc/rsyncd.conf 

[global]                               #configuration

uid = nobody

gid = nobody

use chroot = no

timeout = 300                     

port = 873                                 #is 873, can not

max connections = 30                       #

pid file = /var/log/rsyncd.pid              # IDin , can not to

     lock file = /var/run/rsyncd.lock             #this can not to      

log file = /var/log/rsyncd.log            #file in , this to

log format = %t %a %m %f %b    #Log %t %a IPAddress %m %f file %b %uuser

[backup]                                  # to Sync

path = /data/test                         # to Sync directory

comment =test                             #this

read only = no                            # nocan file ,yes

write only = no                           # nocan file ,yesnot can Download

list = no                                 #is provide

ignore errors                             #some IOError
hosts allow = 192.168.1.0/24               #via IPAddress  

     hosts deny =  *                            #IP

      auth users = www                    #system use user , no .

secrets file=/etc//rsyncd.secret           #file

2. setting rsyncserver and directory Permission;

vi    /etc//rsyncd.secret

www:123456                       #user www: Password123456)

chmod 600  /etc/rsyncd.secret    #,

chmod 777  /data/test  -R        #directory Permission,

3: Start and

A:daemonmethod Start

     /usr/bin/rsync –daemon –config=/etc/rsyncd.conf
       
     : kill pid or pkill rsync

B:xinetdrsync

       vim /etc/xinetd.d/rsync  (will yesno)

             

    /etc/init.d/xinetd start

 

:linuxconfiguration and Test

 1: Environment Configuration

A:need rsync, configuration file

/usr/bin/rsync –daemon or /etc/init.d/xinetd start
B:a file , need and server Password   

    echo 123456 > /etc/rsyncd.secret

     chmod 600  /etc/rsyncd.secret

2:command
   rsync –vzrtopg –delete /data/test/ www@192.168.1.147::backup   –password-file=/etc/rsyncd.secret  

 

need :
  vzrtopg -v -zfor file in -r for directory -tfile -p -o -g
–delete server in no data

      –exclude-from=file file file , not
 /data/test/   need Sync directory
www server backup user
backup server to

 
3: not , in

  cat  /root/rsync.sh
 
nohup sh /root/rsync.sh &

: Summary
      1: to Issues
in configuration rsync, for Client and server not . to is data to server , is server data to Client. is to server , is in command server data to . command
  rsync –vzrtopg –delete  www@192.168.1.147::backup  /data/test/ –password-file=/etc/rsyncd.secret  
method is :
  rsync –vzrtopg –delete /data/test/ www@192.168.1.147::backup   –password-file=/etc/rsyncd.secret  

. rsync and scp method , , server , can data to , can directory data to . configuration (need configuration file ) server

2:
 

method , in not has not
A:server use

server , need will data to server for directory , , server server , need in rsync, file ,
/data/test/ to server backupfor directory

rsync –vzrtopg –delete /data/test/ www@192.168.1.147::backup   –password-file=/etc/rsyncd.secret    

 B:server use

  has server (svnserver ) need data to not for server . can svnserver server . from server for data .

    rsync –vzrtopg –delete  www@192.168.1.147::backup  /data/test/ –password- file=/etc/rsyncd.secret 
   server backup directory to Client /data/test/directory
3: rsync (《can linuxserver 》)
rsyncin Linux/Unixis a to and service .rsynchas , , support , via rsynccan for not data . is system Scale not , for data and can to . rsyncin system not . rsyncdata need all file perform for , then , data is very . , rsyncnot can , data . . rsync+inotifythese Issues
 
2.0: rsync+inotifyimplement data Sync
    : inotifyIntroduction
Inotifyis , , file system , Linuxfrom 2.6.13, for Inotify support , via Inotifycan file system , , ,

:server all need rsync, inotify
rsyncconfiguration 1.0
#cd /usr/local/src/

#wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz

#tar xzvf inotify-tools-3.14.tar.gz

#cd inotify-tools-3.14

#./configure

#make

#make install
 

this “/usr/local/bin/inotifywait: error while loading shared libraries: libinotifytools.so.0”can the following :
ln -sv /usr/local/lib/libinotify* /usr/lib/
ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0

  : in
      vim /root/rsync.sh
      #!/bin/bash
     src=/data/test/
     des=backup
     ip=192.168.1.147
   /usr/local/bin/inotifywait -mrq –timefmt '%d/%m/%y %H:%M' –format '%T %w%f' -e   modify,delete,create,attrib $src | while read file
    do
    rsync -vzrtopg –delete –progress $src
www@$ip::$des –password-file=/etc/rsyncd.secret && echo "$src was rsyncd"
done
   nohup sh/root/rsync.sh& 
 3.0: Sersyncimplement data Sync
  : SersyncIntroduction
Sersync inotify and rsyncfor server perform , inotifyfile system , rsyncis use , is for file not part perform operation , use file system method perform . , is use file tool . tool and tool has :
· sersyncis use c++, file , tool , ;

· , configuration ;

· use perform Sync, can server status ;

· , via for file , if , 10for file ;

· crontabfunction , in xmlconfiguration file , can you to , ;

· socket and http, can perform ;

  : Sersync configuration (in Sersync,)
        1: Client and server respectively rsync, server (1.147) configuration file , 1.0 
2: in configuration Sersyns
              tar xzvf sersync2.5_64bit_binary_stable_final.tar.gz
              mv GNU-Linux-x86 /usr/local/sersync 
3: configuration file
           vim /usr/local/sersync/confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host> #for , can .
    <debug start="true"/> #in sersyncin Run , inotify, rsynccommand .
    <fileSystem xfs="false"/> #for xfsfile system user , need will this .
    <filter start="false"> #system file , file not
    <exclude expression="(.*)/.svn"></exclude>
    <exclude expression="(.*)/.gz"></exclude>
    <exclude expression="^info/*"></exclude>
    <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>            #inotifyfile ,    
    <delete start="true"/>
    <createFolder start="true"/>
    <createFile start="false"/>        
    <closeWrite start="true"/>
    <moveFrom start="true"/>
    <moveTo start="true"/>
    <attrib start="false"/>
    <modify start="false"/>
    </inotify>
    <sersync>               #perform data Sync
    <localpath watch="/data/test">                          # directory
        <remote ip="192.168.1.147" name="backup"/>    # IP and rsync
        <!–<remote ip="192.168.8.39" name="tongbu"/>–>
        <!–<remote ip="192.168.8.40" name="tongbu"/>–>
    </localpath>
    <rsync>
        <commonParams params="-artuz"/>
        <auth start="true" users="www" passwordfile="/etc/rsyncd.secret"/>    
#user , user
        <userDefinedPort start="false" port="874"/><!– port=874 –>
        <timeout start="false" time="100"/><!– timeout=100 –>
        <ssh start="false"/>
    </rsync>
    <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!–default every 60mins execute once–>
    <crontab start="true" schedule="600"><!–600mins–> #600s
        <crontabfilter start="false">
        <exclude expression="*.php"></exclude>
        <exclude expression="info/*"></exclude>
        </crontabfilter>
    </crontab>
    <plugin start="false" name="command"/> #name .
    </sersync>
<plugin name="command"> ##
    <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!–prefix /opt/tongbu/mmm.sh suffix–>
    <filter start="false">
        <include expression="(.*)/.php"/>
        <include expression="(.*)/.sh"/>
    </filter>
    </plugin>
</head>
4: Sersync
A:service
          /usr/local/sersync/sersync2 -d -r -n 8 -o /usr/local/sersync/confxml.xml
-d -rwill already in file -n 10 -oconfiguration file
B: Sersyncstatus Script, if service service
              vim /root/tool/sersync.sh
                  #!/bin/bash
SERSYNC="/usr/local/sersync/sersync2"

CONF_FILE="/usr/local/sersync/confxml.xml"

STATUS=$(ps aux |grep 'sersync2'|grep -v'grep'|wc -l)

if [ $STATUS -eq 0 ];

then

       $SERSYNC -d -r -o $CONF_FILE 

else

       exit 0;

fi

   : Test
       in directory /data/testfile , then view server backupfor directory is
 

 

This article is from “in ” Blog, http://4888761.blog.51cto.com/4878761/1086724

Leave a Comment

Your email address will not be published.