内网使用yum,更换网络yum源

repo文件解读

在CentOS中,"repo"文件通常指的是yum软件包管理器使用的仓库配置文件。这些文件通常存储在/etc/yum.repos.d/目录下,每个文件对应一个软件仓库。这些repo文件是以.repo为扩展名的文本文件,可以使用任何文本编辑器打开并编辑。

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#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-7

#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-7
  • [base]、[updates] 和 [extras]:这些是仓库的名称。它们用于在yum命令中标识仓库。例如,要从base仓库中安装软件包,可以使用yum install packageName命令。
  • name:这是对仓库的描述性名称。
  • mirrorlist:这是一个指向CentOS镜像列表的URL。当你使用这个URL时,yum会从列表中选择一个最快的镜像来下载软件包。
  • baseurl:如果你不想使用mirrorlist,你可以使用这个字段直接指定镜像的URL。通常情况下,你会在注释掉的mirrorlist和未注释掉的baseurl之间进行选择。
  • gpgcheck:这个字段确定yum在安装软件包时是否要检查软件包的GPG签名。如果设置为1,yum将检查软件包的签名。如果设置为0,yum不会检查签名。通常情况下,建议将此选项保持为1,以确保从仓库中安装的软件包是经过验证的。
  • gpgkey:这是用于验证仓库中软件包的GPG密钥的路径。在这个例子中,它指向了CentOS 7的GPG密钥文件。
  • enable=1:表示仓库已启用。这意味着YUM会在搜索软件包和执行操作时考虑该仓库中的软件包。如果您想从该仓库中安装、更新或卸载软件包,仓库必须处于启用状态。
  • enable=0:表示仓库已禁用。这意味着YUM将忽略该仓库中的软件包,不会搜索、安装、更新或卸载与该仓库相关的软件包

比如centos5 repo停止维护了,需要更改repo的enable文件为0,否则可能出现无法使用yum情况。
以及如下报错 M2Crypto.SSL.SSLError: sslv3 alert handshake failure

  File "/usr/lib64/python2.4/site-packages/M2Crypto/httpslib.py", line 47, in connect
    self.sock.connect((self.host, self.port))
  File "/usr/lib64/python2.4/site-packages/M2Crypto/SSL/Connection.py", line 174, in connect
    ret = self.connect_ssl()
  File "/usr/lib64/python2.4/site-packages/M2Crypto/SSL/Connection.py", line 167, in connect_ssl
    return m2.ssl_connect(self.ssl, self._timeout)
M2Crypto.SSL.SSLError: sslv3 alert handshake failure

应添加或者变更 enabled=0,这只是可以使yum可用,上传rpm包至服务器进行yum安装,直接使用yum还是要找最新的repo源

[base]
name=CentOS-$releasever - Base - 163.com
baseurl=https://vault.centos.org/5.11/os/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
enabled=0

内网使用yum

使用前提,我们DC网络和Azure某服务器有专线,可以从DC连接到Azure服务器,且Azure服务器可以访问外网

在Azure服务器上进行配置

yum install -y nginx  #安装nginx做转发

更改配置文件

vim /etc/nginx/nginx.conf
listen   8081 #端口默认80要被墙,更改成不常用的8081

location /zabbix {
            proxy_pass https://repo.zabbix.com;  #追加这一行,你需要访问的源地址
        }
location /mysql {
            proxy_pass http://repo.mysql.com/;   #追加这一行,你需要访问的源地址,“repo.mysql.com/” 这个是绝对路径,不加/容易导致Not Found
        }

location / {
        }

在这里插入图片描述

systemctl restart nginx #重启nginx

在内网DC服务器上操作

配置repo,下面的AzureIP是我的AzureIP,该成自己的,baseurl根据你系统版本,自己改下,这个只是zabbix的源,你可以使用其他的源,都大同小异的

vim /etc/yum.repo.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://AzureIP:8081/zabbix/4.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://AzureIP:8081/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
vim /etc/yum.repo.d/mysql.repo
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://AzureIP:8081/mysql/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://AzureIP:8081/mysql/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://AzureIP:8081/mysql/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://AzureIP:8081/mysql/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-8.0-community]
name=MySQL Cluster 8.0 Community
baseurl=http://AzureIP:8081/mysql/yum/mysql-cluster-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

拷贝Azure上的/etc/pki/rpm-gpg/ 目录下的
RPM-GPG-KEY-ZABBIX和RPM-GPG-KEY-ZABBIX-A14FE591还有RPM-GPG-KEY-mysql放到DC里 然后就可以使用YUM了

yum repolist --noplugins #--noplugins是不加载插件

在这里插入图片描述

更换网络yum源

使用阿里云镜像站的源
https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.60bc1b11weddDS
在这里插入图片描述

备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

更换源

centos8

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

centos6

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo

centos7 直接复制以下文件至/etc/yum.repos.d/CentOS-Base.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

运行 yum makecache 生成缓存

yum makecache 

YUM故障排错

yum list all 有对应包,但是无法安装。大概率是yum本身问题,对yum卸载重装

卸载

rpm -aq|grep yum|xargs rpm -e --nodeps

下载

wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm

重装

rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh yum-3.4.3-168.el7.centos.noarch.rpm --force --nodeps yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

重新安装对应安装包

yum 配置文件未指向默认yum仓库,无法更新

在这里插入图片描述

vim  /etc/yum.conf
reposdir=/etc/yum.repos.yonyou

可以注释该行 #reposdir=/etc/yum.repos.yonyou
再使用yum可成功执行

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值