首页 > Linux工具使用 > lsyncd+rsync实时文件同步

lsyncd+rsync实时文件同步

2017年1月23日

lsyncd+rsync实时文件同步

http://xukaizijian.blog.163.com/blog/static/1704331192010112191936700?suggestedreading
客户端:

[[email protected] ~]# wget http://www.samba.org/ftp/rsync/src/rsync-3.0.7.tar.gz
[[email protected] ~]# tar -zxf rsync-3.0.7.tar.gz
[[email protected] ~]# cd rsync-3.0.7
[[email protected] rsync-3.0.7]#./configure –prefix=/usr/local/rsync && make && make install
修改配置文件:

[[email protected] ~]#cat /etc/rsyncd.conf
uid = root
gid = root
read only = no
use chroot = yes
max connections = 20
log file = /var/log/rsyncd.log
list = yes
pid file = /var/run/rsyncd.pid
hosts allow =10.10.90.97
hosts deny =0.0.0.0/0
[9097]
path = /root/10.10.90.97
comment =focus backup
启动:

rsync:rsync –daemon

服务器端:
1.安装lsyncd

[[email protected] ~]##wget http://lsyncd.googlecode.com/files/lsyncd-1.26.tar.gz
[[email protected] ~]##tar zxvf lsyncd-1.26.tar.gz
[[email protected] ~]##cd lsyncd-1.26
[[email protected] ~]##./configure –prefix=/usr/local/lsyncd
[[email protected] ~]##make && make install
2.配置lsyncd
[[email protected] ~]#vi /etc/lsyncd.conf

/opt/data/ 10.10.90.20::9097
说明:a> /opt/data/ #要实时同步的目录
b>10.10.90.20 #要实时同步到的远端机器
c> 9097 #对应远端机器的rsync的tag。
d> 如果需要同步多台或者同步多个目录就在这个文件中添加相应的行

3.建立lsyncd日志文件
#vi /etc/logrotate.d/lsyncd

/var/log/lsyncd {
missingok
notifempty
sharedscripts
postrotate
/etc/rc.d/init.d/lsyncd restart 2>&1 > /dev/null || true
endscript
}
4.建立lsyncd的启动文件

#!/bin/bash
/etc/rc.d/init.d/functions
lsyncd=”/usr/local/bin/lsyncd”
lockfile=”/var/lock/subsys/lsyncd”
pidfile=”/var/run/lsyncd.pid”
function_start_lsyncd()
{
printf “Starting Lsyncd…\n”
while read i
do
source=`echo $i | awk ‘{print $1}’`
target=`echo $i | awk ‘{print $2}’`
$lsyncd $source $target
done < /etc/lsyncd.conf
}
function_stop_lsyncd()
{
printf “Stoping Lsyncd…\n”
killall $lsyncd
}
function_restart_lsyncd()
{
printf “Restarting Lsyncd…\n”
function_stop_lsyncd
function_start_lsyncd
}
if [ “$1” = “start” ]; then
function_start_lsyncd
elif [ “$1” = “stop” ]; then
function_stop_lsyncd
elif [ “$1” = “restart” ]; then
function_restart_lsyncd
else
printf “Usage: lsyncd.sh {start|stop|restart}\n”
fi
5.启动:
[[email protected] ~]# chmod 755 /etc/init.d/lsyncd
[[email protected] ~]# /etc/init.d/lsyncd start

后记:个人觉得lsyncd+rsync对于大量小文件的实时同步比rsync要好,消耗资源较少,但在配置rsync客户端时,必须设置无密码连接,而且,数据的传输是完全同步的,并不是增量的。

分类: Linux工具使用 标签: ,
本文的评论功能被关闭了.