配置yum源

1.1什么是YUM源?

yum源可以理解为redhat系统的软件商店,可以从yum中安装软件

1.2什么时候要配置yum源

1)redhat系统默认带了yum源,但包含的软件并不是很全,为了安装某些软件,我们必须得先添加相应的yum源。

2)有些服务器为了安全起见,没有连接外网,所以需要配置本地yum源

3)redhat自带的yum源,有时会出现无法连接,或者速度奇慢,需要修改为国内网易源、阿里源等更加稳定快速的源,以便后期下载软件。

yum源的配置文件在 /etc/yum.repos.d/目录中,使用cd命令进行切换cd /etc/yum.repos.d/,操作如下:

[root@yunweidou ~]# cd /etc/yum.repos.d/
[root@yunweidou yum.repos.d]# ls    查看下面的文件
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  CentOS-x86_64-kernel.repo

1.3使用本地yum仓库配置yum源

1)首先进入到/etc/yum.repos.d/目录中,将所有文件删除

[root@yunweidou yum.repos.d]# rm -rf *
[root@yunweidou yum.repos.d]# ls

2)然后点击虚拟机

 

3)点击设置,选择CD/DVD(IDE)选择自己的镜像文件

4)创建一个挂载点

[root@yunweidou yum.repos.d]# mkdir /media/cdrom           创建挂载点
[root@yunweidou yum.repos.d]# mount /dev/cdrom /media/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only

5)使用df查看

[root@#localhost ~]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
devtmpfs                   919488       0    919488   0% /dev
tmpfs                      931500       0    931500   0% /dev/shm
tmpfs                      931500    9756    921744   2% /run
tmpfs                      931500       0    931500   0% /sys/fs/cgroup
/dev/mapper/centos-root  17811456 1302312  16509144   8% /
/dev/sda1                 1038336  153688    884648  15% /boot
tmpfs                      186304       0    186304   0% /run/user/0
/dev/sr0                  4600876 4600876         0 100% /media/cdrom

6)创建一个文件,文件的结尾要以.repo结尾

[root@#localhost ~]# cd /etc/yum.repos.d/
[root@#localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@#localhost yum.repos.d]# vi yunweidou.repo
[yunweidou]      yum源区别名称,用来区分其它yum源
name=yunweidou       yum源描述
baseurl=file:///media/cdrom 本地yum源的绝对路径
enabled=1     是否使用此yum源
gpgcheck=0      检查软件

7)配置完成之后,wq保存退出,下载安装测试,看是否配置成功

[root@#localhost yum.repos.d]# yum -y install wget
Loaded plugins: fastestmirror
Determining fastest mirrors
yunweidou                                                | 3.6 kB     00:00     
(1/2): yunweidou/group_gz                                  | 153 kB   00:00     
(2/2): yunweidou/primary_db                                | 3.3 MB   00:00     
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution
​
Dependencies Resolved
​
================================================================================
 Package      Arch           Version                    Repository         Size
================================================================================
Installing:
 wget         x86_64         1.14-18.el7_6.1            yunweidou         547 k
​
Transaction Summary
================================================================================
Install  1 Package
​
Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : wget-1.14-18.el7_6.1.x86_64                                  1/1 
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                  1/1 
​
Installed:
  wget.x86_64 0:1.14-18.el7_6.1                                                 
​
Complete!

1.4配置阿里云yum源

1)在配置阿里云yum源之前,我们需要将之前配置的本地源删除

[root@#localhost yum.repos.d]# rm -rf *
[root@#localhost yum.repos.d]# ls

2)测试是否还有本地源

[root@#localhost yum.repos.d]# yum -y install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>

3)配置阿里云yum源(前提是机器能上网)

[root@#localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2023-05-15 14:14:28--  https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 2409:8c10:c00:1503:3::3ef, 2409:8c10:c00:1503:3::3f0, 183.204.36.236, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|2409:8c10:c00:1503:3::3ef|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
​
100%[======================================>] 2,523       --.-K/s   in 0s      
​
2023-05-15 14:14:33 (25.5 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]
[root@#localhost yum.repos.d]# ls
CentOS-Base.repo
​

4)测试配置是否成功

[root@#localhost yum.repos.d]# yum -y install vsftpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-29.el7_9 will be installed
--> Finished Dependency Resolution
​
Dependencies Resolved
​
================================================================================
 Package         Arch            Version                 Repository        Size
================================================================================
Installing:
 vsftpd          x86_64          3.0.2-29.el7_9          updates          173 k
​
Transaction Summary
================================================================================
Install  1 Package
​
Total download size: 173 k
Installed size: 353 k
Downloading packages:
vsftpd-3.0.2-29.el7_9.x86_64.rpm                           | 173 kB   00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : vsftpd-3.0.2-29.el7_9.x86_64                                 1/1 
  Verifying  : vsftpd-3.0.2-29.el7_9.x86_64                                 1/1 
​
Installed:
  vsftpd.x86_64 0:3.0.2-29.el7_9                                                
​
Complete!

5)这样yum源的配置就成功了!

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维豆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值