Linux 配置源(yum)

一 :使用背景

随着公司网络安全意识的增加,会将服务器“断网”,既断开服务器访问外网的权限,无法访问外网资源,这就使我们在按照应用,如 docker 、nginx 、redis 等无法按照网上教程直接拉取相关资源安装。

二 : 解决方法

1、手动上传资源

这种方式适用于VPN1安全性要求极高的网络环境
优点 :方便,快捷,不用考虑网络限制,直接上传安装即可
缺点 :资源不好下载或下载慢,对版本要求高的用户无法快速找到对应版本号资源

2、更换yum repo源

默认使用官方的,下载慢,推荐使用阿里或ustc
配置文件在 /etc/yum.repos.d 目录下查看

步骤一 :修改DNS
【CentOS6/7/8】
编辑配置文件 vim /etc/resolv.conf

nameserver 10.12.107.150
nameserver 10.12.107.151

为防止服务器重启时 NetworkManager 服务将 dns 重置,可以通过 chattr +i /etc/resolv.conf 命令将文件锁定

【Ubuntu14/16/18/20】
编辑配置文件 vim /etc/resolvconf/resolv.conf.d/base

nameserver 10.12.107.150
nameserver 10.12.107.151

之后执行:resolvconf -u 使配置生效

chattr +i /etc/resolv.conf 锁定文件
chattr -i /etc/resolv.conf 解除锁定

步骤二 :备份
【CentOS6/7/8】
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup


【Ubuntu14/16/18/20】
# mv /etc/apt/sources.list /etc/apt/sources.list.backup
步骤三 :下载配置文件
注意:下载配置文件之后,CentOS系统需要执行 yum makecache 生成缓存,Ubuntu系统需要执行 apt-get update 更新源,才能使用

【CentOS6】
# curl -ko /etc/yum.repos.d/CentOS-6.repo https://repos.onecc.me/download/CentOS-6.repo

【CentOS7】
# curl -ko /etc/yum.repos.d/CentOS-7.repo https://repos.onecc.me/download/CentOS-7.repo

【CentOS8】
# curl -ko /etc/yum.repos.d/CentOS-8.repo https://repos.onecc.me/download/CentOS-8.repo

【Ubunt14】
# curl -ko /etc/apt/sources.list https://repos.onecc.me/download/Ubuntu14.repo

【Ubunt16】
# curl -ko /etc/apt/sources.list https://repos.onecc.me/download/Ubuntu16.repo

【Ubuntu18】
# curl -ko /etc/apt/sources.list https://repos.onecc.me/download/Ubuntu18.repo

【Ubuntu20】
# curl -ko /etc/apt/sources.list https://repos.onecc.me/download/Ubuntu20.repo
步骤四 :配置其他仓库
【Maven】
<mirror>
    <id>aliyunmaven</id>
    <mirrorOf>*</mirrorOf>
    <name>阿里云公共仓库</name>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>


【NPM】
如需配置阿里源也可以安装仓库管理软件 nrm,通过 nrm 指定 taobao 仓库

# npm install nrm --registry=https://registry.npm.taobao.org
# nrm ls
# nrm use taobao


【Pypi】
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

第四步一般不使用

三 :配置源文件解析

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.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/
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/
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/
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/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

enabled=0 : 开启yum (1 : 关闭yum)
gpgcheck=1 : 进行gpg校验 (0 : 不校验)

四 :示例

docker 的安装

# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
sudo service docker start
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值