yum软件仓库的搭建方式有三种,分别是本地yum源,网络yum源,第三方软件仓库。
以下示例演示了搭建本地yum仓库的方法:
1. 删除 /etc/yum.repos.d/dvd.repo 这个仓库文件
[root@desktop1 ~]# ll /etc/yum.repos.d/ total 8 -rw-r--r--. 1 root root 84 Sep 27 20:20 dvd.repo -r--r--r--. 1 root root 114 Oct 30 2015 packagekit-media.repo [root@desktop1 ~]# rm -f /etc/yum.repos.d/dvd.repo
2.运行yum repolist,确保当前的电脑中没有yum仓库
[root@desktop1 ~]# yum repolist Loaded plugins: langpacks repolist: 0
3. 使用 yum-config-manager 工具,创建一个仓库文件,软件包的目录为本地主机文件系统 中的:/rhel7/dvd
[root@desktop1 ~]# yum-config-manager --add-repo=file:///rhel7/dvd Loaded plugins: langpacks adding repo from: file:///rhel7/dvd [rhel7_dvd] name=added from: file:///rhel7/dvd baseurl=file:///rhel7/dvd enabled=1
4. 再次查看/etc/repos.d/中已经有了新的软件仓库
[root@desktop1 ~]# ll /etc/yum.repos.d/ total 8 -r--r--r--. 1 root root 114 Oct 30 2015 packagekit-media.repo -rw-r--r--. 1 root root 85 Nov 2 16:41 rhel7_dvd.repo
5. 编辑仓库文件rhel7_dvd.repo,确保 repo id 为“LOCAL_RHEL7”,repo name 为“LOCAL_REPO”
原始文件:
[rhel7_dvd] name=added from: file:///rhel7/dvd baseurl=file:///rhel7/dvd enabled=1
更改后:
[root@desktop1 ~]# cat /etc/yum.repos.d/rhel7_dvd.repo [LOCAL_RHEL7] name=LOCAL_REPO gpgcheck=1 gpgkey=file:///rhel7/dvd/RPM-GPG-KEY-redhat-release
6. 使用 yum repolist 确保上一步骤的更改已生效
[root@desktop1 ~]# yum repolist Loaded plugins: langpacks LOCAL_RHEL7 | 4.1 kB 00:00:00 (1/2): LOCAL_RHEL7/group_gz | 134 kB 00:00:00 (2/2): LOCAL_RHEL7/primary_db | 3.4 MB 00:00:00 repo id repo name status LOCAL_RHEL7 LOCAL_REPO 4,305 repolist: 4,305
7. 尝试安装 bind 这个软件包,确认你的 YUM 仓库可以使用
[root@desktop1 ~]# yum -y install bind Loaded plugins: langpacks Resolving Dependencies --> Running transaction check ---> Package bind.x86_64 32:9.9.4-14.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================== Package Arch Version Repository Size ================================================================================================================== Installing: bind x86_64 32:9.9.4-14.el7 LOCAL_RHEL7 1.8 M Transaction Summary ================================================================================================================== Install 1 Package Total download size: 1.8 M Installed size: 4.3 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 32:bind-9.9.4-14.el7.x86_64 1/1 Verifying : 32:bind-9.9.4-14.el7.x86_64 1/1 Installed: bind.x86_64 32:9.9.4-14.el7 Complete! [root@desktop1 ~]#