使用rsync+lsync实现触发式实时同步vim
服务器信息centos
centos6.5服务器
主:192.168.5.4 搭建lsyncsocket
从:192.168.5.3 搭建rsync测试
1.1 从服务器设置ui
# yum -y install rsync xinetd # cp /etc/xinetd.d/rsync /etc/xinetd.d/rsync.blk # vim /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 →修改‘yes’为‘no’ flags = IPv6 →修改‘IPv6’为‘IPv4’ socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } 1.2.启动xinetd并设置开机启动项。
# service xinetd startspa
# chkconfig xinetd onserver
1.3.建立同步文件的存放目录。对象
# mkdir /home/backupip
1.4.建立rsyncd.conf配置文件。
# vim /etc/rsyncd.conf
[backup] →名字任意
path = /home/backup →同步文件存放路径
hosts allow = 192.168.5.4 →容许链接的主机(指定主服务器IP)
hosts deny = *
list = true
uid = root
gid = root
read only = false
2.主服务器设定。
2.1.安装rsync。
# yum -y install rsync
2.2.建立同步对象中,不须要同步的文件一览表。
# vim /etc/rsync_exclude.lst
xx
xx.txt
2.3.在主服务器,执行如下命令。
测试将主服务器/data/下文件同步到从服务器/home/backup
# rsync -avz --delete --exclude-from=/etc/rsync_exclude.lst /data 192.168.5.3::backup
3.使用Rsync + Lsync,当文件或目录发生变动时,可作到实时同步。
3.1.登陆主服务器,下载安装Lsync。
# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install lsyncd -y
3.2.配置lsyncd文件。
# cp /etc/sysconfig/lsyncd /etc/sysconfig/lsyncd.blk
# vim /etc/sysconfig/lsyncd
# Keep the space there for systemd. Don't nest variables without
# changing the systemd service file to use: /usr/bin/sh -c 'eval XXXX'
#
LSYNCD_OPTIONS="-pidfile /var/run/lsyncd.pid /etc/lsyncd.conf" →去掉’‘#’
#LSYNCD_OPTIONS=" "
3.3.配置lsyncd.conf,添加如下内容:
# vim /etc/lsyncd.conf
settings{
statusFile = "/tmp/lsyncd.stat",
statusInterval = 1,
}
sync{
default.rsync,
source="/data", →指定需同步的源文件目录
target="192.168.5.3::backup", →从服务器IP:(rsyncd.conf设定的名字)
excludeFrom="/etc/rsync_exclude.lst", →排除文件列表
}
3.4.启动lsync。
# /etc/rc.d/init.d/lsyncd start
# chkconfig lsyncd on
3.5.在主服务器,建立新测试文件。
data]# touch xx
3.6.在从服务器确认,同步成功。
# ls /home/backup