CentOS 7下配置本地yum源及yum客户端

前端之家收集整理的这篇文章主要介绍了CentOS 7下配置本地yum源及yum客户端前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Linux下对于软件包的管理使用rpm管理方式。直接使用rpm包管理工具来进行rpm包的安装,升级,卸载时,对于最让人头疼的莫过与包之间的依赖关系。yum作为一个rpm包前端管理工具,可以自动处理依赖性关系,一次安装所有依赖的软件包,并且支持在线下载、安装、卸载、升级rpm软件包。本文主要描述基于本机,本地yum服务器配置yum源,以及基于公网yum源配置本地客户端,供大家参考。

一、yum源实现的三个机制

1、需要有一个包含各种rpm安装文件的软件仓库(即yum源)
2、有软件仓库的仓库数据库(repodata),其中收集了软件仓库中所有rpm包的头部信息(每个rpm包的包头信息包含了该包的描述,功能,提供的文件,依赖关系等信息);
3、有软件仓库的地址等信息

二、配置本地yum源

  1. 创建rpm文件存放目录及复制相关文件
  2. # mkdir -pv /mnt/CentOS7_ISO
  3. # cd /run/media/robin/CentOS\ 7\ x86_64/
  4. # cp -R * /mnt/CentOS7_ISO/
  5.  
  6. 修改yumrepo文件配置
  7. # cd /etc/yum.repos.d/
  8. # mkdir old
  9. # mv *.repo old
  10.  
  11. 编辑repo配置文件
  12. # vi /etc/yum.repos.d/local.repo
  13. [local-media]
  14. name=CentOS-$releasever - Media
  15. baseurl=file:///mnt/CentOS7_ISO/
  16. gpgcheck=0
  17. enabled=1
  18. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  19.  
  20. 清空yum缓存目录
  21. [root@centos7-router yum.repos.d]# yum clean all
  22. Loaded plugins: fastestmirror,langpacks
  23. Cleaning repos: local-media
  24. Cleaning up everything
  25. Cleaning up list of fastest mirrors
  26.  
  27. 生成yum元数据
  28. [root@centos7-router yum.repos.d]# yum makecache
  29. Loaded plugins: fastestmirror,langpacks
  30. local-media | 3.6 kB 00:00:00
  31. (1/4): local-media/group_gz | 155 kB 00:00:00
  32. (2/4): local-media/primary_db | 2.8 MB 00:00:00
  33. (3/4): local-media/other_db | 1.2 MB 00:00:00
  34. (4/4): local-media/filelists_db | 2.9 MB 00:00:00
  35. Determining fastest mirrors
  36. Metadata Cache Created ###提示元数据缓存创建成功
  37.  
  38. 查看本机yum repo 仓库
  39. [root@centos7-router ~]# yum repolist
  40. Loaded plugins: fastestmirror,langpacks
  41. Loading mirror speeds from cached hostfile
  42. repo id repo name status
  43. local-media CentOS-7 - Media 3,723
  44. repolist: 3,723

二、基于ftp方式配置本地yum发布源

为本机配置ftp服务器,将其发布供网络其它客户端作为yum源

  1. 安装vsftp
  2. [root@centos7-router ~] # yum -y install vsftpd
  3. [root@centos7-router ~] # vi /etc/selinux/config
  4. SELINUX=disabled
  5. [root@centos7-router ~] # setenforce 0 ###立即生效
  6.  
  7. 修改ftp配置文件
  8. [root@centos7-router ~] # vi /etc/vsftpd/vsftpd.conf
  9. anon_root=/mnt/CentOS7_ISO
  10.  
  11. 启动ftp
  12. [root@centos7-router ~]# systemctl start vsftpd
  13. [root@centos7-router ~]# systemctl enable vsftpd
  14.  
  15. 测试ftp服务可用性
  16. [root@centos7-router ~]# ftp localhost
  17. Trying ::1...
  18. Connected to localhost (::1).
  19. 220 (vsFTPd 3.0.2)
  20. Name (localhost:root): anonymous
  21. 331 Please specify the password.
  22. Password:
  23. 230 Login successful.
  24. Remote system type is UNIX.
  25. Using binary mode to transfer files.
  26. ftp> ls
  27. 229 Entering Extended Passive Mode (|||41973|).
  28. 150 Here comes the directory listing.
  29. -r--r--r-- 1 0 0 14 Sep 14 09:06 CentOS_BuildTag
  30. dr-xr-xr-x 3 0 0 33 Sep 14 09:06 EFI ### Author : Leshami
  31. -r--r--r-- 1 0 0 215 Sep 14 09:06 EULA ### Blog : http://blog.csdn.net/leshami
  32. -r--r--r-- 1 0 0 18009 Sep 14 09:06 GPL
  33. dr-xr-xr-x 2 0 0 41 Sep 14 09:06 LiveOS
  34. dr-xr-xr-x 2 0 0 200704 Sep 14 09:08 Packages
  35. -r--r--r-- 1 0 0 1690 Sep 14 09:08 RPM-GPG-KEY-CentOS-7
  36. -r--r--r-- 1 0 0 1690 Sep 14 09:08 RPM-GPG-KEY-CentOS-Testing-7
  37. -r--r--r-- 1 0 0 2883 Sep 14 09:08 TRANS.TBL
  38. dr-xr-xr-x 3 0 0 54 Sep 14 09:06 images
  39. dr-xr-xr-x 2 0 0 4096 Sep 14 09:06 isolinux
  40. dr-xr-xr-x 2 0 0 4096 Sep 14 09:08 repodata
  41. 226 Directory send OK.
  42.  
  43. 配置防火墙
  44. [root@centos7-router ~]# firewall-cmd --add-service=ftp --permanent
  45. [root@centos7-router ~]# firewall-cmd --add-service=ftp
  46. [root@centos7-router ~]# systemctl reload firewalld.service

