目录

  • 1.yum简介
  • 2.应用场景
  • 3.本地yum仓库搭建
  • 3.1流程
  • 3.2实操
  • 3.利用HTTP服务搭建内网yum仓库
  • 3.1流程
  • 3.2 服务端配置
  • 3.3 客户端配置
  • 4.利用FTP服务搭建内网yum仓库
  • 4.1 流程
  • 4.2 服务端配置
  • 4.3 客户端配置

1.yum简介

yum( Yellow dog Updater, Modified)是一个在 Fedora 和 RedHat 以及 SUSE 中的 Shell 前端软件包管理器。

基于 RPM 包管理,能够从指定的服务器自动下载 RPM 包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

yum 提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

菜鸟教程yum简介

2.应用场景

yum本地仓库搭建是为了当无法连接外网时,通过内网或本地的仓库完成软件的安装与相关的依赖性解决。本地仓库的搭建需要有一个yum源,或者一个系统镜像(一般系统镜像中有部分可安装的软件,这些软件在选择最小化安装的时候,不会安装到系统当中)。

以下实验使用的均为系统镜像源

3.本地yum仓库搭建

3.1流程

graph LR A[挂载镜像] --> B[备份原yum源<br> /etc/yum.repos.d] B --> C[创建本地.repo文件] C --> D[清空缓存<br>建立元数据]

3.2实操

1.挂载镜像

[root@localhost ~]# mount /dev/sr0 /mnt			##/dev/sr0 是光驱设备
mount: /dev/sr0 is write-protected, mounting read-only

2.备份原yum

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak			##移动原repo文件至bak中
[root@localhost yum.repos.d]# ls
bak

3.创建本地repo文件

[root@localhost yum.repos.d]# touch local.repo
[root@localhost yum.repos.d]# vim local.repo
[local]			##注释
name=local			##配置名称
baseurl=file:///mnt				##仓库地址
gpgcheck=0				##不检查完整性

4.清缓存,简历元数据

[root@localhost yum.repos.d]# yum clean all				##情况缓存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: local
Cleaning up list of fastest mirrors
Other repos take up 161 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum makecache 			##建立元数据
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
local                                                                                                                   | 3.6 kB  00:00:00     
(1/4): local/group_gz                                                                                                   | 166 kB  00:00:00     
(2/4): local/filelists_db                                                                                               | 3.2 MB  00:00:00     
(3/4): local/primary_db                                                                                                 | 3.1 MB  00:00:00     
(4/4): local/other_db                                                                                            	    | 1.3 MB  00:00:00     
Metadata Cache Created

5.测试安装tree

[root@localhost yum.repos.d]# tree
bash: tree: command not found...
[root@localhost yum.repos.d]# yum install tree -y
…………
Installed:
  tree.x86_64 0:1.6.0-10.el7                                                                                                                   

Complete!
[root@localhost yum.repos.d]# tree
.
├── bak
│   ├── CentOS-Base.repo
│   ├── CentOS-CR.repo
│   ├── CentOS-Debuginfo.repo
│   ├── CentOS-fasttrack.repo
│   ├── CentOS-Media.repo
│   ├── CentOS-Sources.repo
│   └── CentOS-Vault.repo
└── local.repo

1 directory, 8 files

3.利用HTTP服务搭建内网yum仓库

3.1流程

为确保实验成功,需要关闭防火墙和selinux。

服务端:

graph LR A[下载HTTP服务] --> B[挂载镜像<br>/var/www/html] B --> C[测试正常访问]

客户端:

graph LR A[备份原yum源] --> B[创建本地.repo文件] B --> C[清空缓存<br>建立元数据]

3.2 服务端配置

关闭防火墙与selinux确保正常通信

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0

1.下载http服务

[root@localhost ~]# yum install httpd -y
…………
Installed:
  httpd.x86_64 0:2.4.6-97.el7.centos.4                                               
Dependency Installed:
  apr.x86_64 0:1.4.8-7.el7    apr-util.x86_64 0:1.5.2-6.el7    httpd-tools.x86_64 0:2.4.6-97.el7.centos.4    mailcap.noarch 0:2.1.41-2.el7   
Complete!

2.挂载镜像

[root@localhost ~]# cd /var/www/html
[root@localhost html]# mkdir centos7
[root@localhost html]# ls
centos7
[root@localhost html]# mount /dev/sr0 centos7
mount: /dev/sr0 is write-protected, mounting read-only

3.启动服务,测试服务是否正常

[root@localhost html]# systemctl start httpd

启动过后,在实机中使用http服务访问虚拟机对应目录,应该可以正常查看挂载的内容。

linux配本地仓库mvn linux搭建本地yum仓库_CentOS

3.3 客户端配置

1.备份原yum源

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv *.repo bak

2.创建本地repo文件

