CentOS7配置本地yum源
### 文章目录
- [CentOS7配置本地yum源](#文章目录 CentOS7配置本地yum源 @[toc] RHEL9配置本地yum源)
- [@[toc]](#文章目录 CentOS7配置本地yum源 @[toc] RHEL9配置本地yum源)
- [RHEL9配置本地yum源](#文章目录 CentOS7配置本地yum源 @[toc] RHEL9配置本地yum源)
1.创建本地源文件夹。
bash
[root@localhost ~]# mkdir /mnt/cdrom
2.挂载镜像文件至指定的目录。
bash
[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
(挂载如果需要一直生效,需要配置自动挂载,方式如下)
bash
[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.备份本地默认源。
bash
[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文件。
bash
[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.加载本地源并测试。
bash
[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.安装工具。
bash
[root@localhost ~]# yum install -y vim bash-com*
......
Complete!
RHEL9配置本地yum源
1.本地repo文件参数。(其它与以上操作基本一致)
bash
[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