三、基于http方式配置本地yum发布源

除了支持ftp方式外,也可以通过http方式将其发布供网络其它客户端作为yum源

  1. 安装httpd
  2. [root@centos7-router ~]# yum install httpd
  3. [root@centos7-router ~]# systemctl enable httpd
  4. [root@centos7-router ~]# systemctl start httpd
  5.  
  6. 配置防火墙
  7. [root@centos7-router ~]# firewall-cmd --add-service=http --permanent
  8. [root@centos7-router ~]# firewall-cmd --add-service=http
  9. [root@centos7-router ~]# systemctl reload firewalld.service
  10.  
  11. CentOS 光盘文件copy到/var/www/html/repo
  12. 此处使用了链接方式,将其链接到已经在本地磁盘的/mnt/CentOS7_ISO
  13. [root@centos7-router ~]# ln -sv /mnt/CentOS7_ISO /var/www/html/repo
  14. ‘/var/www/html/repo -> ‘/mnt/CentOS7_ISO
  15. [root@centos7-router ~]# ls /var/www/html/repo
  16. CentOS_BuildTag EULA images LiveOS repo RPM-GPG-KEY-CentOS-7 TRANS.TBL
  17. EFI GPL isolinux Packages repodata RPM-GPG-KEY-CentOS-Testing-7
  18.  
  19. 通过浏览器校验,此时应该可以看到文件列表(此处略) http://192.168.1.175/repo

四、配置本地网络yum源客户端(ftp方式)

  1. 配置客户端
  2. [root@centos7-web ~]# cd /etc/yum.repos.d/
  3. [root@centos7-web ~]# mkdir old
  4. [root@centos7-web ~]# mv *.repo old
  5.  
  6. [root@centos7-web yum.repos.d]# vi /etc/yum.repos.d/intranet.repo
  7. [intranet-media] #库名称
  8. name=CentOS-$releasever - Media #名称描述
  9. baseurl=ftp://172.24.8.254 #yum源目录,源地址
  10. gpgcheck=0 #检查GPG-KEY,0为不检查,1为检查
  11. enabled=1 #是否用该yum源,0为禁用,1为使用
  12. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #gpgcheck=0时无需配置
  13.  
  14. [root@centos7-web yum.repos.d]# yum clean all
  15. [root@centos7-web yum.repos.d]# yum makecache
  16. [root@centos7-web yum.repos.d]# yum repolist
  17. Loaded plugins: fastestmirror,langpacks
  18. Loading mirror speeds from cached hostfile
  19. repo id repo name status
  20. intranet-media CentOS-7 - Media 3,723
  21.  
  22. 测试yum配置
  23. [root@centos7-web yum.repos.d]# yum install ftp -y

四、配置本地网络yum源客户端(http方式)

  1. 配置客户端repo文件
  2. [root@centos7-web ~]# mv /etc/yum.repos.d/intranet.repo /etc/yum.repos.d/old/
  3. [root@centos7-web ~]# yum-config-manager --add-repo=http://192.168.1.175/repo
  4. Loaded plugins: fastestmirror,langpacks
  5. adding repo from: http://192.168.1.175/repo
  6.  
  7. [192.168.1.175_repo]
  8. name=added from: http://192.168.1.175/repo
  9. baseurl=http://192.168.1.175/repo
  10. enabled=1
  11.  
  12. [root@centos7-web ~]# yum clean all
  13. Loaded plugins: fastestmirror,langpacks
  14. Cleaning repos: 192.168.1.175_repo
  15. Cleaning up everything
  16. Cleaning up list of fastest mirrors
  17.  
  18. [root@centos7-web ~]# yum makecache
  19. Loaded plugins: fastestmirror,langpacks
  20. 192.168.1.175_repo | 3.6 kB 00:00:00
  21. (1/4): 192.168.1.175_repo/group_gz | 155 kB 00:00:00
  22. (2/4): 192.168.1.175_repo/primary_db | 2.8 MB 00:00:00
  23. (3/4): 192.168.1.175_repo/other_db | 1.2 MB 00:00:00
  24. (4/4): 192.168.1.175_repo/filelists_db | 2.9 MB 00:00:01
  25. Determining fastest mirrors
  26. Metadata Cache Created
  27.  
  28. [root@centos7-web ~]# yum repolist
  29. Loaded plugins: fastestmirror,langpacks
  30. Loading mirror speeds from cached hostfile
  31. repo id repo name status
  32. 192.168.1.175_repo added from: http://192.168.1.175/repo 3,723
  33. repolist: 3,723

五、配置阿里云、epel yum源客户端

  1. # wget -O /etc/yum.repos.d/aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  2. # rpm -Uvh http://mirrors.kernel.org/fedora-epel/epel-release-latest-7.noarch.rpm
  3. # yum makecache

六、虚拟机环境直接使用iso文件充当yum源(补充@20171110)

如下为光盘iso文件路径,可以直接将其配置到baseurl,最大的好处是,可以节省虚拟机磁盘空间占用。如下: baseurl=”file:///run/media/robin/CentOS 7 x86_64”

猜你在找的CentOS相关文章