centos配置yum源


http://mirrors.163.com/.help
http://centos.ustc.edu.cn

http://mirrors.sohu.com/help

修改步骤:

1,备份原有的

cd  /etc/yum.repos.d

2,下载新的

163的在http://mirrors.163.com/.help/CentOS6-Base-163.repo

mv 

CentOS6-Base-163.repo  CentOS-Base.repo

3,更新源

 yum    clean all  (yum cleanheaders ;  yum cleanpackages);

 yum  update  yum makecache生成缓存, yummakecache主要目的是将服务器上的软件包信息在本地缓存,以提高搜索安装软件的速度


以下来自:http://blog.csdn.net/leshami/article/details/78133716#comments


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

一、yum源实现的三个机制

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

二、配置本地yum源

创建rpm包文件存放目录及复制相关文件
  # mkdir -pv /mnt/CentOS7_ISO
  # cd /run/media/robin/CentOS\ 7\ x86_64/
  # cp -R * /mnt/CentOS7_ISO/

修改yum源repo文件配置
  # cd /etc/yum.repos.d/
  # mkdir old
  # mv *.repo old

编辑repo配置文件
  # vi /etc/yum.repos.d/local.repo 
  [local-media]
  name=CentOS-$releasever - Media
  baseurl=file:///mnt/CentOS7_ISO/
  gpgcheck=0
  enabled=1
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

清空yum缓存目录
  [root@centos7-router yum.repos.d]# yum clean all
  Loaded plugins: fastestmirror, langpacks
  Cleaning repos: local-media
  Cleaning up everything
  Cleaning up list of fastest mirrors

生成yum元数据
  [root@centos7-router yum.repos.d]# yum makecache
  Loaded plugins: fastestmirror, langpacks
  local-media                                                                        | 3.6 kB  00:00:00    
  (1/4): local-media/group_gz                                                      | 155 kB  00:00:00    
  (2/4): local-media/primary_db                                                    | 2.8 MB  00:00:00    
  (3/4): local-media/other_db                                                      | 1.2 MB  00:00:00    
  (4/4): local-media/filelists_db                                                  | 2.9 MB  00:00:00    
  Determining fastest mirrors
  Metadata Cache Created  ###提示元数据缓存创建成功

查看本机yum repo 仓库
  [root@centos7-router ~]# yum repolist
  Loaded plugins: fastestmirror, langpacks
  Loading mirror speeds from cached hostfile
  repo id                                               repo name                    status
  local-media                                        CentOS-7 - Media                   3,723
  repolist: 3,723
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

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

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

安装vsftp
  [root@centos7-router ~] # yum -y install vsftpd
  [root@centos7-router ~] # vi /etc/selinux/config
      SELINUX=disabled
  [root@centos7-router ~] # setenforce 0  ###立即生效

修改ftp配置文件
  [root@centos7-router ~] # vi /etc/vsftpd/vsftpd.conf
  anon_root=/mnt/CentOS7_ISO

启动ftp
  [root@centos7-router ~]# systemctl start vsftpd
  [root@centos7-router ~]# systemctl enable vsftpd

测试ftp服务可用性
  [root@centos7-router ~]# ftp localhost
  Trying ::1...
  Connected to localhost (::1).
  220 (vsFTPd 3.0.2)
  Name (localhost:root): anonymous
  331 Please specify the password.
  Password:
  230 Login successful.
  Remote system type is UNIX.
  Using binary mode to transfer files.
  ftp> ls
  229 Entering Extended Passive Mode (|||41973|).
  150 Here comes the directory listing.
  -r--r--r--    1 0        0              14 Sep 14 09:06 CentOS_BuildTag
  dr-xr-xr-x    3 0        0              33 Sep 14 09:06 EFI  ### Author : Leshami 
  -r--r--r--    1 0        0            215 Sep 14 09:06 EULA ###  Blog : http://blog.csdn.net/leshami 
  -r--r--r--    1 0        0          18009 Sep 14 09:06 GPL
  dr-xr-xr-x    2 0        0              41 Sep 14 09:06 LiveOS
  dr-xr-xr-x    2 0        0          200704 Sep 14 09:08 Packages
  -r--r--r--    1 0        0            1690 Sep 14 09:08 RPM-GPG-KEY-CentOS-7
  -r--r--r--    1 0        0            1690 Sep 14 09:08 RPM-GPG-KEY-CentOS-Testing-7
  -r--r--r--    1 0        0            2883 Sep 14 09:08 TRANS.TBL
  dr-xr-xr-x    3 0        0              54 Sep 14 09:06 images
  dr-xr-xr-x    2 0        0            4096 Sep 14 09:06 isolinux
  dr-xr-xr-x    2 0        0            4096 Sep 14 09:08 repodata
  226 Directory send OK.

