linux中配置yum源

时间:2022-12-29 15:20:41

1、配置163或者阿里云yum源:


阿里云yum源地址:https://mirrors.aliyun.com/centos/6.9/os/x86_64/Packages/

阿里云给出的解决办法:https://mirrors.aliyun.com/centos 点击centos后面的帮助即可看到:

1、备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/ CentOS 5 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo CentOS 6 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 
// 可以直接通过访问url下载到本地后上传到linux目录中,如果linux中不支持wget时,可以使用这种方法。 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 3、之后运行yum makecache生成缓存

 具体操作:

[root@localhost zyj]# cd /etc/yum.repos.d/  //yum源的配置文件,查看默认yum源,一般默认为centos官网下的yum源。
[root@localhost yum.repos.d]# ll
total 24
-rw-r--r--. 1 root root 1991 Mar 28 2017 CentOS-Base.repo -rw-r--r--. 1 root root 647 Mar 28 2017 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 630 Mar 28 2017 CentOS-Media.repo -rw-r--r--. 1 root root 7989 Mar 28 2017 CentOS-Vault.repo -rw-r--r--. 1 root root 289 Mar 28 2017 CentOS-fasttrack.repo [root@localhost yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.backup //备份 [root@localhost yum.repos.d]# ll total 24 -rw-r--r--. 1 root root 1991 Mar 28 2017 CentOS-Base.repo.backup -rw-r--r--. 1 root root 647 Mar 28 2017 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 630 Mar 28 2017 CentOS-Media.repo -rw-r--r--. 1 root root 7989 Mar 28 2017 CentOS-Vault.repo -rw-r--r--. 1 root root 289 Mar 28 2017 CentOS-fasttrack.repo -rw-r--r--. 1 root root 0 Apr 29 11:58 my.repos [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo //下载新的yum源到本地 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 102 2572 102 2572 0 0 7505 0 --:--:-- --:--:-- --:--:-- 11482 [root@localhost yum.repos.d]# ll total 28 -rw-r--r--. 1 root root 2572 Apr 30 03:07 CentOS-Base.repo [root@localhost yum.repos.d]# yum clean all //清除之前的缓存 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: base extras updates Cleaning up Everything Cleaning up list of fastest mirrors [root@localhost yum.repos.d]# yum makecache //生成缓存 Failed to set locale, defaulting to C Loaded plugins: fastestmirror, refresh-packagekit, security Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.7 kB 00:00 base/group_gz | 226 kB 00:00 base/filelists_db | 6.4 MB 00:05 base/primary_db | 4.7 MB 00:06 base/other_db | 2.8 MB 00:03 extras | 3.4 kB 00:00 extras/filelists_db | 26 kB 00:00 extras/prestodelta | 1.7 kB 00:00 extras/primary_db | 30 kB 00:00 extras/other_db | 32 kB 00:00 updates | 3.4 kB 00:00 updates/filelists_db | 4.3 MB 00:05 updates/prestodelta | 245 kB 00:00 updates/primary_db | 7.0 MB 00:05 updates/other_db | 100 MB 01:27

 2、构建本地设置yum源:通过光盘方式。


1、插入完整版的IOS文件到光驱;将虚拟中mini版的linux虚拟机通过设置中的CD选择为完整版的镜像;

2、挂载光盘;mount /dev/cdrom /mnt

[root@localhost ~]# cd /mnt/  //查看挂载点目录
[root@localhost mnt]# ls
[root@localhost mnt]# mount /dev/cdrom /mnt //挂载光盘
mount: block device /dev/sr0 is write-protected, mounting read-only [root@localhost mnt]# cd /dev [root@localhost dev]# ls -l cdrom lrwxrwxrwx. 1 root root 3 4月 30 18:52 cdrom -> sr0 [root@localhost dev]# [root@localhost dev]# cd /mnt/ //查看挂载文件 [root@localhost mnt]# ls CentOS_BuildTag GPL Packages RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Testing-6 EFI images RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Debug-6 TRANS.TBL EULA isolinux repodata RPM-GPG-KEY-CentOS-Security-6 [root@localhost mnt]# cd Packages/ //查看挂载后的rpm文件 [root@localhost Packages]# ls 389-ds-base-1.2.11.15-89.el6.x86_64.rpm libreoffice-math-4.3.7.2-2.el6.x86_64.rpm 389-ds-base-libs-1.2.11.15-89.el6.x86_64.rpm libreoffice-ogltrans-4.3.7.2-2.el6.x86_64.rpm abrt-2.0.8-43.el6.centos.x86_64.rpm libreoffice-opensymbol-fonts-4.3.7.2-2.el6.noarch.rpm abrt-addon-ccpp-2.0.8-43.el6.centos.x86_64.rpm libreoffice-pdfimport-4.3.7.2-2.el6.x86_64.rpm abrt-addon-kerneloops-2.0.8-43.el6.centos.x86_64.rpm libreoffice-pyuno-4.3.7.2-2.el6.x86_64.rpm abrt-addon-python-2.0.8-43.el6.centos.x86_64.rpm libreoffice-ure-4.3.7.2-2.el6.x86_64.rpm abrt-cli-2.0.8-43.el6.centos.x86_64.rpm libreoffice-wiki-publisher-4.3.7.2-2.el6.x86_64.rpm abrt-desktop-2.0.8-43.el6.centos.x86_64.rpm libreoffice-writer-4.3.7.2-2.el6.x86_64.rpm abrt-gui-2.0.8-43.el6.centos.x86_64.rpm libreoffice-xsltfilter-4.3.7.2-2.el6.x86_64.rpm abrt-libs-2.0.8-43.el6.centos.x86_64.rpm libreport-2.0.9-33.el6.centos.x86_64.rpm abrt-python-2.0.8-43.el6.centos.x86_64.rpm libreport-cli-2.0.9-33.el6.centos.x86_64.rpm abrt-tui-2.0.8-43.el6.centos.x86_64.rpm libreport-compat-2.0.9-33.el6.centos.x86_64.rpm abyssinica-fonts-1.0-5.1.el6.noarch.rpm libreport-filesystem-2.0.9-33.el6.centos.x86_64.rpm acl-2.2.49-7.el6.x86_64.rpm libreport-gtk-2.0.9-33.el6.centos.x86_64.rpm acpid-1.0.10-3.el6.x86_64.rpm libreport-newt-2.0.9-33.el6.centos.x86_64.rpm adcli-0.8.1-1.el6.x86_64.rpm libreport-plugin-kerneloops-2.0.9-33.el6.centos.x86_64.rpm aic94xx-firmware-30-2.el6.noarch.rpm libreport-plugin-logger-2.0.9-33.el6.centos.x86_64.rpm aide-0.14-11.el6.x86_64.rpm libreport-plugin-mailx-2.0.9-33.el6.centos.x86_64.rpm akonadi-1.2.1-3.el6.x86_64.rpm libreport-plugin-reportuploader-2.0.9-33.el6.centos.x86_64.rpm alacarte-0.12.4-1.el6.noarch.rpm libreport-plugin-rhtsupport-2.0.9-33.el6.centos.x86_64.rpm alsa-lib-1.1.0-4.el6.x86_64.rpm libreport-plugin-ureport-2.0.9-33.el6.centos.x86_64.rpm alsa-lib-devel-1.1.0-4.el6.x86_64.rpm libreport-python-2.0.9-33.el6.centos.x86_64.rpm alsa-plugins-pulseaudio-1.1.0-1.el6.x86_64.rpm librepository-1.0.0-2.OOo31.1.el6.x86_64.rpm alsa-utils-1.1.0-10.el6.x86_64.rpm libreswan-3.15-7.3.el6.x86_64.rpm

 3、修改/etc/yum.repos.d/CentOS-Base.repo;

 4、该目录下的其他配置文件删除,清除缓存文件并生成缓存;

 5、yum源配置完成后,可使用yum install 安装应用程序。

[root@localhost yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.backup  //备份原有配置文件
[root@localhost yum.repos.d]# ll
总用量 28
-rw-r--r--. 1 root root 1991 3月  28 2017 CentOS-Base.repo -rw-r--r--. 1 root root 1991 4月 30 19:03 CentOS-Base.repo.backup -rw-r--r--. 1 root root 647 3月 28 2017 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 289 3月 28 2017 CentOS-fasttrack.repo -rw-r--r--. 1 root root 630 3月 28 2017 CentOS-Media.repo -rw-r--r--. 1 root root 7989 3月 28 2017 CentOS-Vault.repo [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# vi CentOS-Base.repo //修改配置文件 [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/? release=$releasever&arch=$basearch&repo=os&infra=$infra //将原有的注释,并复制一行进行修改 baseurl=file:///mnt/  //file://表示本地获取 #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 //启用检测gpg签名,验证rpm文件的安全性。 gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-6 //gpg签名文件路径  #released updates [updates] name=CentOS-$releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6  #additional packages that may be useful [extras] name=CentOS-$releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6  #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 //不启用的意思。 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 :wq //保存后退出  [root@localhost yum.repos.d]# yum clean all 已加载插件:fastestmirror Cleaning repos: base extras updates 清理一切 Cleaning up list of fastest mirrors 
[root@localhost yum.repos.d]# yum makecache //生成缓存 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * extras: mirrors.sohu.com * updates: mirrors.aliyun.com base | 4.0 kB 00:00 ... base/group_gz | 226 kB 00:00 ... base/filelists_db | 6.3 MB 00:01 ... base/primary_db | 4.7 MB 00:00 ... base/other_db | 2.7 MB 00:00 ..

注意:使用挂载光盘中的rpm文件作为yum源,由于光盘不能写以及重启后可能需要重新挂载,这时候可以通过将网络上的所有rpm文件下载到本地目录中,如/opt文件中即可。

[root@localhost ~]# cp /mnt/ /opt/
cp: 略过目录"/mnt/"

 

3、构建本地设置yum源:通过下载rpm文件到本地目录的方式。


 1、下载网络上yum源中的所有rpm文件到本地目录中;使用reposync命令。

 安装yum-utils工具后,可以提供reposync命令:同步yum源上的rpm文件到本地目录。注意,同步的yum源需要提前配置好,之后会到配置好的yum源中同步rpm文件到本地目录。

[root@localhost ~]# yum search yum-util //忘记名字时,可以通过search查寻下;
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * extras: mirrors.aliyun.com
 * updates: mirrors.sohu.com
====================================================== N/S Matched: yum-util ======================================================
yum-utils.noarch : Utilities based around the yum package manager

  Name and summary matches only, use "search all" for everything.
[root@localhost ~]# yum install yum-utils -y //安装时不用手动确认yes
已加载插件:fastestmirror
设置安装进程
Loading mirror speeds from cached hostfile
 * extras: mirrors.aliyun.com
 * updates: mirrors.sohu.com
解决依赖关系
--> 执行事务检查
---> Package yum-utils.noarch 0:1.1.30-40.el6 will be 安装
--> 处理依赖关系 libxml2-python,它被软件包 yum-utils-1.1.30-40.el6.noarch 需要
--> 执行事务检查
---> Package libxml2-python.x86_64 0:2.7.6-21.el6_8.1 will be 安装
--> 完成依赖关系计算

依赖关系解决

===================================================================================================================================
 软件包                             架构                       版本                                 仓库                      大小
===================================================================================================================================
正在安装:
 yum-utils                          noarch                     1.1.30-40.el6                        base                     113 k
为依赖而安装:
 libxml2-python                     x86_64                     2.7.6-21.el6_8.1                     base                     325 k

事务概要
===================================================================================================================================
Install       2 Package(s)

总下载量:437 k
Installed size: 2.2 M
下载软件包:
-----------------------------------------------------------------------------------------------------------------------------------
总计                                                                                               1.3 MB/s | 437 kB     00:00     
运行 rpm_check_debug 
执行事务测试
事务测试成功
执行事务
  正在安装   : libxml2-python-2.7.6-21.el6_8.1.x86_64                                                                          1/2 
  正在安装   : yum-utils-1.1.30-40.el6.noarch                                                                                  2/2 
  Verifying  : yum-utils-1.1.30-40.el6.noarch                                                                                  1/2 
  Verifying  : libxml2-python-2.7.6-21.el6_8.1.x86_64                                                                          2/2 

已安装:
  yum-utils.noarch 0:1.1.30-40.el6                                                                                                 

作为依赖被安装:
  libxml2-python.x86_64 0:2.7.6-21.el6_8.1                                                                                         

完毕!

创建目录后,通过reposync命令从yum源中同步rpm文件到本地

[root@localhost ~]# cd /home
[root@localhost home]# ls
x
[root@localhost home]# mkdir mirrors
[root@localhost home]# cd mirrors/
[root@localhost mirrors]# ls
[root@localhost mirrors]# reposync -r base   //-r指定下载的库,可以通过yum repolist查看有哪些库。 
[base: 1     of 6706  ] Downloading Packages/389-ds-base-1.2.11.15-89.el6.x86_64.rpm
[base: 2     of 6706  ] Downloading Packages/389-ds-base-devel-1.2.11.15-89.el6.i686.rpm
Could not retrieve package 389-ds-base-devel-1.2.11.15-89.el6.i686. 
...
[root@localhost mirrors]# ls
base
[root@localhost mirrors]# cd base/
[root@localhost base]# ls
Packages
[root@localhost base]# cd Packages/
[root@localhost Packages]# ll
总用量 3618704

更改yum源配置文件,从163或者默认官网中的yum源下载rpm文件;
[root@localhost yum.repos.d]# yum reposlist
已加载插件:fastestmirror
No such command: reposlist. Please use /usr/bin/yum --help
[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.sohu.com
* extras: mirrors.sohu.com
* updates: mirrors.aliyun.com
仓库标识 仓库名称 状态
base CentOS-6 - Base 6,706
extras CentOS-6 - Extras 53
updates CentOS-6 - Updates 1,185
repolist: 7,944
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# reposync -r base -p /opt/repos/   //-r 指定下载的库,-p指定下载到本地哪个目录
[root@localhost yum.repos.d]# cd /opt/repos
[root@localhost repos]# ls
base
[root@localhost repos]# cd base/
[root@localhost base]# ls
Packages
[root@localhost base]# cd Packages/
[root@localhost Packages]# ls
389-ds-base-1.2.11.15-89.el6.x86_64.rpm             OpenEXR-1.6.1-8.1.el6.x86_64.rpm
389-ds-base-devel-1.2.11.15-89.el6.i686.rpm         OpenEXR-devel-1.6.1-8.1.el6.i686.rpm
389-ds-base-devel-1.2.11.15-89.el6.x86_64.rpm       OpenEXR-devel-1.6.1-8.1.el6.x86_64.rpm
389-ds-base-libs-1.2.11.15-89.el6.i686.rpm          OpenEXR-libs-1.6.1-8.1.el6.i686.rpm
389-ds-base-libs-1.2.11.15-89.el6.x86_64.rpm        OpenEXR-libs-1.6.1-8.1.el6.x86_64.rpm
ConsoleKit-0.4.1-6.el6.x86_64.rpm                   OpenIPMI-2.0.16-14.el6.x86_64.rpm

2、修改/etc/yum.repos.d/CentOS-Base.repo;修改本地目录为/opt/repos/ 其中设置gpgcheck=0;

3、该目录下的其他配置文件删除,清除缓存文件并生成缓存;

4、yum源配置完成后,可使用yum install 安装应用程序。

5、本地yum源需要别人也可以访问,可以通过浏览器访问需要安装相关组建或者通过设置目录共享的方式,具体操作如下:

#服务器端配置:

1、安装nfs-utils和rpcbind yum install -y nfs-utils rpcbind 2、设置开机启动服务 Chkconfig nfs on Chkconfig rpcbind on 3、启动相关服务 Service rpcbind start Service nfs start 4、创建共享目录 mkdir /share 5、编辑/etc/exports文件添加如下内容: vim /etc/exports /share client_ip(rv,no_root_squash,no_subtree_check)

#客户端配置:
指定ip地址的主机:192.168.0.100

指定子网中的所有主机:192.168.0.0/24或192.168.0.0/255.255.255.0

指定域名的主机:nfs.test.com

指定域中的所有主机:*.test.com

所有主机:*