rsync备份工具

关于rsync:

在这里插入图片描述

配置rsync源服务器:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

使用rsync工具:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

rsync的脚本交互处理:

在这里插入图片描述

rsync实时同步:

在这里插入图片描述

关于inotify:

在这里插入图片描述

rsync和inotify实时同步:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

rsync具体部署:

[root@localhost ~]# rpm -q rsync //查看是否安装
rsync-3.0.9-18.el7.x86_64  //系统自带
[root@localhost ~]# vi /etc/rsyncd.conf 
uid = nobody 
gid = nobody
use chroot = yes  //禁锢在宿主主目录
address = 192.168.10.100 //监听地址
port 837 //端口号
# max connections = 4
pid file = /var/run/rsyncd.pid
log file = /var/log/rsync.log
hosts allow = 192.168.10.0/24
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 //不开启压缩
[wwwroot] //备份的模块
path = /var/www/html //备份的目录
comment = web dir //备份的描述
read only = yes //只读开启
auth users = backuper //允许的用户
secrets file = /etc/rsyncd_users.db //验证用户
chmod 600 /etc/rsyncd_users.db //设置其他用户不可读,因为这里是验证用户的账户和密码
yum -y install httpd //yum安装http服务用于远程备份
echo "this is my first web" > /var/www/html/index.html //重定向给共享目录
[root@localhost ~]# cat /var/www/html/index.html 
this is my first web
rsync --daemon //启动
[root@localhost ~]# netstat -anpt | grep rsync
tcp        0      0 192.168.10.100:873      0.0.0.0:*               LISTEN      43504/rsync         

客户机具体部署:

首先安装http服务

rsync -avz backuper@192.168.10.100::wwwroot /var/www/html/ //备份共享目录到本地/var/www/html目录中
这里需要输入密码:abc123
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ll
总用量 4
-rw-r--r--. 1 root root 21 11月 12 11:20 index.html
[root@localhost html]# cat index.html 
this is my first web

因为要输入密码,这里可以做一个免交互:
vi 1.txt
[root@localhost ~]# chmod 600 1.txt
[root@localhost ~]# rsync -avz --password-file=/root/1.txt backuper@192.168.10.100::wwwroot /var/www/html

rsync+inotify实时同步具体部署

rsync配置:
源端设置:read only = no
修改配置文件后需要重启服务
因为需要客户机上传文件,所以需要给共享目录设施至少读写权限
[root@localhost ~]# vi /etc/rsyncd.conf
[root@localhost ~]# chmod -R 777 /var/www/html/
[root@localhost ~]# kill 43504
[root@localhost ~]# netstat -anpt | grep rsync
这里直接杀死进程
[root@localhost ~]# rsync --daemon
[root@localhost ~]# netstat -anpt | grep rsync
tcp 0 0 192.168.10.100:873 0.0.0.0:* LISTEN 43852/rsync
客户机设置:
同样的也需要将上传的目录权限给足

vi /etc/sysctl.conf
fs.inotify.max_queued_events = 16384 //监控事件的最大队列数
fs.inotify.max_user_instances = 1024 //监控的最大实例数
fs.inotify.max_user_watches = 1048576 //监控的每实例的最大文件数

然后解压、编译安装
inotifywait -mrq -e modify,create,move,delete /var/www/html
另外需要再开启一个终端,因为客户端开始实时监控了
在这里插入图片描述
回到监控端可以看见
在这里插入图片描述
然后
制作一个脚本
在这里插入图片描述
运行脚本后就完成了实时同步
在客户机的共享目录里添加文件

在这里插入图片描述
回到服务器上查看可以看见同步完成
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值