导读 | 今天来给大家介绍一下linux制作yum仓库的方法 |
yum仓库配置文件
# 仓库名 [base] # 仓库描述 name=CentOS-$releasever - Base - mirrors.aliyun.com # 仓库地址 baseurl=//mirrors.aliyun.com/centos/$releasever/os/$basearch/ # 检测签名机制(1:开启检测 0:关闭检测) gpgcheck=1 # 签名机制秘钥地址 gpgkey=//mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
yum仓库类型
# 1.远程仓库
// 端口:80 // 端口:443 ftp:// 端口:21
# 2.本地仓库
file:// 没有端口(本地协议) # 协议:// // ftp:// file:// // 端口:80 // 端口: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 //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
原文来自:
本文地址://q13zd.cn/yum-linux.html编辑:王华超,审核员:逄增宝
Linux命令大全:
Linux系统大全: