rsync+lsync在Linux下配置

更新时间:2023-11-15 05:20:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

1.204安装lsyncd

# wget http://lsyncd.googlecode.com/files/lsyncd-1.26.tar.gz # tar zxvf lsyncd-1.26.tar.gz # cd lsyncd-1.26 # ./configure

# make && make install

2. 本地204需要安装rsync客户端

centos 默认状态下rsync已经安装上了。没有安装可以装rpm包,也可以安装源码包进行,只需要客户端工具。

# wget http://www.samba.org/ftp/rsync/src/rsync-3.0.6.tar.gz # tar zvxf rsync-3.0.6.tar.gz # cd rsync-3.0.6

# ./configure --prefix=/usr/local/rsync # make && make install

# cp /usr/local/rsync/bin/rsync /usr/bin/

3. 本地204 lsyncd启动默认日志文件,可以查看lsyncd启动与工作状态 /var/log/lsyncd

4. 本地手动同步目录并监视磁盘目录情况,运行后作为进程一直在后台运行。 # /usr/local/bin/lsyncd /data/soft/ 192.168.162.203::soft

# /usr/local/bin/lsyncd /data/www/ 192.168.162.203::www

5. 或通过配置文件的方式来启动 # vi /etc/lsyncd.conf

1 /var/lib/mysql/ 192.168.0.203::mysql 2 /www/ 192.168.0.203::www 3 /home/svnroot 192.168.0.203:svn

~ ============ 启动脚本如下 ============ vi /root/lsyncd.sh #!/bin/bash

#lsyncd startup script

lsyncd=\

function_start_lsyncd() {

printf \ 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 \ killall $lsyncd }

function_restart_lsyncd() {

printf \ function_stop_lsyncd function_start_lsyncd }

if [ \ function_start_lsyncd elif [ \ function_stop_lsyncd elif [ \ function_restart_lsyncd else

printf \fi

7. 203 rsync配置文件示例 不用安装源码的rsync包了 ================== 203 rsyncd配置文件 ================== # 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

[mysql]

path = /var/lib/mysql/ comment = mysql ignore errors read only = no write only = no list = no

hosts allow = 192.168.0.204

[www]

path = /www/ comment = www ignore errors read only = no write only = no list = no

hosts allow = 192.168.0.204

[svn]

path = /home/svnroot/ comment = svn ignore errors

read only = nolist = no

hosts allow = 192.168.0.204

运行rsyncd服务

# /usr/bin/rsync --daemon

维护注意事项:1.可以用ps -aux查看启动情况 2.客户端要比rsyncd服务端后启动,否则自动启动不了,这时需要手动启动。

双向同步的时候 145启动rsync的时候会报错[root@localhost ~]# /usr/bin/rsync --daemon failed to create pid file /var/run/rsyncd.pid: File exists

[root@localhost ~]# rm -rf /var/run/rsyncd.pid 删掉这个文件 重启就好用了

网上总结rsync报错信息:

Rsync同步常见问题: 错误一:

@ERROR: auth failed on module xxxxx

rsync: connection unexpectedly closed (90 bytes read so far)

rsync error: error in rsync protocol data stream (code 12) at io.c(150) 解决:这是因为密码设置错了,无法登入成功,检查一下rsync.pwd,看客服是否匹配。还有服务器端没启动rsync 服务也会出现这种情况。 错误二:

password file must not be other-accessible continuing without password file Password: 解决:这是因为rsyncd.pwd rsyncd.sec的权限不对,应该设置为600。如:chmod 600 rsyncd.pwd 错误三:

@ERROR: chroot failed

rsync: connection unexpectedly closed (75 bytes read so far)

rsync error: error in rsync protocol data stream (code 12) at io.c(150) 解决:这是因为你在 rsync.conf 中设置的 path 路径不存在,要新建目录才能开启同步。 错误四:

rsync: failed to connect to 218.107.243.2: No route to host (113) rsync error: error in socket IO (code 10) at clientserver.c(104) [receiver=2.6.9]

解决:对方没开机、防火墙阻挡、通过的网络上有防火墙阻挡,都有可能。关闭防火墙,其实就是把tcp udp 的873端口打开。

Reported by oer...@gmail.com, Oct 15, 2010

What steps will reproduce the problem? 1. large homedir ( million files )

2. lsyncd --exclude-from=/home/oernii/.rsync_exclude --no-daemon --verbose /home/oernii/ remote::/BACKUP/

What is the expected output? What do you see instead? sync should run without errors

What version of the product are you using? On what operating system? 1.39

Please provide any additional information below. After running I am getting a LOT of this:

watching /home/oernii/.kde

ERROR: Cannot add watch /home/oernii/.kde (28:No space left on device) 这个错误的解决办法

Comment 1 by d...@dans.im, Oct 15, 2010

\space left on device\probably means you need to increase /proc/sys/fs/inotify/max_user_watches. Eg.: `echo 65536 >/proc/sys/fs/inotify/max_user_watches'.

本文来源:https://www.bwwdw.com/article/bkjv.html

Top