当前位置:首页 > 操作系统 > 正文内容

Linux的YUM源配置(本地YUM源及网络YUM源)

李云召8个月前 (12-01)操作系统2724

大部分情况下服务器是不允许访问公网的,安装软件是很不方便,那么引用下YUM源安装就方便许多了,下边介绍下两种的配置方式:本地和网络的。

本地配置YUM源

1、根据个人喜好使用各种方法上传到服务器,或者是通过cdrom的方式挂载下。

创建两个目录,一个用来存放ISO文件,一个用来挂在ISO镜像
[root@centos01 soft]# mkdir -p /opt/soft /mnt/cdrom

2、执行挂在镜像的命令

[root@centos01 soft]# mount -o loop /opt/soft/CentOS-7.5-x86_64-DVD-1804.iso /mnt/cdrom/
mount: /dev/loop0 写保护,将以只读方式挂载

3、配置到本地YUM源文件,切换到/etc/yum.repos.d目录,将所有repo文件备份后删除,然后创建Local.repo文件

如目录下有其他的“.repo”文件请先删除,或者使用mv命令重新命名为“.repo.bak

[root@centos01 yum.repos.d]# cd /etc/yum.repos.d/
[root@centos01 yum.repos.d]# touch Local.repo
[CentOS7]                  //yum的ID,本地唯一,用于区分不同yum源
name=CentOS-server                //描述信息
baseurl=file:///mnt/cdrom                 //前面的file://是协议,后面的/mnt/cdrom是光盘挂载点
enabled=1                  //1启用当前yum源,0禁用
gpgcheck=0               //1使用公钥验证rpm包的正确性,0不验证

4、执行yum clean all清除历史缓存

[root@centos01 yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: Local-Centos7.5
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@centos01 yum.repos.d]#

执行 yum makecache和yum repolist创建缓存并查看当前yum源的可用资源数

[root@centos01 yum.repos.d]#yum makecache
[root@centos01 yum.repos.d]#yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                         源名称                     状态
Local-Centos7.5                CentOS-7.5                 3,971
repolist: 3,971
[root@centos01 yum.repos.d]#

5、测试安装软件:利用yum进行telnet包安装测试

[root@centos01 /]# yum install telnet
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 telnet.x86_64.1.0.17-64.el7 将被 安装
--> 解决依赖关系完成
 
依赖关系解决
 
==============================================================================================================
 Package              架构                 版本                           源                             大小
==============================================================================================================
正在安装:
 telnet               x86_64               1:0.17-64.el7                  Local-Centos7.5                64 k
 
事务概要
==============================================================================================================
安装  1 软件包
 
总下载量:64 k
安装大小:113 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : 1:telnet-0.17-64.el7.x86_64                                                               1/1 
  验证中      : 1:telnet-0.17-64.el7.x86_64                                                               1/1 
 
已安装:
  telnet.x86_64 1:0.17-64.el7                                                                                 
 
完毕!
[root@centos01 /]#

网络YUM源更换方法:

阿里云
http://mirrors.aliyun.com/repo/

网易
http://mirrors.163.com/.help/centos.html

清华
https://mirrors.tuna.tsinghua.edu.cn/help/centos/

1、进入/etc/yum.repos.d/

执行命令如下:cd /etc/yum.repos.d
将yum源进行备份:mv Centos-Base.repo Centos-Base.repo.bak   也可以删除目录下所有.repo的文件,然后再下载新的配置文件

2、下载Yum源文件,我们以阿里的为例子:执行命令:wget -O Centos-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@localhost yum.repos.d]# wget -O Centos-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2023-12-01 10:58:06--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 36.143.195.224, 111.32.210.190, 111.32.210.193, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|36.143.195.224|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘Centos-Base.repo’
100%[========================================================>] 2,523       --.-K/s   in 0.001s  
2023-12-01 8:08:06 (3.41 MB/s) - ‘Centos-Base.repo’ saved [2523/2523]

3、执行命令:yum makecache,生成YUM缓存

[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                       | 3.6 kB  00:00:00     
extras                                                                     | 2.9 kB  00:00:00     
updates                                                                    | 2.9 kB  00:00:00     
Metadata Cache Created
[root@localhost yum.repos.d]#

4、执行执行命令:yum -y install update

执行 yum makecache和yum repolist创建缓存并查看当前yum源的可用资源数

[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                          repo name                                                status
base/7/x86_64                    CentOS-7 - Base - mirrors.aliyun.com                     10,070+2
extras/7/x86_64                  CentOS-7 - Extras - mirrors.aliyun.com                        518
updates/7/x86_64                 CentOS-7 - Updates - mirrors.aliyun.com                   5,426+8
repolist: 16,014
[root@localhost yum.repos.d]#

5、执行yum install telnet 安装telnet   安装成功表示当前网络YUM源配置成功

[root@centos01 yum.repos.d]# yum install telnet


声明:本文由云召博客收集发布,如有侵权,请联系我们,我们将第一时间进行处理。

本文链接:https://liyunzhao.com/post/138.html

标签: LinuxYUM源
分享给朋友:

“Linux的YUM源配置(本地YUM源及网络YUM源)” 的相关文章

修改机器名的批处理(修改后不用重启立即生效)

修改机器名的批处理(修改后不用重启立即生效)

我们经常修改机器名的时候,系统提示要求重启后生效,现在有了这个批处理,可以不用重启机器就能生效啦,赶紧试试吧。 @echo off title   更改计算机名不重启set /p name=请输您的计算机名: reg add "HKEY_LOCAL_MACHI...

用U盘启动命令 FDISK /CMBR 修复MBR

用U盘启动命令 FDISK /CMBR 修复MBR

          今天给同学安电脑重装系统,发现他的系统却有两个系统,XP+Llinux系统。于是我格了Linux 分区,重新GHOST文件到C盘,重启后提示: GURB     >...

Windows 8.1 Flash For IE 修复方法

Windows 8.1 Flash For IE 修复方法

在Windows8.1的操作系统上,IE打开各种视频网站基本都能播放,但是打开部分网站的时候提示需要升级Flash插件或者是安装Flash插件,但是下载下来有提示如下图:可以采用如下的方式进行修复:1、将32位,64位的flash文件夹分别拷贝到C:\Windows\System32\Macrome...

性能测试知多少--系统计数器与硬件分析

性能测试知多少--系统计数器与硬件分析

性能计数器(Performance Counter),也叫性能监视器。一个人健康状况如何,我们通过对其做各项体检获得相关的状况指标,如血压、心跳,肺活量等。那么在做性能测试过程中,整个系统的软硬件进行监控也必不可少,监控所获得的数据也是我们分析系统性能的主要依据。在整个系统中,对于不同的软件和硬件,...

对硬盘进行分区时,GPT和MBR有什么区别?

对硬盘进行分区时,GPT和MBR有什么区别?

在Windows 8或8.1中设置新磁盘时,系统会询问你是想要使用MBR还是GPT分区。GPT是一种新的标准,并在逐渐取代MBR。GPT带来了很多新特性,但MBR仍然拥有最好的兼容性。GPT并不是Windows专用的新标准—— Mac OS X,Linux,及其他操作系统同样使用GPT。在使用新磁盘...

ssh_exchange_identification:read:Connection reset by peer

ssh_exchange_identification:read:Connection reset by peer

SSH登录相关主机时,提示如下报错如何解决?在客户端连接服务端:[root@foundation66 ~]# ssh root@172.25.254.1ssh_exchange_identification: read: Connection reset by peer## -v表示查看连接详细信息...

发表评论

访客

看不清,换一张

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