CentOS配置:自定义源【yum】
accttodo 12/31/2023 运维操作系统Linux
目录
参考:
# CentOS配置:自定义源【yum】
# 环境依赖
软件/系统 | 版本 | 包名 | 备注 |
---|---|---|---|
Linux | CentOS 7.x |
# 默认安装源配置文件
/etc/yum.repos.d/
目录下的CentOS
仓库配置文件信息:
文件名 | 描述 |
---|---|
CentOS-Base.repo | 主要仓库配置文件,包含基础软件仓库的URL和配置信息 |
CentOS-CR.repo | 可能包含连续发布仓库的配置信息,提供最新软件包更新 |
CentOS-Debuginfo.repo | 调试信息仓库配置,提供软件包的调试符号文件 |
CentOS-fasttrack.repo | 可能配置快速跟踪仓库,包含即将进入下一个版本的软件包更新 |
CentOS-Media.repo | 用于从本地媒体安装软件包的仓库配置文件 |
CentOS-Sources.repo | 包含软件包源代码仓库的配置信息 |
CentOS-Vault.repo | 包含旧版本软件包的存档 |
CentOS-x86_64-kernel.repo | 专门用于x86_64架构CentOS系统的内核更新仓库配置 |
# 文件的配置解释
# 仓库的名称,用于在包管理器中识别仓库
name=
# 仓库的基础URL,用于下载软件包和元数据
baseurl=
# 启用了GPG(GNU Privacy Guard)签名检查,以确保来自可信的源,并且没有在传输过程中被篡改
gpgcheck=1
# 指定了用于验证仓库中软件包签名的GPG公钥的位置
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# 控制仓库是否启用。0表示仓库当前被禁用,1表示启用这个仓库
enabled=0
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 备份默认安装源
ll -a /etc/yum.repos.d
# 创建备份文件夹
mkdir /etc/yum.repos.d/bak20240723
ll -a /etc/yum.repos.d
# 备份默认安装源
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak20240723/
ll -a /etc/yum.repos.d/bak20240723
ll -a /etc/yum.repos.d
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 通过镜像配置本地源
# 挂载本地镜像
本地镜像路径:/data/repo/iso/CentOS-7-x86_64-Everything-2009.iso
# 创建文件夹
mkdir /media/CentOS7.9
ll -a /media
# 挂载镜像
mount -ro loop -t iso9660 /data/repo/iso/CentOS-7-x86_64-Everything-2009.iso /media/CentOS7.9/
ll -a /media/CentOS7.9
1
2
3
4
5
6
2
3
4
5
6
重要:配置在系统启动时自动挂载
# 备份
cp /etc/fstab /etc/fstab.bak20240723
ll -a /etc |grep fstab
# 写入
cat >> /etc/fstab << EOF
# beg:20240723
/data/repo/iso/CentOS-7-x86_64-Everything-2009.iso /media/CentOS7.9 iso9660 loop,ro 0 0
# end.
EOF
# 查看
cat /etc/fstab
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 自定义镜像源
# 创建本地repo文件
vi /etc/yum.repos.d/Def-CentOS-Media.repo
1
2
2
# beg:20240723
[media-def]
name=Def - CentOS-$releasever - Media
baseurl=file:///media/CentOS7.9/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# end.
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 清除缓存并新建缓存
yum clean all
yum makecache
# 查看源列表
yum repolist
1
2
3
4
5
2
3
4
5
# 完全配置自定义本地源
# 创建文件夹
mkdir -p /data/repo/epel/Packages
ll -a /data/repo/epel
1
2
3
2
3
# 创建本地源文件
vi /etc/yum.repos.d/Def-CentOS-Epel.repo
1
2
2
# beg:20240723
[epel-def]
name=Def - CentOS-$releasever - epel
baseurl=file:///data/repo/epel/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# end.
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 安装createrepo
yum install createrepo
1
2
2
# 创建源索引并更新缓存
createrepo /data/repo/epel
ll -a /data/repo/epel
1
2
3
2
3
# 清除缓存并新建缓存
yum clean all
yum makecache
# 查看源列表
yum repolist
1
2
3
4
5
2
3
4
5
# 通过国内源更换默认源
开源镜像站
阿里云开源镜像站:https://mirrors.aliyun.com/
网易开源镜像站:https://mirrors.163.com/
中科大开源镜像站:https://mirrors.ustc.edu.cn/
清华开源镜像站:https://mirrors.tuna.tsinghua.edu.cn/
下面是一个表格,列出了几种镜像的定义和作用:
镜像名称 | 定义 |
---|---|
CentOS | CentOS 是一个开源的、社区驱动的、基于 Red Hat Enterprise Linux(RHEL)源代码构建的操作系统。CentOS 镜像包含了 CentOS 操作系统的完整安装文件,可用于在虚拟机、云环境或物理机上安装 CentOS。 |
EPEL | EPEL(Extra Packages for Enterprise Linux)是一个由 Fedora 社区提供的,为 RHEL 及其衍生版本(如 CentOS)提供额外软件包的仓库。EPEL 镜像包含了这些额外软件包的安装文件。 |
Docker-ce | Docker-ce(Community Edition)是 Docker 的开源版本,用于自动化应用程序的部署、扩展和管理。Docker-ce 镜像是一个轻量级的、可执行的独立软件包,包含了运行特定应用程序所需的一切:代码、运行时、系统工具、系统库和设置。 |
Kubernetes | Kubernetes 是一个开源的、容器编排系统,用于自动化部署、扩展和管理容器化应用程序。Kubernetes 镜像通常指的是包含 Kubernetes 组件(如 kubelet、kubectl、kube-apiserver 等)的 Docker 镜像,或者是包含 Kubernetes 集群所需的其他组件的镜像。 |
Ceph | Ceph 是一个开源的、分布式存储系统,提供了高性能、可靠性和可扩展性。Ceph 镜像包含了 Ceph 存储系统的安装文件和必要的组件,可用于在虚拟机、云环境或物理机上部署 Ceph。 |
SCLo-scl | SCLo-scl(Software Collections Library - Scientific Linux)是 Scientific Linux 的一个软件集合库,提供了较新版本的编译器和运行时环境,以及一些其他软件包。SCLo-scl 镜像可能包含了这些软件包的安装文件。 |
请注意,上述定义和作用是基于一般性的描述,并且可能会随着软件版本的更新和变化而有所调整。在实际使用中,建议查阅相关软件的官方文档以获取最准确的信息。
以阿里为示例如下:
# Base 镜像
sudo wget -O /etc/yum.repos.d/NET-CentOS-Base-Ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo wget -O /etc/yum.repos.d/NET-CentOS-Base-Ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# Epel 镜像
sudo wget -O /etc/yum.repos.d/NET-CentOS-Epel-Ali.repo http://mirrors.aliyun.com/repo/epel-7.repo
# Docker-ce镜像
sudo wget -O /etc/yum.repos.d/NET-CentOS-Docker-ce-Ali.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1
2
3
4
5
6
7
2
3
4
5
6
7
# Kubernetes镜像
sudo vi /etc/yum.repos.d/NET-CentOS-Kubernetes-Ali.repo
1
2
2
# beg:20240723
[k8s]
name=Kubernetes - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
# end.
1
2
3
4
5
6
7
2
3
4
5
6
7
# Ceph镜像
sudo vi /etc/yum.repos.d/NET-CentOS-Ceph-rpm-Ali.repo
1
2
2
# beg:20240723
[ceph-rpm-15.2.17]
name=Ceph-rpm-15.2.17 - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/ceph/rpm-15.2.17/el7/x86_64/
enabled=1
gpgcheck=0
# end.
# beg:20240723
[ceph-rpm-15.2.17-noarch]
name=Ceph-rpm-15.2.17-noarch - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/ceph/rpm-15.2.17/el7/noarch/
enabled=1
gpgcheck=0
# end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# SCLo-scl镜像
sudo vi /etc/yum.repos.d/NET-CentOS-SCLo-scl-Ali.repo
1
2
2
# beg:20240723
[sclo-scl]
name=CentOS - SCLo-scl - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/sclo/x86_64/sclo/
enabled=1
gpgcheck=0
# end.
# beg:20240723
[sclo-scl-rh]
name=CentOS - SCLo-scl-rh - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/sclo/x86_64/rh
enabled=1
gpgcheck=0
# end.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 清除缓存并新建缓存
yum clean all
yum makecache
# 查看源列表
yum repolist
1
2
3
4
5
2
3
4
5
# 内网共享源配置(Nginx)
# Nginx安装
创建软链接
#创建目录
mkdir -p /usr/local/nginx/html/repo
# 创建软链接,将挂载的`/media/CentOS7.9`链接到Nginx的`html/repo/CentOS7.9`
ln -s /media/CentOS7.9 /usr/local/nginx/html/repo/CentOS7.9
# 创建软链接,将挂载的`/data/repo/epel`链接到Nginx的`html/repo/Epel`
ln -s /data/repo/epel /usr/local/nginx/html/repo/Epel
1
2
3
4
5
6
2
3
4
5
6
创建代理访问配置
# 创建代理访问配置
vi /usr/local/nginx/conf/conf.d/repo.conf
1
2
2
client_max_body_size 2048M;
server {
listen 55555;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/repo;
index index.html index.htm;
# 开启目录列表功能
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 测试配置文件语法是否正确
/usr/local/nginx/sbin/nginx -t
# 重新加载配置
systemctl reload nginx
1
2
3
4
2
3
4
防火墙放行55555端口
# 查看默认区域
firewall-cmd --get-default-zone
# 查看当前活动区域
firewall-cmd --get-active-zones
# 查看指定区域的放行端口
firewall-cmd --zone=zone_name --list-ports
# 开放指定区域的55555端口
firewall-cmd --zone=zone_name --add-port=55555/tcp --permanent
# 开发指定区域的55555端口
firewall-cmd --zone=zone_name --add-port=55555/udp --permanent
# 重新加载防火墙配置
firewall-cmd --reload
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
访问地址:http://IP:55555/CentOS7.9/
# 目标源配置
ll -a /etc/yum.repos.d
# 创建备份文件夹
sudo mkdir /etc/yum.repos.d/bak20240723
ll -a /etc/yum.repos.d
# 备份默认安装源
sudo mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak20240723/
ll -a /etc/yum.repos.d/bak20240723
ll -a /etc/yum.repos.d
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 新建新的源配置
sudo vi /etc/yum.repos.d/Def-CentOS-Base.repo
1
2
2
[media-def]
name=Def - CentOS-$releasever-Media - 远程ip:55555
baseurl=http://远程ip:55555/CentOS7.9
enabled=1
gpgcheck=0
[epel-def]
name=Def - CentOS-$releasever-Epel - 远程ip:55555
baseurl=http://远程ip:55555/Epel
enabled=1
gpgcheck=0
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 清除缓存并新建缓存
yum clean all
yum makecache
# 查看源列表
yum repolist
1
2
3
4
5
2
3
4
5