Linux network service deployment yum warehouse

1. Introduction to yum warehouse

1.1yum introduction

yum is a software update mechanism built based on RPM packages (the abbreviation of Red-Hat Package Manager), which can automatically resolve dependencies between software packages. To successfully use the YUM mechanism to update systems and software, you need to have a software repository (repository) that contains various rpm installation package files and their dependent software. The server that provides the software repository is also called the "source" server. As long as the address and other information of the software warehouse are correctly specified in the client, the software can be installed or updated through the corresponding "source" server.

1.2yum implementation process

软件仓库的提供方式
- 1.本地yum源(file:///mnt)
- 2.http yum源(http:///192.168.140.111/centos7)
- 3.ftp yum源(ftp:///192.168.140.111/centos7)

1.2.1Yum working principle

1.客户端根据配置文件找到yum仓库服务器的位置
2.服务端向客户端发送元数据包(包含 软件依赖关系 软件的位置)  
#相当于软件安装目录 
3.客户端下载后,在元数据包中的查找到目标,发送请求
4.服务器响应并将相关软件包和依赖关系发送给客户端,客户端下载安装

Insert image description here

1.2.2 Precautions

yum需要依赖于环境,依赖于服务端和客户端,允许跨网络

服务器:
- RPM包 (Packages文件夹中)
- 元数据(repodata文件夹:目录(软件的目录),软件的依赖关系,软件的位置)

客户端的配置文件中 
baseurl=地址   一定要写到到   这两个文件夹 repodata  packages  的上级目录 

最终形成两个文件夹Packages (包文件夹一般取名packages)和  repodata(元数据文件夹)

2. yum configuration file

2.1yum configuration file

2.1.1 Main configuration file

[root@localhost]# /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever //yum下载的RPM包的缓存目录 $basearch代表硬件架构 $releasever系统版本比如7
keepcache=0         //是否保存缓存  0代表不保存,1代表保存
debuglevel=2               //调试级别了解即可
logfile=/var/log/yum.log   // 日志文件位置
exactarch=1	  //是否允许不同版本的rpm安装
obsoletes=1	//update 的一个参数是否可以允许旧版本的运行	
gpgcheck=1      //验证秘钥
plugins=1      //是否允许插件1代表可以
installonly_limit=5  //保存几个内核 5代表5个

Insert image description here

2.1.2 Warehouse settings file

/etc/yum.repos.d/*.repo     //yum仓库文件位置

Insert image description here

2.1.3 Log files

/var/log/yum.log    //日志文件位置

Insert image description here

3. Detailed explanation of yum command

3.1 Download and install

yum install  软件名 -y #通过yum方式安装

Insert image description here

3.2 Query

3.2.1 Display available installation packages: yum list

Insert image description here

3.2.2 Display detailed information of the specified installation package: yum info

yum info  [软件名] #显示指定安装包详细信息,不加软件名是显示所有包的详细信息

Insert image description here

3.2.3 Find software installation packages based on keywords: yum search

yum search  关键词 #根据关键字查找软件安装包

Insert image description here

3.2.4 Find the corresponding software package according to the command name: yum provides

yum   provides 命令 #根据命令名查找对应的软件包

Insert image description here

3.2.5 Query the installation package group: yum grouplist

yum grouplist  [包组名] #安装包组的查询 不加包组名 就是显示所有

Insert image description here

3.2.6 Detailed information of the installation package group: yum groupinfo

yum groupinfo  <包组名> #显示包组的详细信息

#举例#
yum groupinfo Minimal Install #最小化安装包组的详细信息

Insert image description here

3.2.7 View historical usage records: yum history

yum history  #查看历史记录

Insert image description here

3.3 Uninstall

3.3.1yum remove

yum remove 	[软件名] 卸载已安装的软件

Insert image description here

3.3.2yum history undo

选择ID 1,2,3,4,5
可以使用yum history undo 4 进行卸载,这样对比remove好处是可以将所有的依赖都删除

Insert image description here

再次查看history,可以看见增加了一条删除记录

Insert image description here

#如果卸载错误#
yum history redo n #反悔卸载,n为卸载记录的ID

#举例#
yum history redo 8 #重新安装第二条记录中卸载的软件

Insert image description here

3.4 Only download but not install

当内网的一台主机安装某个软件包却缺少依赖包时,可以先由一台可连接外网的服务器下载依赖包,之后共享给这台主机
yum install --downloadonly +软件名称 --downloaddir=指定rpm包存放路径 

4. How to build yum warehouse

4.1 Build a local yum warehouse

systemctl stop firewalld
setenforce 0

Insert image description here

[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载

Insert image description here

切换到源文件目录   cd /etc/yum.repos.d/

Insert image description here

[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# ls
bak               CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo      CentOS-Vault.repo
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# mv *.repo bak/
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# 
[root@localhost yum.repos.d]# ls
bak

Insert image description here

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

Insert image description here

yum clean all
yum makecache

Insert image description here

yum -y install tree  //安装软件检测源的变化

Insert image description here

4.2 Use HTTP method to build yum warehouse

Server

systemctl stop firewalld   //关闭防火墙
setenforce 0

Insert image description here

yum -y install httpd  //安装http

Insert image description here

mount /dev/sr0 /var/www/html  //将光驱挂载在可以共享的文件夹下

Insert image description here

client
Insert image description here

vim http.repo  #新建 http.repo文件
[http]
name=http
baseurl=http://192.168.2.102 #服务器的ip地址
gpgcheck=0  #关闭校验
:wq  #退出并保存

Insert image description here

yum clean all   //清理缓存

Insert image description here

yum makecache   //建立元数据库

Insert image description here

yum -y install tree  //安装tree

Insert image description here
Insert image description here

4.3 Use FTP to build a yum warehouse

Configure server

#关闭防火墙
systemctl stop firewalld  
setenforce 0
# yum 安装ftp软件
yum -y install vsftpd

Insert image description here

cd /var/ftp/
mkdir /var/ftp/centos7  #新建目录作为挂载点
mount /dev/sr0 /var/ftp/centos7  #挂载

Insert image description here
client

systemctl stop firewalld.service 
setenfore 0  #关闭防火墙和selinux
cd /etc/yum.repos.d 
mkdir backup 
mv *.repo  bak   #移走网络源
vim ftp.repo  #新建 ftp.repo文件

Insert image description here

vim ftp.repo  #新建 ftp.repo文件
[ftp]
name=ftp
baseurl=ftp://192.168.190.254/test  #挂载目录
gpgcheck=0  #关闭校验
:wq  #退出并保存

Insert image description here

yum clean all 
yum makecache #清除网络源缓存,建立本地源数据

Insert image description here

yum install -y tree #安装tree以测试源的变化

Insert image description here

Guess you like

Origin blog.csdn.net/m0_62231324/article/details/132248473