linux中配置yum源

Posted 七彩蜗牛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux中配置yum源相关的知识,希望对你有一定的参考价值。

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生成缓存

 具体操作:

[[email protected] zyj]# cd /etc/yum.repos.d/  //yum源的配置文件,查看默认yum源,一般默认为centos官网下的yum源。
[[email protected] 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
[[email protected] yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.backup  //备份
[[email protected] 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
[[email protected] yum.repos.d]# 
[[email protected] 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
[[email protected] yum.repos.d]# ll
total 28
-rw-r--r--. 1 root root 2572 Apr 30 03:07 CentOS-Base.repo
[[email protected] 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

[[email protected] 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

[[email protected] ~]# cd /mnt/  //查看挂载点目录
[[email protected] mnt]# ls
[[email protected] mnt]# mount /dev/cdrom /mnt //挂载光盘
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] mnt]# cd /dev 
[[email protected] dev]# ls -l cdrom
lrwxrwxrwx. 1 root root 3 4月  30 18:52 cdrom -> sr0
[[email protected] dev]# 
[[email protected] dev]# cd /mnt/ //查看挂载文件
[[email protected] 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
[[email protected] mnt]# cd Packages/   //查看挂载后的rpm文件
[[email protected] 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 安装应用程序。

[[email protected] yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.backup  //备份原有配置文件
[[email protected] 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
[[email protected] yum.repos.d]# 
[[email protected] yum.repos.d]# 
[[email protected] 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 //保存后退出

[[email protected] yum.repos.d]# yum clean all
已加载插件:fastestmirror
Cleaning repos: base extras updates
清理一切
Cleaning up list of fastest mirrors

[[email protected] 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文件中即可。

[[email protected] ~]# cp /mnt/ /opt/
cp: 略过目录"/mnt/"

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


 1、下载网络上yum源中的rpm文件到本地目录中;下载完成后通过crt自带的文件传输功能上传到linux对应的目录中;具体不在这里示范;

[[email protected] ~]# mkdir mirrors
[[email protected] ~]# cd mirrors/
[[email protected] mirrors]# mkdir base
[[email protected] mirrors]# ls
base

 

安装yum-utils工具后,可以提供reposync命令。

[[email protected] ~]# 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.
[[email protected] ~]# 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                                                                                         

完毕!

 

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

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

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

Linux下设置目录网络共享

服务器端配置:

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

所有主机:*

 


以上是关于linux中配置yum源的主要内容,如果未能解决你的问题,请参考以下文章

Linux中升级更新命令yum upgrade和yum update的区别

linux 下yum软件库配置文件详解!.repo

linux 中 配置自己的yum仓库 里面有一步是vi模式下编辑自己的XXXX.repo文件

linux中使用yum配置linux环境

Linux 7 中Yum 配置 说明

ubuntu16.04 yum报错:There are no enabled repos. Run “yum repolist all“ to see the repos you have.(代码片段