配置内网yum源

文章详细介绍了如何在无法访问外网的生产服务器上构建内网yum源,包括下载必要的工具如createrepo和reposync,配置阿里云镜像,同步仓库到本地,创建索引,并配置内网其他主机访问此yum源的步骤。

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

因安全保密的需求,一般生产服务器并不能访问外网,这样就需要构建内网的yum源

1、下载插件

yum -y install wget yum-utils createrepo

createrepo:用于生成yum源各软件之间的依赖索引。
yum-utils:安装后可使用 yumdownloader 命令下载所需软件包。
reposync:Reposync用于将远程yum存储库同步到本地,使用yum检索包的目录

2、配置yum源

下载阿里源

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

查看配置好的网络源id

yum repolist

yum1.png

3、将yum源拉到本地服务器上

建立目录

mkdir  /yum

拉取yum源到本地

base

reposync -r base -p /yum

 

yum2.png

 

epel

reposync -r epel -p /yum

yum3.png

extras

reposync -r extras -p /yum

yum4.png

 

reposync命令参数

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

生成索引依赖

需要用到createrepo,没有的话需要使用yum下载

base

createrepo /yum/base

image2023-6-26_16-58-39.png

 epel

createrepo /yum/epel

image2023-6-26_17-5-9.png

 extras

createrepo /yum/extras

image2023-6-26_17-8-44.png

updates

createrepo /yum/updates

202306271687867408289003.jpg

4、配置yum源的url地址

选择nginx配置yum源的共享目录下面需要在内网的其他主机上配置yum文件,保证能连接到yum源上

]# vim /nginx/conf/vhosts/yum.conf
server {
    listen 18200;
    server_name localhost;
    
    location / {
        root  /yum;         ##yum源主目录
        autoindex off;
        autoindex_exact_size off;
        autoindex_localtime on;
        charset utf-8;
        index  index.html index.htm;
  }
}
 
]# /nginx/sbin/nginx -s reload

下面需要在内网的其他主机上配置yum文件,保证能连接到yum源上

##CentOS-Base.repo文件,配置base,extras,updates源的相关参数
]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]       ##base源
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://172.25.230.47:18200/base/       ##base源url路径
gpgcheck=1
 
[updates]        ##updates源
name=CentOS-$releasever 
enabled=1
failovermethod=priority
baseurl=http://172.25.230.47:18200/updates/     ##updates源url路径
gpgcheck=1
 
[extras]     ##extras源
name=CentOS-$releasever
enabled=1
failovermethod=priority
baseurl=http://172.25.230.47:18200/extras/      ##extras源url路径
gpgcheck=1
 
##epel.repo文件,配置epel源
]# vim /etc/yum.repos.d/epel.repo
[epel]    
name=Extra Packages for Enterprise Linux 7 - $basearch
enabled=1
failovermethod=priority
baseurl=http://172.25.230.47:18200/epel/    ##epel源url路径
gpgcheck=0

##epel.repo文件,配置epel源
]# vim /etc/yum.repos.d/epel.repo
[epel]    
name=Extra Packages for Enterprise Linux 7 - $basearch
enabled=1
failovermethod=priority
baseurl=http://172.25.230.47:18200/epel/    ##epel源url路径
gpgcheck=0

重建yum缓存

yum clean all

yum makecache

image2023-6-26_22-36-16.png

测试yum安装

image2023-6-27_12-24-15.png

 

 远程yum源同步脚本,通过设置计划任务执行

#!/bin/bash
 
yumdir=/yum
yumlog=/yum/yumsync.log
 
yumsour=(base centos-sclo-rh centos-sclo-sclo epel extras updates)
for i in ${yumsour[*]};do
  reposync -r $i -n repoid=[] -p $yumdir
  if [ $? -eq 0 ];then
    echo "[`date +%F_%H:%M:%d`] success: $i source sync" | tee -a $yumlog
  else
    echo "[`date +%F_%H:%M:%d`] error: $i source sync failed" | tee -a $yumlog
  fi
done

yumsync.sh

欢迎访问个人技术博客,有各种关于linux技术,中间件,数据库,应用等文章的分享,还有其他的人文文章,放松心情,可以点击右侧分类来查找相关的内容,也可以在留言本里给我留言交流技术:

OPSZHN运维技术分享博客 - 享受每一天

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值