rsync lsync

 

[1] Install xinetd on HostA and HostB.
[root@lan ~]# 
yum -y install xinetd


[root@lan ~]# 
vi /etc/xinetd.d/rsync


# default: off
# description: The rsync server is a good addition to an ftp server, as it \
#      allows crc checksumming etc.
service rsync
{
disable
no
# change

socket_type
= stream

wait
= no

user
= root

server
= /usr/bin/rsync

server_args
= --daemon

log_on_failure
+= USERID

}

[root@lan ~]# 
/etc/rc.d/init.d/xinetd start

Starting xinetd:
[  OK  ]

[root@lan ~]# 
chkconfig xinetd on

[root@lan ~]# 
chown nobody. /home/backup

[root@lan ~]# 
vi /etc/rsyncd.conf


# any name you like

[site]
# destination directory

path = /home/backup
# IP address you allow that connect to this server

hosts allow = 192.168.0.0/24
# allow update

read only = false
[2] Install and configure Lsync on HostA. Get latest lsync from here when you run wget.
# install some requied packages

[root@www ~]# 
yum -y install libxml2-devel zlib-devel readline-devel


[root@www ~]# 
wget http://lsyncd.googlecode.com/files/lsyncd-1.26.tar.gz


[root@www ~]# 
tar zxvf lsyncd-1.26.tar.gz

[root@www ~]# 
cd lsyncd-1.26

[root@www lsyncd-1.26]# 
./configure

[root@www lsyncd-1.26]# 
make

[root@www lsyncd-1.26]# 
make install

[root@www lsyncd-1.26]# 
cp lsyncd.conf.xml /etc/lsyncd.conf.xml

[root@www lsyncd-1.26]# 
cd

[root@www ~]# 
rm -rf lsyncd-1.26

[root@www ~]# 
vi /etc/lsyncd.conf.xml


# line 61: change to mirrored directory

<source path="
/var/www/html
"/>

# line 62: destination directory which name is the one in rsyncd.conf on the section [1]

<target path="
192.168.0.20::site/
"/> 

[root@www ~]# 
vi /etc/rc.d/init.d/lsyncd
   
# create init script


# it's an example

#!/bin/bash
#
# lsyncd: Starts the lsync Daemon
#
# chkconfig: 345 99 90
# description: 
Lsyncd uses rsync to synchronize local directories with a remote

#
machine running rsyncd. Lsyncd watches multiple directories

#
trees through inotify. The first step after adding the watches

#
is to, rsync all directories with the remote host, and then sync

#
single file buy collecting the inotify events.

# processname: lsyncd

. /etc/rc.d/init.d/functions

config="/etc/lsyncd.conf.xml"
lsyncd="/usr/local/bin/lsyncd"
lockfile="/var/lock/subsys/lsyncd"
prog="lsyncd"
RETVAL=0

start() {
if [ -f $lockfile ]; then

echo -n $"$prog is already running: "

echo

else

echo -n $"Starting $prog: "

daemon $lsyncd --conf=$config

RETVAL=$?

echo

[ $RETVAL = 0 ] && touch $lockfile

return $RETVAL

fi

}
stop() {
echo -n $"Stopping $prog: "

killproc $lsyncd

RETVAL=$?

echo

[ $RETVAL = 0 ] && rm -f $lockfile

return $RETVAL

}
case "$1" in
start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

status)

status $lsyncd

;;

*)

echo "Usage: lsyncd {start|stop|restart|status}"

exit 1

esac

exit $?


[root@www ~]# 
vi /etc/logrotate.d/lsyncd


# set logrotation

/var/log/lsyncd {
   daily
   copytruncate
   compress
   notifempty
   missingok
   postrotate
     /etc/rc.d/init.d/lsyncd restart 2>&1 > /dev/null || true
   endscript
}


[root@www ~]# 
chmod 755 /etc/rc.d/init.d/lsyncd

[root@www ~]# 
/etc/rc.d/init.d/lsyncd start

Starting lsyncd: 
[  OK  ]

[root@www ~]# 
chkconfig --add lsyncd

[root@www ~]# 
chkconfig lsyncd on
[3] Make sure on HostB that files are copied normally. 

你可能感兴趣的:(职场,rsync,休闲,lsync)