lsyncd安装部署记录

约定如下:    
运行lsyncd的节点为master    
被同步的节点为slave

1.在master上生成key并copy给slave节点做免密码通信。
这里我们是自用的机器则直接用的root。

ssh-keygen -t rsa  # 全部回车默认

ssh-copy-id root@slave_server_IP

2.安装epel源码仓库和lsyncd

yum -y install epel-release
yum install lsyncd rsynce
systemctl enable lsyncd

3.配置文并启动

cat   /etc/lsyncd.conf
sync { default.rsyncssh,host="slave_server_IP-A",source="/opt/nginx/",targetdir="/opt/nginx/"}

sync { default.rsyncssh,host="slave_server_IP-B",source="/opt/nginx/",targetdir="/opt/nginx/"}

4.启动并查看状态

systemctl start lsyncd
systemctl status lsyncd

更多的使用细节懒得记录了。


更多的配置例子和文章可以参考下面
/usr/share/doc/lsyncd*/examples/
https://github.com/axkibe/lsyncd
http://seanlook.com/2015/05/06/lsyncd-synchronize-realtime/



从Sean's Notes复制了个/etc/lsyncd.conf的配置细节

settings {

logfile ="/usr/local/lsyncd-2.1.5/var/lsyncd.log",

statusFile ="/usr/local/lsyncd-2.1.5/var/lsyncd.status",

inotifyMode = "CloseWrite",

maxProcesses = 8,

}



-- I. 本地目录同步,direct:cp/rm/mv。 适用:500+万文件,变动不大

sync {

default.direct,

source    = "/tmp/src",

target    = "/tmp/dest",

delay = 1

maxProcesses = 1

}


-- II. 本地目录同步,rsync模式:rsync

sync {

default.rsync,

source    = "/tmp/src",

target    = "/tmp/dest1",

excludeFrom = "/etc/rsyncd.d/rsync_exclude.lst",

rsync     = {

binary = "/usr/bin/rsync",

archive = true,

compress = true,

bwlimit   = 2000

}

}


-- III. 远程目录同步,rsync模式 + rsyncd daemon

sync {

default.rsync,

source    = "/tmp/src",

target    = "syncuser@172.29.88.223::module1",

delete="running",

exclude = { ".*", ".tmp" },

delay = 30,

init = false,

rsync     = {

binary = "/usr/bin/rsync",

archive = true,

compress = true,

verbose   = true,

password_file = "/etc/rsyncd.d/rsync.pwd",

_extra    = {"--bwlimit=200"}

}

}


-- IV. 远程目录同步,rsync模式 + ssh shell

sync {

default.rsync,

source    = "/tmp/src",

target    = "172.29.88.223:/tmp/dest",

-- target    = "root@172.29.88.223:/remote/dest",

-- 上面target,注意如果是普通用户,必须拥有写权限

maxDelays = 5,

delay = 30,

-- init = true,

rsync     = {

binary = "/usr/bin/rsync",

archive = true,

compress = true,

bwlimit   = 2000

-- rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"

-- 如果要指定其它端口,请用上面的rsh

}

}


-- V. 远程目录同步,rsync模式 + rsyncssh,效果与上面相同

sync {

default.rsyncssh,

source    = "/tmp/src2",

host      = "172.29.88.223",

targetdir = "/remote/dir",

excludeFrom = "/etc/rsyncd.d/rsync_exclude.lst",

-- maxDelays = 5,

delay = 0,

-- init = false,

rsync    = {

binary = "/usr/bin/rsync",

archive = true,

compress = true,

verbose   = true,

_extra = {"--bwlimit=2000"},

},

ssh      = {

port  =  1234

}

}


添加新评论 »