配置内网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源的共享目录下面需要在内网的其他主机上配置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运维技术分享博客 - 享受每一天

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
配置CentOS使用阿里云的yum源,可以按照以下步骤进行操作: 1. 首先备份原有的yum源文件。可以通过以下命令进行备份: ``` cd /etc/yum.repos.d/ mkdir bak/ mv *.repo bak/ ``` 2. 下载阿里云的CentOS-Base.repo文件,并保存到/etc/yum.repos.d/目录下。可以使用以下命令进行下载: ``` curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo ``` 3. 如果需要使用阿里云的epel源,可以继续进行以下操作。在/etc/yum.repos.d/目录下创建epel.repo文件,并添加以下内容: ``` [epel] name=Extra Packages for Enterprise Linux $releasever - $basearch baseurl=https://mirrors.aliyun.com/epel/$releasever/$basearch gpgcheck=1 gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-$releasever enabled=1 ``` 4. 如果需要在企业内网搭建本地yum源服务器,可以按照以下步骤进行操作: - 在内网搭建一台yum源服务器,并配置网络策略允许该服务器每周日晚限时联网。 - 使用yum-utils工具包中的reposync工具,将阿里云的yum源软件包同步到本地服务器的指定目录。可以使用如下命令进行同步: ``` reposync --repoid=阿里云yum源名称 --download_path=/mirror ``` 其中,阿里云yum源名称是指要同步的源的名称,/mirror是指本地服务器上指定的目录。 5. 使用createrepo工具对指定目录下的rpm文件进行索引建立。可以使用如下命令进行索引建立: ``` createrepo /mirror ``` 6. 使用Apache或Nginx等软件提供web服务,将本地服务器上的/mirror目录作为yum源目录,在其他CentOS主机上配置使用该本地yum源。 通过以上步骤,就可以成功配置CentOS使用阿里云的yum源了。请根据实际情况进行相应的配置和操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值