reposync命令详解--reposync同步aliyunyum库到本地

参考: reposync - 命令 - -桃枝夭夭- - 博客园

0. 简介

reposync 命令简单来说就是可以把指定外网源(repo id)的包同步到本地文件中

1. 安装 reposync 命令

[root@V10SP1-1 ~]# yum install -y dnf-plugins-core

2. 常用选项以及参数

选项 含义
-c [file] 指定配置文件运行(默认配置文件是 /etc/yum.conf )
-q 静谧运行
-v 显示详细操作
-h 获取帮助
-b 尝试使用最佳的软件包版本
-C 只从系统缓存中运行,不更新缓存
-R [min] 最大命令等待时间
-y 所有回答都是 yes
-x [package] 排除哪些包
-n repoid=[] 只下载最新的包,相同的跳过
-p 指定下载路径
--delete 删除已不在仓库中的本地软件包

3. 例子

#1. 同步整个源到指定目录
[root@V10SP1-1 pac]# reposync -p /root/pac

# 2. 同步指定源到指定目录
[root@V10SP1-1 pac]# reposync  --repoid=ks10-adv-updates -p /root/pac/

# 3. 更新同步过的源
[root@V10SP1-1 pac]# reposync -n --repoid=ks10-adv-updates -p /root/pac

4. 使用场景

常见的使用场景就是,一个服务器集群,只有一台服务器能连接外网,连接外网那台服务器就把外网源的包全部同步下来放在本地,集群中其他服务器就以这台服务器为包库使用 yum 安装,当然,同步完包之后还需要使用 createrepo 来生成 repodata


5. reposync同步aliyunyum库到本地

5.1 软件安装:

# yum-utils:reposync同步工具
# createrepo:编辑yum库工具​
yum -y install yum-utils createrepo plugin-priorities 

# plugin-priorities:控制yum源更新优先级工具,用来控制进行yum源检索的先后顺序,
# 建议可以用在client端。

5.2 安装nginx:

yum –y install Nginx

5.3 修改nginx配置文件:

vi /etc/nginx/nginx.conf

5.4 备份yum库

mkdir /repo  && mv /etc/yum.repos.d/* /repo 

5.5 建立aliyun yum库

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

wget -O /etc/yum.repos.d/CentOS-epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

5.6 刷新缓存

yum clean all
yum makecache

5.7 查看仓库列表

[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
仓库标识仓库名称状态
baseCentOS-6 - Base - mirrors.aliyun.com6,706
extras  CentOS-6 - Extras - mirrors.aliyun.com 46
updates CentOS-6 - Updates - mirrors.aliyun.com   826
repolist: 7,778

5.8 nginx的html目录

/usr/share/nginx/html/

5.9 建立rpm库存放目录

mkdir -p /usr/share/nginx/html/Aliyun/CentOS/7/64bit/{base,extras,updates}

5.10 同步下载rpm包

reposync -p /usr/share/nginx/html/Aliyun/CentOS/7/64bit

# 同步镜像到本地
reposync -r base
reposync -r extras
reposync -r updates

5.11 创建yum仓库 

yum installcreaterepo yum-utils -y
cd base
createrepo ./
cd ../extras
createrepo ./
cd ../updates
createrepo ./

5.12 其他服务器连接YUM仓库:

vim /etc/yum.repos.d/test.repo

[base]
name=CentOS-Base(GDS)
baseurl=http://10.63.215.7/Aliyun/CentOS/7/64bit/base
path=/
enabled=1
gpgcheck=0
 
[updates]
name=CentOS-Updates(GDS)
baseurl=http://10.63.215.7/Aliyun/CentOS/7/64bit/updates
path=/
enabled=1
gpgcheck=0
 
[extras]
name=CentOS-Extras(GDS)
baseurl=http://10.63.215.7/Aliyun/CentOS/7/64bit/extras
path=/
enabled=1
gpgcheck=0

5.13 建立定时同步,每周一的3点同步:

crontab -e

0 3 * * 1 /usr/bin/reposync -np   /usr/share/nginx/html/Aliyun/CentOS/7/64bit

参考:centos7搭建自己的yum源 - juandx - 博客园

                             CentOS7下的YUM源服务器搭建详解_Ivan_fay的博客-CSDN博客

                             同步阿里云镜像到本地,在本地搭建YUM仓库 - bamboo233 - 博客园

猜你喜欢

转载自blog.csdn.net/justlpf/article/details/127382277
今日推荐