[root@localhost yum.repos.d]# touch http.repo
[root@localhost yum.repos.d]# vim http.repo
[http.repo]
name=http
baseurl=http://192.168.186.5/centos7
gpgcheck=0

3.清空缓存,建立元数据

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: http.repo
Cleaning up list of fastest mirrors
Other repos take up 129 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum makecache 
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
http.repo                                                                                                               | 3.6 kB  00:00:00     
(1/4): http.repo/group_gz                                                                                               | 166 kB  00:00:00     
(2/4): http.repo/filelists_db                                                                                           | 3.2 MB  00:00:00     
(3/4): http.repo/primary_db                                                                                             | 3.1 MB  00:00:00     
(4/4): http.repo/other_db                                                                                               | 1.3 MB  00:00:00     
Metadata Cache Created

4.测试安装

[root@localhost yum.repos.d]# tree
bash: tree: command not found...
[root@localhost yum.repos.d]# yum install tree -y
…………
Installed:
  tree.x86_64 0:1.6.0-10.el7                                                       
Complete!
[root@localhost yum.repos.d]# tree
.
├── bak
│   ├── CentOS-Base.repo
│   ├── CentOS-CR.repo
│   ├── CentOS-Debuginfo.repo
│   ├── CentOS-fasttrack.repo
│   ├── CentOS-Media.repo
│   ├── CentOS-Sources.repo
│   └── CentOS-Vault.repo
└── http.repo

4.利用FTP服务搭建内网yum仓库

4.1 流程

为确保实验正常完成,关闭服务端的防火墙与selinux
服务端:

graph LR A[下载搭建FTP服务] --> B[挂载镜像<br>/var/ftp]

客户端:

graph LR A[下载安装FTP服务] --> B[测试访问服务端FTP文件] B --> C[备份原yum源] --> D[创建本地.repo文件] D --> E[清空缓存<br>建立元数据]

4.2 服务端配置

关闭防火墙与selinux

[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0

1.下载安装FTP服务。
服务端使用vsftp软件,进行安全传输(相对的安全)。

[root@localhost ~]# yum install vsftpd -y
…………
Installed:
  vsftpd.x86_64 0:3.0.2-29.el7_9                                                                                                               

Complete!

2.挂载镜像

[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# ls
pub
[root@localhost ftp]# mkdir centos7
[root@localhost ftp]# mount /dev/sr0 centos7
mount: /dev/sr0 is write-protected, mounting read-only

3.开启服务

[root@localhost ftp]# systemctl start vsftpd

4.3 客户端配置

1.客户端直接安装ftp即可

[root@localhost ~]# yum install ftp -y
…………
Installed:
  ftp.x86_64 0:0.17-67.el7                                                                                                                     

Complete!

2.测试连接

[root@localhost ~]# ftp 192.168.186.5			## 填写服务端的ip
Connected to 192.168.186.5 (192.168.186.5).  
220 (vsFTPd 3.0.2)
Name (192.168.186.5:root): ftp			## 使用匿名用户ftp
331 Please specify the password.
Password:			## 直接回车即可
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,186,5,71,83).
150 Here comes the directory listing.
drwxrwxr-x    8 0        0            2048 Nov 25  2018 centos7
drwxr-xr-x    2 0        0               6 Jun 09  2021 pub
226 Directory send OK.
ftp> quit
221 Goodbye

3.剩下步骤与 3.3 步骤相同,注意配置本地repo配置如下。

[root@localhost yum.repos.d]# vim ftp.repo

[ftp.repo]
name=ftp
baserul=ftp://192.168.186.5/centos7
gpgcheck=0

清空缓存,建立元数据

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: ftp.repo
Cleaning up list of fastest mirrors
Other repos take up 130 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum makecache 
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
ftp.repo                                                                                                                                                                                   | 3.6 kB  00:00:00     
(1/4): ftp.repo/group_gz                                                                                                                                                                   | 166 kB  00:00:00     
(2/4): ftp.repo/filelists_db                                                                                                                                                               | 3.2 MB  00:00:00     
(3/4): ftp.repo/primary_db                                                                                                                                                                 | 3.1 MB  00:00:00     
(4/4): ftp.repo/other_db                                                                                                                                                                   | 1.3 MB  00:00:00     
Metadata Cache Created

4.测试

[root@localhost yum.repos.d]# yum install tree -y
Loaded plugins: fastestmirror, langpacks
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                                            ftp.repo                                            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:01     
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@localhost yum.repos.d]# tree
.
├── bak
│   ├── CentOS-Base.repo
│   ├── CentOS-CR.repo
│   ├── CentOS-Debuginfo.repo
│   ├── CentOS-fasttrack.repo
│   ├── CentOS-Media.repo
│   ├── CentOS-Sources.repo
│   └── CentOS-Vault.repo
└── ftp.repo

1 directory, 8 files