当前位置:首页 > linux系统知识 > 正文内容

配置内网yum源

因安全保密的需求,一般生产服务器并不能访问外网,这样就需要构建内网的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源的共享目录

]# 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

扫描二维码推送至手机访问。

版权声明:本文由个人博客发布,如需转载请注明出处。

本文链接:https://opszzfwordpress.club/post/132.html

分享给朋友:

“配置内网yum源” 的相关文章

权限管理

权限管理

1、权限标识r:读权限  4w:写权限    2x:执行权限...

linux-计划任务

linux-计划任务

1、指令指令:crontab -e   格式:分 时 日 月 周(星期)0-59 &nbs...

linux配置FTP

linux配置FTP

1、下载ftpyum -y install vsftpd2、建立ftp使用用户、组useradd -...

构建linux时间服务器

构建linux时间服务器

1、环境准备服务器ipip功能172.16.0.3ntp服务端172.16.0.2客户端在服务端和客...

du和df查看的数值不一致

du和df查看的数值不一致

我们通过df和du分别查看分区,发现二者的数值有时并不完全一样首先简单介绍一下二者的概念:df:di...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。