一个专业运维
技术分享网站!

部署lsync 实时同步

温馨提示:文档只提供参考,谢谢

1.1 主机规划

backup   rsync-server
nfs      rsync-clinet

1.2 安装部署

yum install rsync -y

1.3 查看配置文件

[root@backup /opt] rpm -qc rsync
/etc/rsyncd.conf
/etc/sysconfig/rsyncd

1.4 修改配置文件

[root@backup /opt] vim /etc/rsyncd.conf 
uid = www
gid = www 
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
#####################################
[backup]
path = /backup

[data]
path = /data

1.5 创建用户以及数据目录

[root@backup /opt]# groupadd www -g 666
[root@backup /opt]# useradd www -u 666 -g 666 -M -s /sbin/nologin
[root@backup /opt]# id www
uid=666(www) gid=666(www) groups=666(www)

1.6 创建目录以及授权

[root@backup /opt] mkdir /data
[root@backup /opt] mkdir /backup
[root@backup /opt] chown -R www:www /backup/
[root@backup /opt] chown -R www:www /data/

1.7 创建密码文件并授权

[root@backup /opt] vim /etc/rsync.passwd
rsync_backup:123456

[root@backup ~] chmod 600 /etc/rsync.passwd 

1.7.1.启动服务

systemctl start rsyncd 
systemctl status rsyncd

1.8 免密传输文件测试

[root@nfs ~] echo "123456" > /etc/rsync.passwd ^C
[root@nfs ~] 
[root@nfs ~] chmod 600 /etc/rsync.passwd  ^C
[root@nfs ~] 
[root@nfs ~] rsync -avzP --password-file=/etc/rsync.passwd /etc rsync_backup@10.0.0.41::data

2.nfs 安装部署

[root@nfs ~] yum install rsync -y
[root@nfs ~] yum install inotify-tools -y
[root@nfs ~] yum install lsyncd -y

2.1 创建用户 有用户就不用创建了

[root@nfs ~]  groupadd www -g 666
[root@nfs ~]  useradd www -u 666 -g 666 -M -s /sbin/nologin
[root@nfs ~]  id www
uid=666(www) gid=666(www) groups=666(www)

2.2 创建目录以及授权

[root@nfs ~] mkdir /data
[root@nfs ~] mkdir /backup
[root@nfs ~] chown -R www:www /backup/
[root@nfs ~] chown -R www:www /data/

2.3 创建配置文件

image.png

[root@nfs ~] vim /etc/lsyncd.conf
settings {
  logfile = "/var/log/lsyncd/lsyncd.log",
  statusFile = "/var/log/lsyncd/lsyncd.status",
  inotifyMode = "CloseWrite",
  maxProcesses = 8,
}
sync {
  default.rsync,
  source = "/data",
  target = "rsync_backup@172.16.1.41::data",
  delete = true,
  exclude = { ".*" },
  delay = 1,
  rsync = {
    binary = "/usr/bin/rsync",
    archive = true,
    compress = true,
    verbose = true,
    password_file = "/etc/rsync.passwd",
    _extra = {"--bwlimit=200"}
  }
}

2.4 创建密码文件并授权

[root@nfs ~] vim /etc/rsync.passwd
123456

[root@nfs ~] chmod 600 /etc/rsync.passwd 

2.5 启动命令

[root@nfs ~] systemctl start rsyncd
[root@nfs ~] systemctl status rsyncd
[root@nfs ~] systemctl start lsyncd 
[root@nfs ~] systemctl status lsyncd

报错排除方法

password file must not be other-accessible    # 密码文件不能以其他方式访问
@ERROR: auth failed on module data           # @错误:验证模块数据失败

1.nfs 创建密码要注意一下
2.密码文件目录不授权.会出现报错

历史上的今天
六月
17
    哇哦~~~,历史上的今天没发表过文章哦
赞(2) 打赏
未经允许不得转载:小柳实验室 » 部署lsync 实时同步

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