您的位置:首页 > 运维架构 > Linux

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

2017-12-17 22:30 696 查看

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[/code] 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


参考

lsyncd在centos和Ubuntu下的安装配置方法 
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: