【分享】centos7更换国内源
Centos7配置yum国内源
基于 RHEL 的八个 YUM/DNF 第三方存储库
https://www.51cto.com/article/706719.html
# 安装epel源和ELRepo源(依赖epel源)
yum install -y epel-release elrepo-release
# 安装SCL源
## centos-release-scl centos-release-scl-rh是SCL源
## scl-utils scl-utils-build是SCL-utils工具
yum install -y centos-release-scl centos-release-scl-rh scl-utils scl-utils-build
# 安装IUS源(依赖依赖epel源)
## 导入IUS源gpg key
rpm --import https://repo.ius.io/RPM-GPG-KEY-IUS-7
## 安装IUS源
yum install -y https://repo.ius.io/ius-release-el7.rpm
# 安装REMi源
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# 查看repolist
yum repolist
配置基础源
该源包含base
,updates
,epel
,会自动匹配Centos系统版本
参考: https://mirrors.ustc.edu.cn/help/centos.html
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-KaTeX parse error: Expected 'EOF', got '#' at position 57: …token comment">#̲mirrorlist=http…releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲amp;repo=update…infra
baseurl=https://mirrors.ustc.edu.cn/centos/
r
e
l
e
a
s
e
v
e
r
<
/
s
p
a
n
>
/
u
p
d
a
t
e
s
/
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
v
a
r
i
a
b
l
e
"
>
releasever</span>/updates/<span class="token variable">
releasever</span>/updates/<spanclass="tokenvariable">basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-KaTeX parse error: Expected 'EOF', got '#' at position 56: …token comment">#̲mirrorlist=http…releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲amp;repo=extras…infra
baseurl=https://mirrors.ustc.edu.cn/centos/
r
e
l
e
a
s
e
v
e
r
<
/
s
p
a
n
>
/
e
x
t
r
a
s
/
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
v
a
r
i
a
b
l
e
"
>
releasever</span>/extras/<span class="token variable">
releasever</span>/extras/<spanclass="tokenvariable">basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-KaTeX parse error: Expected 'EOF', got '#' at position 54: …token comment">#̲mirrorlist=http…releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲amp;repo=centos…infra
baseurl=https://mirrors.ustc.edu.cn/centos/
r
e
l
e
a
s
e
v
e
r
<
/
s
p
a
n
>
/
c
e
n
t
o
s
p
l
u
s
/
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
v
a
r
i
a
b
l
e
"
>
releasever</span>/centosplus/<span class="token variable">
releasever</span>/centosplus/<spanclass="tokenvariable">basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
配置base源
参考: https://mirrors.bfsu.edu.cn/help/centos/
参考 https://developer.aliyun.com/mirror/centos
# 备份Base.repo
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
下载阿里云的base源
# 下载阿里云的base源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 如果没有wget程序则使用curl下载
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
下载163的base源
# 下载163的base源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
# 如果没有wget程序则使用curl下载
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
刷新源
# 快速生成缓存
sudo yum makecache fast
# 生成完整缓存
sudo yum clean all && sudo yum makecache
查看源是否添加成功
# 查看yum源是否添加成功
sudo yum repolist
安装epel源
Extra Packages for Enterprise Linux
缩写为epel
;
epel
源中有许多高质量的扩展软件,例如: htop
,ncdu
,nginx
,vnstat
# 安装epel源
yum install epel-release -y
# 手动安装
rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
# 备份epel.repo
mv /etc/yum.repos.d/epel.repo epel.repo{
,.bak}
# 直接下载epel.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 或
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 有时候aliyun会抽风连不上,可以换用其他国内源
curl -o /etc/yum.repos.d/epel.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
替换epel.repo文件
适用于RHEL7
手动创建epel.repo
,将下方配置3选1
粘贴到epel.repo
# 手动编辑epel.repo文件
vim /etc/yum.repos.d/epel.repo
配置内容如下
# 中科大的epel源---建议
[epel-USTC]
name=epel-USTC--CentOS-$releasever
baseurl=https://mirrors.ustc.edu.cn/epel/$releasever/$basearch/
enabled=1
gpgcheck=0
# 华为云的epel源
[epel-huaweicloud]
name=epel-huaweicloud-CentOS-
r
e
l
e
a
s
e
v
e
r
<
/
s
p
a
n
>
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
a
s
s
i
g
n
−
l
e
f
t
v
a
r
i
a
b
l
e
"
>
b
a
s
e
u
r
l
<
/
s
p
a
n
>
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
o
p
e
r
a
t
o
r
"
>
=
<
/
s
p
a
n
>
h
t
t
p
s
:
/
/
m
i
r
r
o
r
s
.
h
u
a
w
e
i
c
l
o
u
d
.
c
o
m
/
e
p
e
l
/
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
v
a
r
i
a
b
l
e
"
>
releasever</span> <span class="token assign-left variable">baseurl</span><span class="token operator">=</span>https://mirrors.huaweicloud.com/epel/<span class="token variable">
releasever</span><spanclass="tokenassign−leftvariable">baseurl</span><spanclass="tokenoperator">=</span>https://mirrors.huaweicloud.com/epel/<spanclass="tokenvariable">releasever/$basearch/
gpgcheck=0
# 清华的epel源
[epel-tsinghua]
name=Extra Packages-tsinghua for Enterprise Linux
r
e
l
e
a
s
e
v
e
r
<
/
s
p
a
n
>
−
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
v
a
r
i
a
b
l
e
"
>
releasever</span> - <span class="token variable">
releasever</span>−<spanclass="tokenvariable">basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/
r
e
l
e
a
s
e
v
e
r
<
/
s
p
a
n
>
/
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
v
a
r
i
a
b
l
e
"
>
releasever</span>/<span class="token variable">
releasever</span>/<spanclass="tokenvariable">basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
保存
# 保存
:wq
刷新源
# 快速生成缓存
sudo yum makecache fast
# 生成完整缓存
sudo yum clean all && sudo yum makecache
查看源是否添加成功
# 查看yum源是否添加成功
sudo yum repolist
从epel源中安装软件
# 安装htop
yum install -y htop
安装ELRepo源
用来更新内核,Centos7的内核默认只到3.10,这个源可以更新到最新的内核.例如5.4
https://blog.csdn.net/omaidb/article/details/126462414
安装4.4以上版本内核
https://blog.csdn.net/omaidb/article/details/121856924
安装SCL源
https://blog.csdn.net/omaidb/article/details/126462159
安装IUS源
为RHEL和CentOS提供高质量、最新版的软件,如PHP, Python, MySQL等。
参考https://blog.csdn.net/omaidb/article/details/126462236
安装REMI源
Remi
源中的软件几乎都是最新稳定版,这些都是Linux骨灰级的玩家编译好放进源里的.
Remi
下载地址:http://rpms.famillecollet.com/
参考: https://wsgzao.github.io/post/epel/
# Centos7安装remi源
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# Centos7安装REMI源(国内安装)
yum install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
# rhel8安装remi源
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-8.rpm
安装raven源
源项目地址:https://pkgs.dyn.su/
参考:https://sysadmins.ws/viewtopic.php?f=96&t=22598&sid=b17673c41ea6e1a8f6ccb9b39bbf967c
# rhel8安装raven源
dnf localinstall -y https://pkgs.dyn.su/el8/base/x86_64/raven-release.el8.noarch.rpm
RHEL7配置raven源
[raven]
name=Raven's Packages for EL
baseurl=http://pkgs.dyn.su/$releasever/base/$basearch/
enabled=1
gpgcheck=0
[raven-httpd]
name=Raven’s httpd build for EL
baseurl=http://pkgs.dyn.su/
r
e
l
e
a
s
e
v
e
r
<
/
s
p
a
n
>
/
h
t
t
p
d
/
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
v
a
r
i
a
b
l
e
"
>
releasever</span>/httpd/<span class="token variable">
releasever</span>/httpd/<spanclass="tokenvariable">basearch/
enabled=0
gpgcheck=0
[raven-extras]
name=Raven's Extra Packages for EL
baseurl=http://pkgs.dyn.su/
r
e
l
e
a
s
e
v
e
r
/
e
x
t
r
a
s
/
releasever/extras/
releasever/extras/basearch/
enabled=0
gpgcheck=0
[raven-testing]
name=Raven’s Unstsble Packages for EL
baseurl=http://pkgs.dyn.su/
r
e
l
e
a
s
e
v
e
r
<
/
s
p
a
n
>
/
t
e
s
t
i
n
g
/
<
s
p
a
n
c
l
a
s
s
=
"
t
o
k
e
n
v
a
r
i
a
b
l
e
"
>
releasever</span>/testing/<span class="token variable">
releasever</span>/testing/<spanclass="tokenvariable">basearch/
enabled=0
gpgcheck=0
其他国内常用源
参考: https://wiki.centos.org/zh/AdditionalResources/Repositories
启用禁用的源
# 启用PowerTools源
sudo yum config-manager –set-enabled PowerTools
使用指定的yum仓库安装包
# 从指定的yum仓库中安装包
yum --enablerepo=repo名 install 包名
# 从所有yum仓库中安装包
yum --enablerepo=* install 包名
# 禁止从指定的yum仓库中安装包
yum --disablerepo=repo名 install 包名
文章原文: https://blog.csdn.net/omaidb/article/details/120393850