linux 搭建本地 yum 源

以下是基于阿里云的 CentOS Linux release 7.6.1810 源

首先把源改成阿里云的

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

首先查看启用的源

[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id           repo name                                            status
base/7/x86_64     CentOS-7 - Base - mirrors.aliyun.com                10,019
*epel/x86_64      Extra Packages for Enterprise Linux 7 - x86_64       13,343
extras/7/x86_64    CentOS-7 - Extras - mirrors.aliyun.com              435
updates/7/x86_64   CentOS-7 - Updates - mirrors.aliyun.com             2,500
repolist: 26,297

安装同步工具并同步(缺少其他依赖库自行安装即可)

yum install createrepo yum-utils
mkdir /mirror && cd /mirror
#开始同步,时间会比较长
reposync

同步完之后会有 base、epel、extras、updates 目录,大多数我们只要用到 base 即可

创建索引

#为每个创建索引,此时会出现 repodata 目录
createrepo base -o base
createrepo epel -o epel
createrepo extras -o extras
createrepo updates -o updates

#在当前目录更新
createrepo --update base
createrepo --update epel
createrepo --update extras
createrepo --update updates

此时 /mirror 目录即为 yum 源,然后配置 /etc/yum.repo.d/ 目录下的文件即可

[root@localhost yum.repos.d]# cat CentOS-Media.repo 
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-7.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[base]
name=CentOS-$releasever - base
baseurl=file:///home/mirror/base/
#        file:///media/cdrom/
#        file:///media/cdrecorder/
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - extras
baseurl=file:///home/mirror/extras/
#        file:///media/cdrom/
#        file:///media/cdrecorder/
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever - updates
baseurl=file:///home/mirror/updates/
#        file:///media/cdrom/
#        file:///media/cdrecorder/
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[epel]
name=CentOS-$releasever - epel
baseurl=file:///home/mirror/epel/
#        file:///media/cdrom/
#        file:///media/cdrecorder/
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

当然了,也可以把上面的源复制到u盘里,就可以在不同机器上来离线安装软件。


上一篇: linux 磁盘相关命令 du、df、lsblk、blkid
下一篇: linux 包管理 rpm、yum
作者邮箱: 203328517@qq.com