自制YUM仓库

YUM仓库配置文件

# 仓库名称
[base]
# 仓库描述
name=CentOS-$releasever - Base - mirrors.aliyun.com
# 仓库地址
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
# 检测签名机制(1:开启检测 0:关闭检测)
gpgcheck=1
# 签名机制秘钥地址
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

YUM仓库类型

# 1.远程仓库
http:// 端口:80
https:// 端口:443
ftp:// 端口:21
# 2.本地仓库
file:// 没有端口(本地协议)
## 协议:http:// https:// ftp:// file://
http:// 端口:80
https:// 端口:443
ftp:// 端口:21
file:// 没有端口(本地协议)

本地YUM仓库(file://)

# 先决条件
1)创建仓库的命令
- createrepo
2)还要有rpm包
- 网站获取
- 镜像获取
- yum源获取
3)yum源的配置文件

# 1.安装创建仓库的命令
[root@localhost <sub>]# yum install -y createrepo

# 2.通过镜像,获取rpm包
## 1)挂载镜像
[root@localhost </sub>]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

## 2)创建一个仓库目录
[root@localhost <sub>]# mkdir /local_yum_repo

## 3)拷贝所有rpm包到仓库目录中
[root@localhost </sub>]# cp /mnt/Packages/*.rpm /local_yum_repo/

## 4)先把目录变成仓库
[root@localhost <sub>]# createrepo /local_yum_repo/
Spawning worker 0 with 4021 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

## 5)检查是否把目录变成了仓库
[root@localhost </sub>]# ll -d /local_yum_repo/repodata/
drwxr-xr-x 2 root root 4096 Apr 25 10:10 /local_yum_repo/repodata/

## 6)压缩其他yum源
[root@localhost <sub>]# gzip -r /etc/yum.repos.d/

## 7)手写yum源配置文件(必须以repo结尾)
[root@localhost </sub>]# vim /etc/yum.repos.d/local.repo
# 仓库名称
[wjh_local]
# 仓库描述
name=Local Repository By wjh
# 仓库的地址
baseurl=file:///local_yum_repo
# 关闭签名检测机制
gpgcheck=0
# 开启仓库
enabled=1

## 8)使用yum源
[root@localhost ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
wjh_local
| 2.9 kB 00:00:00
wjh_local/primary_db
| 3.1 MB 00:00:00
repo id repo name status
wjh_local Local Repository By wjh enabled: 4,02

远程yum仓库

# 先决条件
1)创建仓库的命令
- createrepo
2)还要有rpm包
- 网站获取
- 镜像获取
- yum源获取
3)yum源的配置文件

# 1.安装创建仓库的命令
[root@localhost <sub>]# yum install -y createrepo

# 2.通过镜像,获取rpm包
## 1)挂载镜像
[root@localhost </sub>]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

## 2)安装vsftpd服务
[root@localhost <sub>]# yum install -y vsftpd

## 3)启动服务
[root@localhost </sub>]# systemctl start vsftpd

## 4)检查端口
如果没有netstat 命令,则需要安装
[root@localhost <sub>]# yum install -y net-tools
[root@localhost </sub>]# netstat -lntup
[root@localhost <sub>]# netstat -lntup|grep vsftpd
tcp6 0 0 :::21 :::* LISTEN 7763/vsftpd

## 5)打开浏览器访问:ftp://10.0.0.185/
ftp://IP

## 6)关闭防火墙和selinux
[root@localhost </sub>]# systemctl stop firewalld
[root@localhost <sub>]# setenforce 0

## 7)创建仓库目录
[root@localhost </sub>]# mkdir /var/ftp/pub/{base,epel}
[root@localhost <sub>]# ll /var/ftp/pub/
drwxr-xr-x 2 root root 6 Apr 25 11:13 base
drwxr-xr-x 2 root root 6 Apr 25 11:13 epel

## 8)拷贝rpm包到base目录下
[root@localhost </sub>]# cp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm /mnt/Packages/net-tools-2.0-0.24.20131004git.el7.x86_64.rpm /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm /var/ftp/pub/base/
[root@localhost <sub>]# ll /var/ftp/pub/base/
total 616
-rw-r--r--. 1 root root 313032 Apr 25 17:50 net-tools-2.0-0.24.20131004git.el7.x86_64.rpm
-rw-r--r--. 1 root root 47508 Apr 25 17:50 tree-1.6.0-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 266160 Apr 25 17:50 zip-3.0-11.el7.x86_64.rpm

## 9)下载rpm包到epel源
[root@localhost </sub>]# cd /var/ftp/pub/epel/
[root@localhost epel]# wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/n/nginx-1.20.1-9.el7.x86_64.rpm
[root@localhost epel]# ll
total 588
-rw-r--r--. 1 root root 601193 Oct 19 2021 nginx-1.20.1-9.el7.x86_64.rpm
[root@localhost epel]# wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/v/vim-go-1.8-3.el7.x86_64.rpm
[root@localhost epel]# ll
total 660
-rw-r--r--. 1 root root 601193 Oct 19 2021 nginx-1.20.1-9.el7.x86_64.rpm
-rw-r--r--. 1 root root 70428 Aug 11 2016 vim-go-1.8-3.el7.x86_64.rpm

#目录变成仓库
[root@localhost <sub>]# createrepo /var/ftp/pub/base
[root@localhost </sub>]# createrepo /var/ftp/pub/epel

## 10)在其他机器上手写repo配置文件
[root@localhost yum.repos.d]# vi local_epel.repo
# 仓库名称
[wjh_local_epel]

# 仓库描述
name=Local Repository By wjh

# 仓库的地址
baseurl=ftp://10.0.0.185/pub/epel/

# 关闭签名检测机制
gpgcheck=0

# 开启仓库
enabled=1

# 仓库名称
[wjh_local_base]

# 仓库描述
name=Local Repository By wjh

# 仓库的地址
baseurl=ftp://10.0.0.185/pub/base/

# 关闭签名检测机制
gpgcheck=0

# 开启仓库
enabled=1

## 11)检查yum仓库
[root@localhost yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
wjh_local_base | 2.9 kB 00:00:00
wjh_local_epel | 2.9 kB 00:00:00
(1/2): wjh_local_base/primary_db | 3.2 kB 00:00:00
(2/2): wjh_local_epel/primary_db | 3.7 kB 00:00:00
repo id repo name status wjh_local_base Local Repository By wjh enabled: 3 wjh_local_epel Local Repository By wjh enabled: 2 repolist: 5

## 12)使用yum安装
[root@localhost yum.repos.d]# yum install -y tree
..................................
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!


[root@localhost yum.repos.d]# yum install -y zip
..................................
Installed:
zip.x86_64 0:3.0-11.el7
Complete!