加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

rsync实现定时同步

发布时间:2020-12-13 23:59:49 所属栏目:Linux 来源:网络整理
导读:rsync服务标准配置(将/home/coremail目录同步至备机的/tmp/123目录下) 一、服务端/数据源 开启rsync服务 1、确保系统内安装了xinetd服务 2、修改配置,启动rsync服务 vim /etc/xinetd.d/rsync 将 disable=yes 修改为 disable=no 保存退出 重启xinetd servi
rsync服务标准配置(将/home/coremail目录同步至备机的/tmp/123目录下)
一、服务端/数据源
开启rsync服务
1、确保系统内安装了xinetd服务
2、修改配置,启动rsync服务
vim /etc/xinetd.d/rsync

disable=yes
修改为
disable=no
保存退出
重启xinetd
service xinetd restart

3、确认服务在监听
[[email?protected] coremail]# netstat -anop |grep 873
tcp 0 0 :::873 :::* LISTEN 22406/xinetd off (0.00/0/0)

4、添加 /etc/rsyncd.conf配置文件
[[email?protected] coremail]# cat /etc/rsyncd.conf
read only = yes
uid = coremail
gid = coremail
max connections = 5
hosts allow = 192.168.213.129
use chroot = no
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid

[data]
path = /home/coremail/
auth users = test
secrets file =/etc/rsyncd.secrets

[[email?protected] coremail]# ll /etc/rsyncd.conf
-rw-r--r-- 1 root root 270 3月 25 18:49 /etc/rsyncd.conf
[[email?protected] coremail]#
以上配置定义了要同步的数据目录,以及rsync中的虚拟同步账号test, test的密码文件路径。
hosts allow为允许连接的客户端ip

5、添加账号密码文件/etc/rsyncd.secrets
[[email?protected] coremail]# cat /etc/rsyncd.secrets
test:12345
[[email?protected] coremail]# ll /etc/rsyncd.secrets
-rw------- 1 root root 11 3月 25 16:52 /etc/rsyncd.secrets
[[email?protected] coremail]#
/etc/rsyncd.secrets的权限必须是600, test的密码是12345

二、客户端配置
1、客户端需要将服务端的虚拟账号test密码配置到本地
[email?protected] var]#
[[email?protected] var]# cat /etc/rsyncd.secrets
12345
[[email?protected] var]#
[[email?protected] var]# ll /etc/rsyncd.secrets
-rw------- 1 root root 6 3月 25 16:59 /etc/rsyncd.secrets
[[email?protected] var]#
/etc/rsyncd.secrets的权限必须是600

2、执行命令同步
rsync -av --delete --password-file=/etc/rsyncd.secrets [email?protected]::data /tmp/123
获取本地的密码文件,来进行同步,将服务端的[data]下配置的目录同步到本地的/tmp/123目录下
rsync -av --delete --password-file=/etc/rsyncd.secrets --exclude=var/backup/ [email?protected]::data /tmp/123

同步整个数据目录,排除掉/home/coremail/var/backup, 配置中的var/backup/是一个相对路径,取决于[data]下的配置路径

3、设置计划周期即可实现

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读