linux 数据同步rsync的安装

1、A服务器安装lsyncd

#前提是有配置EPEL源
#依赖
yum install -y gcc gcc-c++ lua lua-devel cmake libxml2 libxml2-devel
#lsyncd安装
yum -y install lsyncd

2、A服务器配置到B服务器的免密登录

ssh-keygen -t rsa
ssh-copy-id -p 22 root@B
ssh -p 22 root@B

3、配置文件解释

vim /etc/lsyncd.conf

settings {
    logfile = "/var/log/lsyncd.log",          --日志路径
    statusFile = "/var/log/lsyncd.status",    --状态文件
    pidfile = "/var/run/lsyncd.pid",          --pid文件路径
    statusInterval = 1,                       --状态文件写入最短时间
    nodaemon = false,                         --daemon运行
    maxProcesses = 1,                         --最大进程
    maxDelays = 1,                            --最大延迟
}
sync {
    default.rsyncssh,      --默认rsync+ssh,rsync版本需要升级3以上版本
    source = "/apps/www/renwoleblog/",        --源目录
    delete = true,                            --保持完全同步    
    delete = false,               --只同步A服务器的添加文件不同步删除操作   
    host = "root@B服务器地址",         
    targetdir = "/apps/www/renwoleblog/bak/", --目标目录
    exclude={                 
             ".txt"            --需排除的文件
    },
rsync = {
    binary = "/usr/bin/rsync", --需先安装好rsync
    archive = true,            --归档
    compress = false,          --压缩
    owner = true,              --属主
    perms = true,              --权限
    whole_file = false
    },
ssh = {
    port = 22
    }

4、本地目录同步配置方案

sync {
    default.rsync,
    source = "/apps/www/renwoleblog/", --源文件
    target = "/apps/www/renwoleblog/bak/", --同步到的位置
}

5、远程同步rsync-daemon模式配置方案

sync {
    default.rsync,
    source    = "/apps/www/renwoleblog/",
    target    = "root@B服务器IP::renwolecom",
    delete="true", --保持完全同步
    exclude = { ".bak*" }, --排除文件
    delay = 30,
    init = false,
    rsync = {
    binary = "/usr/bin/rsync",
    archive = true,
    compress = true,
    verbose   = true,
    perms = true,
    password_file = "/etc/rsync.password",
    _extra    = {"--bwlimit=200"}
    }
}

6、重点参数解释

--        # 注释符
settings  # 是全局配置
sync      # 定义同步参数
rsync     # 定义同步文件参数
ssh       # 定义服务器远程端口

7、启动lsyncd并加入自启

#检测配置文件是否正确
lsyncd -nodaemon /etc/lsyncd.conf
#启动
systemctl start lsyncd
systemctl enable lsyncd

8、测试远程同步案例配置

settings {
   logfile    = "/var/log/lsyncd/lsyncd.log",
   statusFile = "/tmp/lsyncd.status",
   insist = true,
   inotifyMode = "Modify",
   statusInterval = 1
}

sync {
   default.rsyncssh,
   source="/root/lsy_node",
   host="B服务ip地址",
   targetdir="/root/lsy_test",
   delete="false",
   maxDelays = 5,
   delay = 0,
   rsync = {
     archive = true,
     compress = false,
     -- verbose   = true
   },
   ssh = {
     port = 22
   }
}
#A服务器创建 a b c 三个文件
[root@aly lsy_node]# touch {a,b,c}
[root@aly lsy_node]# ls
a  b  c

#B服务器查看同步效果
[root@k8s-master lsy_test]# ls
1  2  a  b  c
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值