自学内容网 自学内容网

CentOS7&RHEL9本地yum源配置

CentOS7配置本地yum源

1.创建本地源文件夹。

[root@localhost ~]# mkdir /mnt/cdrom

2.挂载镜像文件至指定的目录。

[root@localhost ~]# mount /dev/sr0 /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# ls /mnt/cdrom/
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

(挂载如果需要一直生效,需要配置自动挂载,方式如下)

[root@localhost ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  475M     0  475M   0% /dev
tmpfs                   tmpfs     487M     0  487M   0% /dev/shm
tmpfs                   tmpfs     487M  7.6M  479M   2% /run
tmpfs                   tmpfs     487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        17G  1.4G   16G   8% /
/dev/sda1               xfs      1014M  138M  877M  14% /boot
tmpfs                   tmpfs      98M     0   98M   0% /run/user/0
/dev/sr0                iso9660   4.4G  4.4G     0 100% /mnt/cdrom
[root@localhost ~]# vim /etc/fstab 
[root@localhost ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Fri Oct 11 03:49:41 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=4be482c4-39dd-443f-8a78-78647260fa24 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sr0        /mnt/cdrom      iso9660 defaults        0 0//配置文件最末加上此条配置
[root@localhost ~]# mount -a//触发挂载

3.备份本地默认源。

[root@localhost ~]# ls /etc/yum.repos.d/
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
[root@localhost ~]# mv /etc/yum.repos.d/* /media/
[root@localhost ~]# ls /media/
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
[root@localhost ~]# ls /etc/yum.repos.d/

4.配置本地源,编写local.repo文件。

[root@localhost ~]# vi /etc/yum.repos.d/local.repo
[root@localhost ~]# cat /etc/yum.repos.d/local.repo
[centos7_local]
name=centos_local
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0

5.加载本地源并测试。

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: centos7_local
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
centos7_local                                                                                         | 3.6 kB  00:00:00     
(1/4): centos7_local/group_gz                                                                         | 153 kB  00:00:00     
(2/4): centos7_local/filelists_db                                                                     | 3.3 MB  00:00:00     
(3/4): centos7_local/primary_db                                                                       | 3.3 MB  00:00:00     
(4/4): centos7_local/other_db                                                                         | 1.3 MB  00:00:00     
Metadata Cache Created

6.安装工具。

[root@localhost ~]# yum install -y vim bash-com*
......
Complete!

RHEL9配置本地yum源

1.本地repo文件参数。(其它与以上操作基本一致)

[root@redhat03 ~]# cat /etc/yum.repos.d/local.repo 
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
enabled=1
gpgcheck=0
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
enabled=1
gpgcheck=0

原文地址:https://blog.csdn.net/qq_65998623/article/details/142920222

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!