CentOS6.9下的lsyncd安装与配置(以本地同步为例)

lsyncd+rsync文件实时同步

0.rsync两端都需要安装 yum -y install rsync

1.提供lsyncd的安装源

rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

2.yum安装lsyncd的依赖

yum -y install lua lua-devel pkgconfig gcc asciidoc

3.预先解决之后步骤的报错(测试复现率100%

Error: Cannotretrieve metalink for repository: epel. Please verify its path and try again

解决方法:

vi /etc/yum.repos.d/epel.repo

编辑[epel]下的baseurl前的#号去掉,mirrorlist前添加#号。

正确的配置:

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

4.yum安装lsyncd

yum install lsyncd

5.为日志文件创建目录(很可能是已经存在的目录)

mkdir /var/log/lsyncd

编写配置文件

1.VI编辑配置文件

vi /etc/lsyncd.conf

2.配置文件的最简写法(远程同步)

[root@iZ230xvongqZ ~]# cat /etc/lsyncd.conf 
# vi etc/lsyncd.conf
settings {
    logfile      ="/var/log/lsyncd/lsyncd.log",
    statusFile   ="/var/log/lsyncd/lsyncd.status",
    inotifyMode  = "CloseWrite or Modify",
    maxProcesses = 8,
    -- nodaemon = true,
    }
sync {
    default.rsync,
    source    = "/data/home/wwwroot/default",
    target    = "xxx.xxx.xxx.xxx:/data/home/wwwroot/default",
    delay     = 0,
    rsync     = {
        binary    = "/usr/bin/rsync",
        archive   = true,
        compress  = true,
        verbose   = true,
                    rsh = "/usr/bin/ssh -p 2222 -o StrictHostKeyChecking=no"
        }
    }
sync {
    default.rsync,
    source    = "/home/wwwroot/jifen",
    target    = "xxx.xxx.xxx.xxx:/home/wwwroot/jifen",
    delay     = 0,
    rsync     = {
        binary    = "/usr/bin/rsync",
        archive   = true,
        compress  = true,
        verbose   = true,
                    rsh = "/usr/bin/ssh -p 2222 -o StrictHostKeyChecking=no"
        }
    }
sync {
    default.rsync,
    source    = "/data/home/wwwroot/default",
    target    = "xx.xx.xx.xx:/data/home/wwwroot/default",
    delay     = 0,
    rsync     = {
        binary    = "/usr/bin/rsync",
        archive   = true,
        compress  = true,
        verbose   = true,
        rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
        }
    }
sync {
    default.rsync,
    source    = "/home/wwwroot/jifen",
    target    = "xx.xx.xx.xx:/home/wwwroot/jifen",
    delay     = 0,
    rsync     = {
        binary    = "/usr/bin/rsync",
        archive   = true,
        compress  = true,
        verbose   = true,
        rsh = "/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no"
        }
    }
[root@iZ230xvongqZ ~]#
 
需要设置更多同步参数在此基础上扩展配置文件即可

同步更多目录可以直接复制sync

应注意每行后面的逗号不要漏写


启动Lsyncd服务

1.开启lsyncd服务

/etc/init.d/lsyncd start
2.显示服务运行状态
/etc/init.d/lsyncd status

3.设置lsyncd服务自启动

chkconfig lsyncd on

参考

lsyncdcentosUbuntu下的安装配置方法 
https://www.scalescale.com/tips/nginx/lsyncd-live-file-syncronization-linux/

官方文档对配置文件中Settings部分的解释 
https://github.com/axkibe/lsyncd/wiki/Lsyncd-2.1.x-%E2%80%96-The-Configuration-File

官方文档对配置文件中sync部分的解释 
https://github.com/axkibe/lsyncd/wiki/Lsyncd%202.1.x%20%E2%80%96%20Layer%204%20Config%20%E2%80%96%20Default%20Behavior

一篇中文文章,在安装和配置上给了我很多帮助 
https://linux.cn/article-5849-1.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值