Rsync+Inotify实现自动同步清华大学yum源到本地

本文介绍如何使用Rsync和Inotify实现实时自动同步清华大学的yum源至本地服务器,通过监控目录变化触发同步,确保本地源的实时更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Rsync+Inotify实现自动同步清华大学yum源到本地

本篇介绍Rsync+Inotify实现自动同步清华大学yum源到本地,需要同步的目录地址:https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/

1、安装Rsync服务

[root@myzdl ~]# yum install rsync
[root@myzdl ~]# rsync --list-only mirrors.tuna.tsinghua.edu.cn::centos/7/os/x86_64/
+==================================================+
|               Tsinghua University                |
|          -= Open Source Mirror Site =-           |
+--------------------------------------------------+
|   Welcome to Tsinghua Open Source Mirror Site.   |
|                                                  |
|   This mirror is also available on HTTP.         |
|   HTTP  [https://mirrors.tuna.tsinghua.edu.cn]   |
|   RSYNC [rsync://mirrors.tuna.tsinghua.edu.cn]   |
|                                                  |
|   If you have any issues, please contact us      |
|   via GitHub @ https://github.com/tuna/issues    |
|   or IRC at #tuna on freenode                    |
|   or Fishroom at https://fishroom.tuna.moe/      |
|                                                  |
|   Supported by                                   |
|      Tsinghua Information Technology Center      |
|   Maintained by                                  |
|      Tsinghua University TUNA Association        |
|   Service Provided by                            |
|      nanomirrors                                 |
|   This storage server is sponsored by            |
|      Megvii Technology Inc.                      |
|                                                  |
|   TUNA acknowledges the contribution from Megvii |
|   to open source software and communities        |
|                                                  |
+==================================================+

drwxr-xr-x             15 2020/04/22 18:58:47 .
-rw-r--r--             29 2020/04/21 01:55:44 .discinfo
-rw-r--r--            353 2020/04/21 02:00:59 .treeinfo
-rw-rw-r--             14 2020/04/22 01:15:06 CentOS_BuildTag
-rw-rw-r--            227 2017/08/30 22:33:06 EULA
-rw-rw-r--         18,009 2015/12/10 06:35:46 GPL
-rw-rw-r--          1,690 2015/12/10 06:35:46 RPM-GPG-KEY-CentOS-7
-rw-rw-r--          1,690 2015/12/10 06:35:46 RPM-GPG-KEY-CentOS-Testing-7
drwxr-xr-x              3 2020/04/21 02:00:13 EFI
drwxr-xr-x              3 2020/04/21 02:00:13 LiveOS
drwxr-xr-x         10,072 2020/04/22 18:58:47 Packages
drwxr-xr-x              5 2020/04/21 02:00:49 images
drwxr-xr-x             11 2020/04/22 18:58:47 isolinux
drwxr-xr-x             12 2020/04/22 07:37:50 repodata
[root@myzdl ~]# 

2、安装Inotify服务

inotify可以实时监控目录文件,当文件目录发生变化,则触动rsync同步文件。
inotify-tool有两个程序,分别是inotifywait和inotifywatch。
[root@myzdl ~]# yum install inotify-tools
[root@myzdl ~]# vim inotify.sh

#!/bin/bash
#This is rsync script on inotify.
export PATH=/bin:/usr/bin:/usr/local/bin
Desdir=mirrors.tuna.tsinghua.edu.cn::centos/7/os/x86_64/
Localdir=/var/ftp/Tsinghua/
inotifywait -mrq --timefmt '%y-%m-%d %H:%M' --format '%T %w%f %e' --event modify,create,move,delete,attrib, $Localdir | while read line 
do
echo "$line" > /var/log/inotify.log 2>&1
/usr/bin/rsync -avz --delete --progress  $Desdir $Localdir >>/var/log/sync.log 2>&1
done &

[root@myzdl ~]# mkdir .script
[root@myzdl ~]# mv inotify.sh .script/
[root@myzdl ~]# echo “/root/.script/inotify.sh” >>/etc/rc.local
[root@myzdl ~]# chmod o+x /etc/rc.d/rc.local

#同步成功如下,10G左右

[root@myzdl ~]# du -h /var/ftp/Tsinghua/*
4.0K	/var/ftp/Tsinghua/CentOS_BuildTag
2.5M	/var/ftp/Tsinghua/EFI/BOOT/fonts
8.3M	/var/ftp/Tsinghua/EFI/BOOT
8.3M	/var/ftp/Tsinghua/EFI
4.0K	/var/ftp/Tsinghua/EULA
20K	/var/ftp/Tsinghua/GPL
60M	/var/ftp/Tsinghua/images/pxeboot
636M	/var/ftp/Tsinghua/images
60M	/var/ftp/Tsinghua/isolinux
491M	/var/ftp/Tsinghua/LiveOS
9.0G	/var/ftp/Tsinghua/Packages
29M	/var/ftp/Tsinghua/repodata
4.0K	/var/ftp/Tsinghua/RPM-GPG-KEY-CentOS-7
4.0K	/var/ftp/Tsinghua/RPM-GPG-KEY-CentOS-Testing-7
[root@myzdl ~]# 
[root@myzdl ~]# ls /var/ftp/Tsinghua/Packages/ | wc
  10070   10070  401037

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

zdl244

你的鼓励是我最大的动力

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

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

打赏作者

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

抵扣说明:

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

余额充值