怎么配置yum服务器网络源与本地源

怎么配置yum服务器网络源与本地源,第1张

Centos--yum配置本地数据源准备工具:centos安装镜像文件1.挂载镜像文件,我这里使用虚拟机来设置,设备状态的已连接勾上2.复制镜像文件到服务器目录,我这放在/opt目录下3.复制完成后,进入yum的配置目录,编辑yum的配置文件#cd /etc/yum.repos.d/#vi CentOS-Media.repo更改baseurl的内容,使其指向本地的镜像文件目录:baseurl=file:///opt/soft/CentOS_6.3_Final/ --本地光盘挂载目录gpgcheck=0 --检查GPG-KEY,0为不检查,1为检查enabled=1 --启用yum源,0为不启用,1为启用4.将CentOS-Debuginfo.repo,CentOS-Base.repo等其他配置改名或者删掉,就可以绕过网络进行本地源安装#mv CentOS-Base.repo CentOS-Base.repo.backup#mv CentOS-Debuginfo.repoCentOS-Debuginfo.repo.backup5.执行yum更新命令#yum clean all#yum update出现以下画面表示配置成功6.安装mysql示例7.yum命令详解安装yum <选项><软件包软件名组名>install package 安装指定的安装包packagelocalinstall package 本地安装软件包groupinstall package 组安装升级yum <选项><软件包软件名组名>update 更新全部可以更新的软件包update package 更新指定程序包packagecheck-update检查系统中可以被升级的软件包。groupupdate group1 升级组group1 里面的软件包。卸载 (强烈不建议使用yum卸载包)卸载包的时候也会把其他关联包也卸载掉,严重导致系统崩溃yum <选项><软件包软件名组名>remove package1 : 卸载软件包package1 erase package1 : 卸载软件包package1 groupremove group1 :卸载组group1里面所包括的软件包。查询yum <选项><软件包软件名组名>info <package>:显示安装包信息list :显示所有已经安装和仓库中可以安装的程序包list<package>:显示指定软件包安装情况grouplist :显示仓库中有哪些组deplist<package1>:查看程序package1依赖情况groupinfo <group1>:显示程序组group1信息search <keyword>:查找软件包

修改yum源配置文件,删除yum源,又重新在另一台主机上复制了无问题的yum配置文件,导致yum源无法使用。

yum报错如下

[root@java152 ~]# yum makecache

已加载插件:fastestmirror

Loading mirror speeds from cached hostfile

* base: mirrors.tencentyun.com

* extras: mirrors.tencentyun.com

* updates: mirrors.tencentyun.com

http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found

#####报错信息是%24releasever 和404,意思就是无法解析腾讯云的$releasever变量。

To address this issue please refer to the below wiki article

https://wiki.centos.org/yum-errors

If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

base | 1.0 kB 00:00:00

http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for base: Damaged repomd.xml file

正在尝试其它镜像。

http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30000 milliseconds')

正在尝试其它镜像。

http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

正在尝试其它镜像。

http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

正在尝试其它镜像。

http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

正在尝试其它镜像。

http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

正在尝试其它镜像。

http://mirrors.tencentyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

正在尝试其它镜像。

One of the configured repositories failed (CentOS-$releasever - Base - mirrors.aliyun.com),

and yum doesn't have enough cached data to continue. At this point the only

safe thing yum can do is fail. There are a few ways to work "fix" this:

1. Contact the upstream for the repository and get them to fix the problem.

2. Reconfigure the baseurl/etc. for the repository, to point to a working

upstream. This is most often useful if you are using a newer

distribution release than is supported by the repository (and the

packages for the previous distribution release still work).

3. Run the command with the repository temporarily disabled

yum --disablerepo=base ...

4. Disable the repository permanently, so yum won't use it by default. Yum

will then just ignore the repository until you permanently enable it

again or use --enablerepo for temporary usage:

yum-config-manager --disable base

or

subscription-manager repos --disable=base

5. Configure the failing repository to be skipped, if it is unavailable.

Note that yum will try to contact the repo. when it runs most commands,

so will have to try and fail each time (and thus. yum will be be much

slower). If it is a very temporary problem though, this is often a nice

compromise:

yum-config-manager --save --setopt=base.skip_if_unavailable=true

failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.

http://mirrors.aliyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found

http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno -1] Error importing repomd.xml for base: Damaged repomd.xml file

http://mirrors.tencentyun.com/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30000 milliseconds')

http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')

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

47

48

49

50

51

52

53

54

55

56

57

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

47

48

49

50

51

52

53

54

55

56

57

1.查看DNS没有问题,且主机可以访问到外网。

在这里插入图片描述

2.重装yum服务,还是不能用。

yum-3.4.3-161.el7.centos.noarch.rpm

yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm

命令:rpm -ivh yum-3.4.3-161.el7.centos.noarch.rpm --nodeps --force //nodeps 强制安装force 避免依赖

命令:rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm --nodeps --force

命令:rpm -ivh yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm --nodeps --force

1

2

3

4

5

6

1

2

3

4

5

6

最终解决方法

上边一直提示 404 错误,然后我直接访问

http://mirrors.tencentyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml

发现这个地址打不开

将腾讯yum源仓库的$releasever变量都改为7

命令:vim /etc/yum.repos.d/Centos-Base.repo

vim /etc/yum.repos.d/Centos-Epel.repo

命令::%s/$releasever/7/g #文本编辑器中的替换命令

在这里插入图片描述

修改完之后执行

# yum makecache # OK

1

1

知识扩展:

问题分析一下

1、对比.repo文件和报错信息,可以发现$releasever变量没有被系统识别,在连接网络yum源的时候,变成了%24releasever。

2、查询资料得知,yum中的变量$releasever是由/etc/yum.conf中的distroverpkg定义的。centos-release为一个rpm包,所谓“distroverpkg=centos-release”的意思,其实是将 $releasever设置为centos-release 这个RPM包的版本号;打开yum的配置文件

vim /etc/yum.conf

在这里插入图片描述

通过rpm可以查询到改软件包并没有被安装:

在这里插入图片描述

解决思路

由于centos-release依赖关系比较复杂,约40个左右依赖包,我们可以修改yum源文件,把$releasever全部替换为7(上边已操作),修改以下爱两个配置文件。

# vim /etc/yum.repos.d/Centos-Base.repo # 修改腾讯内部yum源Base仓库

# vim /etc/yum.repos.d/Centos-Epel.repo# 修改腾讯内部yum源EPEL源仓库

1

2

1

2

在这里插入图片描述

此时yum可以正常使用,通过yum安装centos-release

命令:yum -y install centos-release

下载完centos-release源之后,再将base和epel源的7改回$releasever。yum makecache制作缓存yum即可恢复使用。

文章知识点与官方知识档案匹配

CS入门技能树Linux入门初识Linux

25431 人正在系统学习中


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/623370.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-07-16
下一篇2023-07-16

发表评论

登录后才能评论

评论列表(0条)

    保存