配置防火墙
  [root@centos7-router ~]# firewall-cmd --add-service=ftp --permanent
  [root@centos7-router ~]# firewall-cmd --add-service=ftp
  [root@centos7-router ~]# systemctl reload firewalld.service
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46

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

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

安装httpd
  [root@centos7-router ~]# yum install httpd
  [root@centos7-router ~]# systemctl enable httpd
  [root@centos7-router ~]# systemctl start httpd

配置防火墙
  [root@centos7-router ~]# firewall-cmd --add-service=http --permanent
  [root@centos7-router ~]# firewall-cmd --add-service=http
  [root@centos7-router ~]# systemctl reload firewalld.service

将CentOS 光盘文件copy到/var/www/html/repo
此处使用了链接方式,将其链接到已经在本地磁盘的/mnt/CentOS7_ISO
  [root@centos7-router ~]# ln -sv /mnt/CentOS7_ISO /var/www/html/repo
  ‘/var/www/html/repo’ -> ‘/mnt/CentOS7_ISO’
  [root@centos7-router ~]# ls /var/www/html/repo
  CentOS_BuildTag EULA images LiveOS repo RPM-GPG-KEY-CentOS-7 TRANS.TBL
  EFI GPL isolinux Packages repodata RPM-GPG-KEY-CentOS-Testing-7

通过浏览器校验,此时应该可以看到文件列表(此处略) http://192.168.1.175/repo  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

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

配置客户端
  [root@centos7-web ~]# cd /etc/yum.repos.d/
  [root@centos7-web ~]# mkdir old
  [root@centos7-web ~]# mv *.repo old

  [root@centos7-web yum.repos.d]# vi /etc/yum.repos.d/intranet.repo
  [intranet-media]                                    #库名称
  name=CentOS-$releasever - Media    #名称描述
  baseurl=ftp://172.24.8.254                   #yum源目录,源地址
  gpgcheck=0                                         #检查GPG-KEY,0为不检查,1为检查
  enabled=1                                            #是否用该yum源,0为禁用,1为使用 
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7  #gpgcheck=0时无需配置 

  [root@centos7-web yum.repos.d]# yum clean all
  [root@centos7-web yum.repos.d]# yum makecache
  [root@centos7-web yum.repos.d]# yum repolist
  Loaded plugins: fastestmirror, langpacks
  Loading mirror speeds from cached hostfile
  repo id                     repo name                         status
  intranet-media              CentOS-7 - Media                               3,723
  repolist: 3,723

测试yum配置
  [root@centos7-web yum.repos.d]# yum install ftp -y
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

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

配置客户端repo文件
  [root@centos7-web ~]# mv /etc/yum.repos.d/intranet.repo /etc/yum.repos.d/old/
  [root@centos7-web ~]# yum-config-manager --add-repo=http://192.168.1.175/repo
  Loaded plugins: fastestmirror, langpacks
  adding repo from: http://192.168.1.175/repo

  [192.168.1.175_repo]
  name=added from: http://192.168.1.175/repo
  baseurl=http://192.168.1.175/repo
  enabled=1

  [root@centos7-web ~]# yum clean all
  Loaded plugins: fastestmirror, langpacks
  Cleaning repos: 192.168.1.175_repo
  Cleaning up everything
  Cleaning up list of fastest mirrors

  [root@centos7-web ~]# yum makecache
  Loaded plugins: fastestmirror, langpacks
  192.168.1.175_repo | 3.6 kB 00:00:00
  (1/4): 192.168.1.175_repo/group_gz | 155 kB 00:00:00
  (2/4): 192.168.1.175_repo/primary_db | 2.8 MB 00:00:00
  (3/4): 192.168.1.175_repo/other_db | 1.2 MB 00:00:00
  (4/4): 192.168.1.175_repo/filelists_db | 2.9 MB 00:00:01
  Determining fastest mirrors
  Metadata Cache Created

  [root@centos7-web ~]# yum repolist
  Loaded plugins: fastestmirror, langpacks
  Loading mirror speeds from cached hostfile
  repo id repo name status
  192.168.1.175_repo added from: http://192.168.1.175/repo 3,723
  repolist: 3,723
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

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

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

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

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

配置文件类似:

name=centos7repo
# mount -o loop xxxx.iso /mnt/iso
baseurl=“file:///mnt/iso”
enabled=1
gpgckeck=0
gpgkey=file:///mnt/iso/RPM-GPG-KEY-redhat-release

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

朝闻道-夕死可矣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值