Linux yum源配置

时间:2022-12-07 19:33:16

Linux yum源配置

  本文介绍Red Hat下yum源配置方法,Redhat使用yum网络源需要购买服务,但是本地yum源不会收费。

  CentOS用户自带yum源,并且yum不收费。

准备工具:

  1、安装机器时的镜像

  2、VMware机器设置里CD/DVD选项,勾选已连接和开机自动连接

步骤:

  1、首先编写yum源的repo文件,存放路径 /etc/yum.repos.d/,以repo结尾,名字任意命名

    格式如下:    

      [rhel7.4]        是用于区别各个不同的仓库,名字不能和其他的仓库名字重复
      name=        对仓库的描述,
      baseurl=          路径  
      enable=        是否启用,1启用  0关闭                     
      gpgcheck=      是否验证,1启用,0关闭

按照这个格式配置,就可以使用yum仓库了,其他更深入的功能见后边更新讲解

       

[root@localhost ~]#  vim /etc/yum.repos.d/rhel.repo 

[rhel7.4]
name=RedHat_Enterprise_linux_7.4
baseurl=file:///iso
enable=1
gpgcheck=0

  

  2、挂载镜像

    首先创建一个挂载点,因为上边配置文件里写的是根目录下的iso目录,所以在根下边创建一个/iso

      mkdir /iso

挂载
[root@localhost ~]# mount /dev/cdrom /iso/
mount: /dev/sr0 is write-protected, mounting read-only 可以看到已经挂载成功
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 10G 7.7G 2.4G 77% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 8.9M 1.9G 1% /dev/shm
tmpfs 1.9G 9.2M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/rhel-usr 35G 24G 12G 68% /usr
/dev/sda1 1014M 145M 870M 15% /boot
/dev/mapper/rhel-tmp 4.0G 60M 4.0G 2% /tmp
/dev/mapper/rhel-opt 4.0G 559M 3.5G 14% /opt
/dev/mapper/rhel-var 8.0G 5.0G 3.1G 63% /var
tmpfs 378M 0 378M 0% /run/user/0
/dev/sr0 3.8G 3.8G 0 100% /iso 当/iso出现以下内容,表明挂载成功
[root@localhost ~]# ls /iso/
addons GPL media.repo RPM-GPG-KEY-redhat-release
EFI images Packages TRANS.TBL
EULA isolinux repodata
extra_files.json LiveOS RPM-GPG-KEY-redhat-beta

  查看仓库

[root@localhost ~]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repo id repo name status
rhel7.4 RedHat_Enterprise_linux_7.4 4,986
repolist: 4,986

  安装服务测试一下

[root@localhost ~]# yum install vsftpd
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved =========================================================================================
Package Arch Version Repository Size
=========================================================================================
Installing:
vsftpd x86_64 3.0.2-22.el7 rhel7.4 169 k Transaction Summary
=========================================================================================
Install 1 Package Total download size: 169 k
Installed size: 348 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-22.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1 Installed:
vsftpd.x86_64 0:3.0.2-22.el7 Complete!

  至此,yum配置安装完成