阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

分享一下自制yum仓库

32次阅读
没有评论

共计 5276 个字符,预计需要花费 14 分钟才能阅读完成。

导读 今天来给大家介绍一下 linux 制作 yum 仓库的方法

分享一下自制 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 ]# yum install -y createrepo

# 2. 通过镜像,获取 rpm 包
# 1)挂载镜像

[root@localhost]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

# 2)创建一个仓库目录

[root@localhost ]# mkdir /local_yum_repo

# 3)拷贝 rpm 包到仓库目录中

[root@localhost]# cp /mnt/Packages/*.rpm /local_yum_repo/

# 4)先把仓库变成目录

[root@localhost ]# createrepo /local_yum_repo/
Spawning worker 0 with 4070 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

# 5) 检查是否把目录变成了仓库

[root@localhost]# ll -d /local_yum_repo/
drwxr-xr-x. 3 root root 225280 Apr 25 17:28 /local_yum_repo/

# 6)压缩其他 yum 源

[root@localhost ]# gzip -r /etc/yum.repos.d/

# 7)手写 yum 源配置文件(必须以 repo 结尾)

# 仓库名
[zxw_local]

# 仓库描述
name=Local Pepository By zxw

# 仓库地址
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
repo id                                                                          repo name                                                                                       status
zxw_local                                                                        Local Pepository By zxw                                                                         enabled: 4,070
repolist: 4,070
远程 yum 仓库
# 1. 先决条件

1)创建仓库的命令

- createrepo

2)还要有 rpm 包

- 网站获取
 - 镜像获取
 - yum 源获取 

3)yum 源的配置文件
# 1. 安装创建仓库的命令

[root@localhost ]# yum install -y createrepo
# 2. 通过镜像,获取 rpm 包

## 1)挂载镜像

[root@localhost]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

## 2)安装安装 vsftpd 服务

[root@localhost ]# yum install -y vsftpd

## 3)启动服务

[root@localhost]# systemctl start vsftpd

## 4)检查端口
如果没有命令 net-tools 就安装一个

[root@localhost ]# yum install -y net-tools
[root@localhost ]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      941/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1107/master         
tcp6       0      0 :::21                   :::*                    LISTEN      11416/vsftpd        
tcp6       0      0 :::22                   :::*                    LISTEN      941/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1107/master         
[root@localhost ]# netstat -lntup|grep vsftpd
tcp6       0      0 :::21                   :::*                    LISTEN      11416/vsftpd   

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

ftp://ID

## 6)关闭防火墙

[root@localhost]# systemctl stop firewalld
[root@localhost ]# setenforce 0

## 7) 创建仓库目录

[root@localhost]# mkdir /var/ftp/pub/{base,epel}
[root@localhost ]# ll /var/ftp/pub/
total 0
drwxr-xr-x. 2 root root 6 Apr 25 18:27 base
drwxr-xr-x. 2 root root 6 Apr 25 18:27 epel

## 8)拷贝 rpm 包到 base 目录下(我就随便弄了俩,这里只是示范)

[root@localhost pub]# cp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm ./base/
[root@localhost pub]# cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm ./base/
[root@localhost pub]# ll base/
total 308
-rw-r--r--. 1 root root  47508 Apr 25 18:42 tree-1.6.0-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 266160 Apr 25 18:38 zip-3.0-11.el7.x86_64.rpm

## 9)下载 rpm 包到 epel 源

[root@localhost pub]# cd epel/
[root@localhost epel]# wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/h/hdf5-1.8.12-13.el7.x86_64.rpm
[root@localhost epel]# ll
total 1644
-rw-r--r--. 1 root root 1682124 Sep 16  2021 hdf5-1.8.12-13.el7.x86_64.rpm

## 10)分别把这两个目录做成仓库

[root@localhost]# createrepo /var/ftp/pub/base/
Spawning worker 0 with 2 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost ]# createrepo /var/ftp/pub/epel/
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost ]# ll /var/ftp/pub/base/
total 312
drwxr-xr-x. 2 root root   4096 Apr 25 19:16 repodata
-rw-r--r--. 1 root root  47508 Apr 25 18:42 tree-1.6.0-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 266160 Apr 25 18:38 zip-3.0-11.el7.x86_64.rpm
[root@localhost ]# ll /var/ftp/pub/epel/
total 1648
-rw-r--r--. 1 root root 1682124 Sep 16  2021 hdf5-1.8.12-13.el7.x86_64.rpm
drwxr-xr-x. 2 root root    4096 Apr 25 19:17 repodata

## 11)在其他机器上手写 repo 配置文件

[root@zxw]# vim /etc/yum.repos.d/base_epel.repo
[zxw_base]
name=wode base cangku
baseurl=ftp://10.0.0.105/pub/base/
gpgcheck=0
enabled=1


[zxw_epel]
name=wode epel cangku
baseurl=ftp://10.0.0.105/pub/epel
gpgcheck=0
enabled=1

# 12)检查 yum 仓库
[root@zxw ]# yum repolist 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                              repo name                                    status
zxw_base                             wode base cangku                             2
zxw_epel                             wode epel cangku                             1
repolist: 3

# 13)使用 yum 安装
[root@zxw ]# yum install -y tree
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
 Package         Arch              Version                    Repository           Size
========================================================================================
Installing:
 tree            x86_64            1.6.0-10.el7               zxw_base             46 k

Transaction Summary
========================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm                                     |  46 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tree-1.6.0-10.el7.x86_64                                             1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64                                             1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                                                            

Complete!
[root@zxw ~]# tree
.
├── 1.TXT
└── 2.TXT

0 directories, 2 files

阿里云 2 核 2G 服务器 3M 带宽 61 元 1 年,有高配

腾讯云新客低至 82 元 / 年,老客户 99 元 / 年

代金券:在阿里云专用满减优惠券

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2024-07-25发表,共计5276字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中