1、背景
由于开发环境只有局域网,没法使用网上的各种YUM源,来回拷贝rpm包安装麻烦,还得解决依赖问题。故搭建本地yum源,方便软件的安装。
2、环境
我这里使用centos7.5的最小化安装
[root@bogon ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
3、安装
1.挂载CentOS-7-x86_64-DVD-1804.iso镜像。
[root@bogon ~]# mkdir /mnt/dvdrom #创建挂载目录
[root@bogon ~]# mount /dev/cdrom /mnt/dvdrom/ #将ISO镜像挂载在创建的目录上
mount: /dev/sr0 写保护,将以只读方式挂载
[root@bogon ~]# mkdir /yum/ #创建存放rpm包的目录
[root@bogon ~]# cp -a /mnt/dvdrom/ /yum/ #将挂载目录里的文件拷贝本地目录
[root@bogon ~]# ll /yum/
总用量 0
drwxr-xr-x. 8 root root 254 5月 4 2018 dvdrom
[root@bogon ~]# ll /yum/dvdrom/
总用量 320
-rw-rw-r--. 1 root root 14 5月 2 2018 CentOS_BuildTag
drwxr-xr-x. 3 root root 35 5月 4 2018 EFI
-rw-rw-r--. 1 root root 227 8月 30 2017 EULA
-rw-rw-r--. 1 root root 18009 12月 10 2015 GPL
drwxr-xr-x. 3 root root 57 5月 4 2018 images
drwxr-xr-x. 2 root root 198 5月 4 2018 isolinux
drwxr-xr-x. 2 root root 43 5月 4 2018 LiveOS
drwxrwxr-x. 2 root root 221184 5月 4 2018 Packages
drwxrwxr-x. 2 root root 4096 5月 4 2018 repodata
-rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 5月 4 2018 TRANS.TBL
[root@bogon ~]#
2.备份并删除本地repo
[root@bogon ~]# cd /etc/yum.repos.d/
[root@bogon yum.repos.d]# ll
总用量 40
-rw-r--r--. 1 root root 1664 4月 29 2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 4月 29 2018 CentOS-CR.repo
-rw-r--r--. 1 root root 649 4月 29 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 4月 29 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 4月 29 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 122 6月 9 15:58 centos.repo
-rw-r--r--. 1 root root 1331 4月 29 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 4月 29 2018 CentOS-Vault.repo
[root@bogon yum.repos.d]# tar zcvf repo-bk.tar.gz CentOS-*
CentOS-Base.repo
CentOS-CR.repo
CentOS-Debuginfo.repo
CentOS-fasttrack.repo
CentOS-Media.repo
CentOS-Sources.repo
CentOS-Vault.repo
[root@bogon yum.repos.d]# rm -f CentOS-*
3.配置本地repo
[root@bogon yum.repos.d]# vi centos.repo #创建本地repo
[root@bogon yum.repos.d]# cat centos.repo
[centos]
name=centos
baseurl=file:///yum/dvdrom/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@bogon yum.repos.d]# yum clean all #清除yum缓存
Loaded plugins: fastestmirror
Cleaning repos: centos
Cleaning up everything
Cleaning up list of fastest mirrors
[root@bogon yum.repos.d]# yum makecache #重新构建yum源
centos | 3.6 kB 00:00:00
(1/4): centos/group_gz | 166 kB 00:00:00
(2/4): centos/filelists_db | 3.1 MB 00:00:00
(3/4): centos/primary_db | 3.1 MB 00:00:00
(4/4): centos/other_db | 1.3 MB 00:00:00
Metadata Cache Created
[root@bogon yum.repos.d]#
编写repo需注意,配置repo路径、关闭gbp校验、启用这个repo
3.完成配置。
[root@localhost yum.repos.d]# yum -y install vim
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.160-5.el7 will be installed
--> Processing Dependency: vim-common = 2:7.4.160-5.el7 for package: 2:vim-enhanced-7.4.160-5.el7.x86_64
--> Processing Dependency: libgpm.so.2()(64bit) for package: 2:vim-enhanced-7.4.160-5.el7.x86_64
--> Running transaction check
---> Package gpm-libs.x86_64 0:1.20.7-5.el7 will be installed
---> Package vim-common.x86_64 2:7.4.160-5.el7 will be installed
--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.160-5.el7.x86_64
--> Running transaction check
---> Package vim-filesystem.x86_64 2:7.4.160-5.el7 will be installed
--> Finished Dependency Resolution