Rsync使用教程

一、安装

1、直接yum安装

yum install rsync –y

二、配置

1、修改配置文件

vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes
address = 192.168.137.129
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
hosts allow = 192.168.137.0/24
[rsync]
    path = /data/
    comment = Document Root of www.gateway.com
    read only = yes
    dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
    auth users = rsync
	secrets file = /etc/rsyncd_users.db

2、启动服务

systemctl start rsyncd

3、编写账户信息

vim /etc/rsyncd_users.db
rsync:123456
chmod 600 /etc/rsyncd_users.db

#客户端创建密码文件
vim /etc/rsyncpasswd
123456
chmod 600/etc/rsyncpasswd

三、同步方式

1、手动同步,删除客户端文件(服务端没有,客户端有)

客户端执行:
rsync -avzH --delete --password-file=/etc/rsyncpasswd rsync@192.168.137.129::rsync  /data

在这里插入图片描述

3、手动同步,不删除客户端文件

rsync -avzH --password-file=/etc/rsyncpasswd rsync@192.168.137.129::rsync  /data

在这里插入图片描述

4、实时同步

#配置免密
ssh-keygen
ssh-copy-id -i id_rsa.pub  root@192.168.137.130

(1) 修改内核配置文件

vim /etc/sysctl.conf
fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 1024
fs.inotify.max_user_watches = 1048576

#餐宿含义
max_queue_events:监控队列大小
max_user_instances:最多监控实例数
max_user_watches:每个实例最多监控文件数

#刷新配置
sysctl –p

(2) 编译安装inotify

yum install gcc -y
tar zxcf inotify-tools-3.14.tar.gz

./configure
make && make install

(3) 编写实时监控脚本

vim rsync-inotify.sh
#!/bin/bash
INOTIFY_CMD="inotifywait -mrq -e modify,create,attrib,move,delete /data/"
RSYNC_CMD="rsync -azH --delete /data/ 192.168.137.130:/data/"

$INOTIFY_CMD | while read DIRECTORY EVENT FILE

do
    if [ $(pgrep rsync | wc -l) -ge 0 ] ;
    then  $RSYNC_CMD
    fi
done

(4) 执行脚本

nohup bash rsync-inotify.sh  &

(5)服务端

vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
address = 0.0.0.0
port 873
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
[rsync]
    path = /data/mongodbdataexport/
    comment = Document Root of www.gateway.com
    read only = yes
    dont compress = *.gz *.bz2 *.tgz *.zip *.rar *.z
    auth users = rsync
	secrets file = /etc/rsyncd_users.db

#创建同步用户
useradd rsync
echo “123abcABC” |passwd –stdin rsync

(6)客户端

ssh-keygen
cd .ssh/
ssh-copy-id -i id_rsa.pub -p53639  rsync@13.228.97.182
rsync -avzh -e 'ssh -p 53639' --delete rsync@13.228.97.182:/data/mongodbdataexport/  /data/mongodbdataexport/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

平凡似水的人生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值