linux中配置yum源

配置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]# mv 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

 构建本地设置yum源:将光盘中现有的rpm文件作为对象,制作本地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 //将原有的注释,并复制一行进行修改 mirrorlist=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]# [root@localhost yum.repos.d]# yum makecache 已加载插件:fastestmirror Determining fastest mirrors 错误:Cannot find a valid baseurl for repo: base [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# vi CentOS-Base.repo baseurl=file:///mnt/
:wq //保存后退出
[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文件中即可。

猜你喜欢

转载自www.cnblogs.com/zhaoyujiao/p/8973803.html