Lsync+Rsync实时同步
Author:Alvin-zeng
目录
一、描述2
1、需求2
二、服务器22上面的配置2
1、编译安装软件2
2、将同步路径写入配置文件3
3、编写启动脚本3
4、启动添加开机启动5
三、 23服务器上的配置5
1、编译安装软件5
2、编辑配置文件5
3、运行服务7
4、增加开机启动7
5、运行22服务器上的服务7
服务器上很多时候需要多个文件同步其实可以用lsync代替计划任务来完成这份工作
有两台机器192.168.1.22和192.168.1.23 23配置rsync服务可以接受22上推送过来的数据进行数据同步
# tar -xvf lsyncd-1.39.tar.gz
# cd lsyncd-1.39
# ./configure
# make && make install
#=======================
# tar -xvf rsync-3.0.7.tar.gz
# cd rsync-3.0.7
# ./configure --prefix=/usr/local/rsync
# make && make install
# cp /usr/local/rsync/bin/rsync /usr/bin/
# vi /etc/lsyncd.conf
/test 192.168.1.23::test 这个TEST要和下面23上配置里面的[test]对应
vi /root/lsyncd.sh
#!/bin/bash
#lsyncd startup script
lsyncd="/usr/local/bin/lsyncd"
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
# vi /etc/rc.d/rc.local
/root/lsyncd.sh start
# tar -xvf rsync-3.0.7.tar.gz
# cd rsync-3.0.7
# ./configure --prefix=/usr/local/rsync
# make && make install
# cp /usr/local/rsync/bin/rsync /usr/bin/
# vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[test]
path = /test
comment = test
ignore errors
read only = no
write only = no
list = no
hosts allow = 192.168.1.22
# /usr/bin/rsync �Cdaemon
# vi /etc/rc.d/rc.local
/usr/bin/rsync --daemon
# ./root/lsyncd.sh start