0
点赞
收藏
分享

微信扫一扫

yum管理工具

yum概述

什么是yum

yum也是一种rpm包管理工具,相比于rpm命令,优势是可以自动解决依赖关系。自动解决依赖关系前提条件,你的yum源中要有这些依赖包
举例:
nginx安装需要依赖pcre-devel、openssl-devel

yum install -y nginx

什么是yum源

yum源:可以理解为手机中的应用商店
yum源其他名称:镜像站,yum仓库,rpm仓库

yum包管理

更改yum

  • 打开对应yum源的镜像站:mirrors.aliyun.com

![1650674000318](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650674000318.png)

  • 下载两个源:
  • Base源:所有系统的基础软件包
  • centos

![1650674177815](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650674177815.png)

  • 配置方法

![1650674363756](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650674363756.png)

  • epel源:扩展软件包

![1650674458924](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650674458924.png)

  • 配置方法

![1650674571116](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650674571116.png)

wget-O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

curl-o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7

yum包管理命令

# 1.查询仓库中所有的rpm包
yum list
可以配合|grep过滤出想要的rpm包

# 2.查看仓库中所有安装包的详细信息
yum infoyum
info tree

# 3.根据命令或文件查找该命令属于哪个rpm包
yum provides 命令

注意:尽量接命令的绝对路径,不知道命令的绝对路径的情况下,*/命令

配置yum源

# 使用阿里云的yum源
http://mirrors.aliyun.com
# 系统中需要的基础yum源

base源:和镜像中的Linux基础rpm包差不多
epel源:一些扩展安装包

# yum源的配置文件存放目录
[root@shiying <sub>]# ll /etc/yum.repos.d/
total 40
-rw-r--r--. 1 root root 2523 Apr 21 19:01 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 23 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Oct 23 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Oct 23 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Oct 23 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 Oct 23 2020 CentOS-x86_64-kernel.repo
# 1.删除所有官方yum源
[root@shiying </sub>]#rm -f /etc/yum.repos.d/*
# 2.安全方式,不使用yum源
gzip -r /etc/yum.repos.
# 3.下载Base源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

[root@shiying <sub>]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2523 100 2523 0 0 12611 0 --:--:-- --:--:-- --:--:-- 12678

[root@shiying </sub>]# /etc/yum.repos.d

# 4.下载epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

[root@shiying <sub>]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 664 100 664 0 0 2815 0 --:--:-- --:--:-- --:--:-- 2813

[root@shiying </sub>]# /etc/yum.repos.d

## 注意:在/etc/yum.repos.d/目录下所有的yum源配置,必须以.repo结尾

## 安装nginx服务,使用nginx官方yum源
# 1.打开官网 http://nginx.org/
# 2.找nginx的yum仓库
# 3.vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

1.阿里云镜像站:http://mirrors.aliyun.com
2.网易镜像站:http://mirrors.163.com/
3.清华源:https://mirrors.tuna.tsinghua.edu.cn
4.中科大源:https://mirrors.ustc.edu.cn/
5.华为源:https://mirrors.huaweicloud.com/homeyu

yum命令实践

yum查询

## 查看yum仓库中的所有可以安装的rpm包
[root@shiying <sub>]# yum list

## 过滤看看yum仓库中是否有wget包
[root@shiying </sub>]# yum list|grep wget
wget.x86_64 1.14-18.el7_6.1 @base

包名 版本和发布次数 这包在哪个仓库中

## 查看指定包的详细信息
[root@shiying <sub>]# yum info wget

## 查看yum仓库中,所有安装包的详细信息
[root@shiying </sub>]# yum info

## 根据命令查找包
[root@shiying <sub>]# yum provides ifconf
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No matches found

## 该命令隶属于的包名
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
### 该命令隶属于的仓库
Repo : base
### 装完后,命令会在/usr/sbin下叫ifconfig
Filename : /usr/sbin/ifconf


## 根据命令查找属于哪个安装包,最好写命令的绝对路径
[root@shiying </sub>]# yum provides */ifconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo : base
Matched from:
Filename : /sbin/ifconfig

yum安装

yum安装方式:
-本地安装
yum localinstall -y 包名(前提该包已经下载在服务器上了,加上路径就是本地安装)
- yum源安装
yum install -y tree
-网站上安装
yum install -y http://test.driverzeng.com/Nginx_package/nginx-1.12.2-3.el7.x86_64.rpm

自动解决依赖关系的前提条件:在你的所有yum源中都要有该软件的依赖包

yum重装

yum reinstall -y 包名
作用:误删除了该服务相关的任何一个文件,使用reinstall都可以恢复,但是恢复的是最初始的配置

reinstall的方式,必须跟最开始安装这个包的方式保持一致

## yum源安装 reinstall重安装方式保持一致
[root@shiying <sub>]# yum -y install vsftpd
[root@shiying </sub>]# ll /etc/vsftpd/
total 20
-rw-------. 1 root root 125 Jun 10 2021 ftpusers
-rw-------. 1 root root 361 Jun 10 2021 user_list
-rw-------. 1 root root 5116 Jun 10 2021 vsftpd.conf
-rwxr--r--. 1 root root 338 Jun 10 2021 vsftpd_conf_migrate.sh
[root@shiying <sub>]# cd /etc/vsftpd
[root@shiying vsftpd]# rm -rf vsftpd.conf
[root@shiying vsftpd]# ll
total 12
-rw-------. 1 root root 125 Jun 10 2021 ftpusers
-rw-------. 1 root root 361 Jun 10 2021 user_list
-rwxr--r--. 1 root root 338 Jun 10 2021 vsftpd_conf_migrate.sh
[root@shiying vsftpd]# cd
[root@shiying </sub>]# yum reinstall -y vsftpd

## 本地安装 reinstall重安装方式保持一致
[root@shiying ~]# yum remove -y vsftpd
[root@shiying Packages]# yum -y install vsftpd-3.0.2-28.el7.x86_64.rpm
[root@shiying Packages]# ll /etc/vsftpd
total 20
-rw-------. 1 root root 125 Oct 14 2020 ftpusers
-rw-------. 1 root root 361 Oct 14 2020 user_list
-rw-------. 1 root root 5116 Oct 14 2020 vsftpd.conf
-rwxr--r--. 1 root root 338 Oct 14 2020 vsftpd_conf_migrate.sh
[root@shiying Packages]# rm -rf /etc/vsftpd/vsftpd.conf
[root@shiying Packages]# ll /etc/vsftpd/
total 12
-rw-------. 1 root root 125 Oct 14 2020 ftpusers
-rw-------. 1 root root 361 Oct 14 2020 user_list
-rwxr--r--. 1 root root 338 Oct 14 2020 vsftpd_conf_migrate.sh
[root@shiying Packages]# yum -y reinstall vsftpd-3.0.2-28.el7.x86_64.rpm

vsftpd:是一个服务 供文件上传下载远程传输
[root@shiying pub]# cd /etc/vsftpd/
[root@shiying vsftpd]# ll
total 20
-rw-------. 1 root root 125 Jun 10 2021 ftpusers
-rw-------. 1 root root 361 Jun 10 2021 user_list
-rw-------. 1 root root 5116 Jun 10 2021 vsftpd.conf
-rwxr--r--. 1 root root 338 Jun 10 2021 vsftpd_conf_migrate.sh
关闭防火墙
[root@shiying vsftpd]# systemctl stop firewalld
启动vsftpd
[root@shiying vsftpd]# systemctl start vsftpd
查看是哪个端口
[root@shiying vsftpd]# netstat -lntup
-bash: netstat: command not found
关闭这个服务
[root@shiying vsftpd]# systemctl stop vsftpd

yum更新

# 查看当前系统中,有哪些软件是可以更新的
[root@shiying Packages]# yum check-update

# 更新指定的软件包
[root@shiying Packages]# yum update -y zlib

# 更新所有可更新的软件包 比较危险会更新系统版本
[root@zls vsftpd]# yum update -y


[root@shiying Packages]# yum check-update|grep kernel
kernel.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools.x86_64 3.10.0-1160.62.1.el7 updates
kernel-tools-libs.x86_64 3.10.0-1160.62.1.el7 updates
查看当前系统内核版本
[root@shiying Packages]# uname -a
Linux shiying 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

yum卸载

[root@zls <sub>]# yum erase 包名 -y

[root@zls </sub>]# yum remove 包名 -y

yum仓库指令

# 查看所有源中可用的yum仓库

[root@shiying Packages]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
仓库名 仓库描述 仓库状态:多少个
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,751
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 509
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 3,728
repolist: 28,060

# 查看所有源中,所有的yum仓库
[root@shiying Packages]# yum repolist all

## 使用yum-config-manager

# 1.没有命令,要安装命令
[root@shiying <sub>]# yum install -y yum-config-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
No package yum-config-manager available.
Error: Nothing to do

# 2.查询该命令属于哪个包
[root@shiying </sub>]# yum provides */yum-config-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
epel/x86_64/filelists_db | 12 MB 00:00:00
yum-utils-1.1.31-54.el7_8.noarch : Utilities based around the yum package manager
Repo : base
Matched from:
Filename : /usr/bin/yum-config-manager

# 3.安装对应的rpm包
[root@shiying <sub>]# yum -y install yum-utils

更改配置文件
[root@shiying </sub>]# vim /etc/yum.repos.d/CentOS-Base.repo

## 修改yum源配置文件,开启或关闭仓库
# 1.开启
[root@zls vsftpd]# yum-config-manager --enable nginx-mainline
# 2.关闭
[root@zls vsftpd]# yum-config-manager --disable nginx-mainline

yum缓存命令

## 不仅清除所有的缓存 下载到本地的rpm包也会清除
yum clean all

## 加载缓存
yum makecache

## 默认情况下,yum是不会下载rpm的只会安装

# 除非开启,下载的配置
vim/etc/yum.conf

[root@shiying <sub>]# vim /etc/yum.conf

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0 # 把0改成1就是开启下载rpm

## 下面是yum下载后的默认路径
[root@shiying </sub>]# ll /var/cache/yum/x86_64/7/
total 4
drwxr-xr-x. 4 root root 33 Apr 23 11:55 base
drwxr-xr-x. 4 root root 33 Apr 23 10:39 base-debuginfo
drwxr-xr-x. 4 root root 33 Apr 23 10:39 base-source

## 下载nginx,不安装,并指定目录
yum install nginx -y--downloadonly--downloaddir=/tmp

--downloadonly:仅下载,不安装
--downloaddir:指定下载的目录

## yum clean packages
只会清除默认路径下的rpm包

[root@shiying <sub>]# yum install vsftpd -y --downloadonly
[root@shiying </sub>]# rpm -qa|grep vsftpd
vsftpd-3.0.2-28.el7.x86_64
[root@shiying <sub>]# ll /var/cache/yum/x86_64/7/updates/packages/
total 176
-rw-r--r--. 1 root root 176896 Jun 11 2021 vsftpd-3.0.2-29.el7_9.x86_64.rpm
[root@shiying </sub>]# yum install vsftpd -y --downloadonly --downloaddir=/tmp
[root@shiying <sub>]# ll /tmp
total 200
-rw-r--r--. 1 root root 176896 Jun 11 2021 vsftpd-3.0.2-29.el7_9.x86_64.rpm

[root@shiying </sub>]# find /var/cache/yum/ -type f -name '*.rpm'
/var/cache/yum/x86_64/7/updates/packages/vsftpd-3.0.2-29.el7_9.x86_64.rpm
[root@shiying <sub>]# find /var/cache/yum/ -type f -name '*.rpm'
/var/cache/yum/x86_64/7/updates/packages/vsftpd-3.0.2-29.el7_9.x86_64.rpm
[root@shiying </sub>]# yum clean packages
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
1 package file removed
[root@shiying <sub>]# find /var/cache/yum/ -type f -name '*.rpm'
[root@shiying </sub>]# ll /tmp
total 200
drwxr-xr-x. 74 root root 8192 Apr 21 16:51 etc
drwx------. 2 root root 6 Apr 22 15:37 vmware-root_556-2966037836
-rw-r--r--. 1 root root 176896 Jun 11 2021 vsftpd-3.0.2-29.el7_9.x86_64.rpm

yum包组管理命令

# 查看有哪些包组可以安装
[root@shiying ~]# yum group list

#安装包组
yum groups install 包组名字

# 卸载包组
yum groups remove 包组名字

![1650770218529](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650770218529.png)

yum历史命令

# 查看yum的历史操作
[root@shiying <sub>]# yum history
命令的ID 执行的命令 执行的时间 动作 操作几个包
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
19 | root <root> | 2022-04-23 11:06 | I, U | 5
18 | root <root> | 2022-04-23 10:12 | Reinstall | 1
17 | root <root> | 2022-04-23 10:09 | Install | 1
16 | root <root> | 2022-04-23 10:08 | Erase | 1
15 | root <root> | 2022-04-23 10:02 | Reinstall | 1
14 | root <root> | 2022-04-23 10:00 | Install | 1

# 查看某个历史操作的详细信息
yum history info +ID

[root@shiying </sub>]# yum history info 14
Loaded plugins: fastestmirror
Transaction ID : 14
Begin time : Sat Apr 23 10:00:01 2022
Begin rpmdb : 350:f229c465e32ff184066669973bc6595fd3f9cb5f
End time : (0 seconds)
End rpmdb : 351:13d0b589427ec90118c48b2ded2a1960c1074f7a
User : root <root>
Return-Code : Success
Command Line : -y install vsftpd
Transaction performed with:
Installed rpm-4.11.3-45.el7.x86_64 @anaconda
Installed yum-3.4.3-168.el7.centos.noarch @anaconda
Installed yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch @anaconda
Packages Altered:
Install vsftpd-3.0.2-29.el7_9.x86_64 @updates
history info

# 撤销历史操作:一般撤销更新操作
yum history undo ID

YUM仓库配置文件

# 仓库名字
[base]
# 仓库的描述
name=CentOS-$releasever- Base - mirrors.aliyun.com

# 仓库的地址
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/

# 仓库签名检查机制
gpgcheck=1
# 仓库开启/关闭(1:开启,0:关闭,默认1)
enabled=1

# 公钥的地址
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-Cent

公钥:锁
私钥:钥匙


[root@shiying <sub>]# ssh root@10.0.0.106
root@10.0.0.106's password:
Last login: Sat Apr 23 23:09:53 2022
[root@localhost </sub>]# logout
Connection to 10.0.0.106 closed.

[root@shiying <sub>]# ssh keygen
ssh: Could not resolve hostname keygen: Name or service not known
[root@shiying </sub>]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
root@shiying <sub>]# cd </sub>/.ssh/
[root@shiying .ssh]# ll
[root@shiying .ssh]# cd
[root@shiying <sub>]# yum install -y vsftpd

[root@shiying </sub>]# cd /var/ftp/pub/
[root@shiying pub]# ll
total 0
[root@shiying pub]# mkdir base
[root@shiying pub]# mkdir epel
[root@shiying pub]# ll
total 0
drwxr-xr-x. 2 root root 6 Apr 23 15:27 base
drwxr-xr-x. 2 root root 6 Apr 23 15:28 epel
[root@shiying pub]# cp /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm ./base/
[root@shiying pub]# cp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm ./base/
[root@shiying pub]# cp /mnt/Packages/unzip-6.0-21.el7.x86_64.rpm ./epel/
[root@shiying pub]# systemctl start vsftpd
[root@shiying pub]# yum provides */repodata
[root@shiying pub]# yum install -y createrepo
[root@shiying pub]# createrepo /var/ftp/pub/
[root@shiying pub]# ll
total 4
drwxr-xr-x. 2 root root 75 Apr 23 15:30 base
drwxr-xr-x. 2 root root 41 Apr 23 15:31 epel
drwxr-xr-x. 2 root root 4096 Apr 23 15:59 repodata
[root@shiying pub]# ll base/
total 308
-rw-r--r--. 1 root root 47508 Apr 23 15:30 tree-1.6.0-10.el7.x86_64.rpm
-rw-r--r--. 1 root root 266160 Apr 23 15:30 zip-3.0-11.el7.x86_64.rpm
[root@shiying pub]# ll epel
total 172
-rw-r--r--. 1 root root 175412 Apr 23 15:31 unzip-6.0-21.el7.x86_64.rpm

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
[root@localhost <sub>]# ll /mnt
total 696
-rw-r--r--. 3 root root 14 Oct 30 2020 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Oct 27 2020 EFI
-rw-rw-r--. 21 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 21 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 2048 Oct 27 2020 images
drwxr-xr-x. 2 root root 2048 Nov 3 2020 isolinux
drwxr-xr-x. 2 root root 2048 Oct 27 2020 LiveOS
drwxr-xr-x. 2 root root 673792 Nov 4 2020 Packages
drwxr-xr-x. 2 root root 4096 Nov 4 2020 repodata
-rw-rw-r--. 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Nov 4 2020 TRANS.TBL

## 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 4070 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/
drwxr-xr-x. 3 root root 225280 Apr 25 10:10 /local_yum_repo/

[root@localhost </sub>]# ll -d /local_yum_repo/repodata/
drwxr-xr-x. 2 root root 4096 Apr 25 10:10 /local_yum_repo/repodata/

[root@localhost <sub>]# ll /local_yum_repo/repodata/
total 13912
-rw-r--r--. 1 root root 3396545 Apr 25 10:10 2a19a04ec968e091696c22a976a27be4edb85bd4934b335575aba238861061da-primary.sqlite.bz2
-rw-r--r--. 1 root root 3402915 Apr 25 10:10 4a1c8221285db1b9d5361d4567baa883e60ee29c32d8d0a1b7777d7d7761664d-filelists.xml.gz
-rw-r--r--. 1 root root 3462802 Apr 25 10:10 60aa4673bf5fa63d1a7a640ef407b8e48fe5b3337720d844a29a53fec130d6da-filelists.sqlite.bz2
-rw-r--r--. 1 root root 1357114 Apr 25 10:10 9d6292fa12fd9ca472fafa8c0b348c3e1f139681aa066d41dc53b3563bcd1f53-other.sqlite.bz2
-rw-r--r--. 1 root root 1602174 Apr 25 10:10 a987612cd39d54bf129c1230f6699be448fca318fa5c9e401d633613012e89cb-primary.xml.gz
-rw-r--r--. 1 root root 1006186 Apr 25 10:10 b157d8b012febabf1c72d579b5155b8519a362a64bbd37c40acb22b6cc544ccf-other.xml.gz
-rw-r--r--. 1 root root 3009 Apr 25 10:10 repomd.xml

## 6)压缩其他yum源
[root@localhost </sub>]# gzip -r /etc/yum.repos.d/
[root@localhost <sub>]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 549 Oct 23 2020 CentOS-Base.repo.gz
-rw-r--r--. 1 root root 735 Oct 23 2020 CentOS-CR.repo.gz
-rw-r--r--. 1 root root 426 Oct 23 2020 CentOS-Debuginfo.repo.gz
-rw-r--r--. 1 root root 232 Oct 23 2020 CentOS-fasttrack.repo.gz
-rw-r--r--. 1 root root 381 Oct 23 2020 CentOS-Media.repo.gz
-rw-r--r--. 1 root root 506 Oct 23 2020 CentOS-Sources.repo.gz
-rw-r--r--. 1 root root 813 Oct 23 2020 CentOS-Vault.repo.gz
-rw-r--r--. 1 root root 272 Oct 23 2020 CentOS-x86_64-kernel.repo.gz

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

## 8)使用yum源
[root@localhost </sub>]# yum repolist all

## 9)安装
yum install -y xxx

远程YUM仓库

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

# 1.安装创建仓库的命令
[root@localhost <sub>]# yum install -y createrpo
# 2.通过镜像,获取rpm包

## 1)挂载镜像
[root@localhost </sub>]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost <sub>]# ll /mnt
total 696
-rw-r--r--. 3 root root 14 Oct 30 2020 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 Oct 27 2020 EFI
-rw-rw-r--. 21 root root 227 Aug 30 2017 EULA
-rw-rw-r--. 21 root root 18009 Dec 10 2015 GPL
drwxr-xr-x. 3 root root 2048 Oct 27 2020 images
drwxr-xr-x. 2 root root 2048 Nov 3 2020 isolinux
drwxr-xr-x. 2 root root 2048 Oct 27 2020 LiveOS
drwxr-xr-x. 2 root root 673792 Nov 4 2020 Packages
drwxr-xr-x. 2 root root 4096 Nov 4 2020 repodata
-rw-rw-r--. 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 21 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 Nov 4 2020 TRANS.TBL

## 2)安装vsftpd服务
[root@localhost </sub>]# yum install vsftpd -y
## 3)启动服务
[root@localhost <sub>]# systemctl start vsftpd

## 4)检查端口
如果没有netstat 命令,则需要安装
[root@localhost </sub>]# yum install -y net-tools

[root@localhost <sub>]# 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 947/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1114/master
tcp6 0 0 :::21 :::* LISTEN 9821/vsftpd
tcp6 0 0 :::22 :::* LISTEN 947/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1114/master

[root@localhost </sub>]# netstat -lntup|grep vsftpd

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

## 6)打开浏览器访问:ftp://10.0.0.105:21
/ftp://IP

## 7)创建仓库目录

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

要以.repo结尾
[root@localhost <sub>]# vim /etc/yum.repos.d/base.repo
[base_shiying1]
name=base-repo
baseurl=ftp://10.0.0.105/pub/base/
gpgcheck=0
enabled=1

[root@localhost </sub>]# vim /etc/yum.repos.d/epel.repo

## 8)拷贝rpm包到base目录下
[root@localhost <sub>]# cp /mnt/Packages/zip-3.0-11.el7.x86_64.rpm /mnt/Packages/net-tools-2.0-0.25.20131004git.el7.x86_64.rpm /var/ftp/pub/base/
[root@localhost </sub>]# ll /var/ftp/pub/base
total 572
-rw-r--r--. 1 root root 312968 Apr 25 16:28 net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
drwxr-xr-x. 2 root root 4096 Apr 25 15:57 repodata
-rw-r--r--. 1 root root 266160 Apr 25 16:28 zip-3.0-11.el7.x86_64.rpm

## 9)下载rpm包到epel源下
1.wget +直接加网址

[root@localhost epel]# yum install -y wget
[root@localhost epel]# wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/n/ncdu-1.16-1.el7.x86_64.rpm
HTTP request sent, awaiting response... 200 OK
Length: 54292 (53K) [application/octet-stream]
Saving to: ‘ncdu-1.16-1.el7.x86_64.rpm’

100%[============================>] 54,292 --.-K/s in 0.06s

[root@localhost epel]# ll /var/ftp/pub/epel/
total 60
-rw-r--r--. 1 root root 54292 Jul 3 2021 ncdu-1.16-1.el7.x86_64.rpm
drwxr-xr-x. 2 root root 4096 Apr 25 15:59 repodata

下载rpm包到epel源下
2. curl +直接加网址查看到的rpm包
[root@localhost epel]# curl https://mirrors.aliyun.com/epel/7/x86_64/Packages/n/

#拼命令截取
[root@localhost epel]# curl https://mirrors.aliyun.com/epel/7/x86_64/Packages/n/ |grep 'href' | awk -F '[<>]' '{print $5}'

[root@localhost epel]# curl -s https://mirrors.aliyun.com/epel/7/x86_64/Packages/n/ |grep 'href' | awk -F '[<>]' '{print "wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/n/"$5}' |bash
wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/n/

# 或者这样截取
[root@localhost epel]# curl -s https://mirrors.aliyun.com/epel/7/x86_64/Packages/z/|awk -F'"' '/.rpm/{print "wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/z/"$4}
# //是awk过滤你想要的关键字 取行 eg: /.rpm/ /(111|222)/

[root@localhost epel]# ll /var/ftp/pub/epel/repodata
total 28
-rw-r--r--. 1 root root 586 Apr 25 15:59 01a3b489a465bcac22a43492163df43451dc6ce47d27f66de289756b91635523-filelists.sqlite.bz2
-rw-r--r--. 1 root root 123 Apr 25 15:59 401dc19bda88c82c403423fb835844d64345f7e95f5b9835888189c03834cc93-filelists.xml.gz

## 9)先把目录变成仓库,两个目录各一个仓库

[root@localhost epel]# createrepo /var/ftp/pub/base/
Spawning worker 0 with 2 pkgs

[root@localhost epel]# createrepo /var/ftp/pub/epel/
Spawning worker 0 with 51 pkgs

[root@localhost <sub>]# baseurl=ftp://10.0.0.105/pub/base/
[root@localhost </sub>]# epelurl=ftp://10.0.0.105/pub/epel/

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

[root@localhost epel]# ll /var/ftp/pub/base/
total 2856
drwxr-xr-x. 2 root root 4096 Apr 26 17:13 repodata

[root@localhost <sub>]# ll /var/ftp/pub/epel/
drwxr-xr-x. 2 root root 4096 Apr 26 17:13 repodata

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

手写yum源配置文件(必须以repo结尾)
[root@localhost <sub>]# vim /etc/yum.repos.d/base.repo
[base_shiying1]
name=base-repo
baseurl=ftp://10.0.0.105/pub/base/
gpgcheck=0
enabled=1

[root@localhost </sub>]# vim /etc/yum.repos.d/epel.repo
[root@localhost epel]# yum repolist
repo id repo name status
!base_shiying1 base-repo 0
!epel_shiying2 epel-repo 0

[root@localhost epel]# yum makecache

[root@localhost epel]# yum repolist

repo id repo name status
base_shiying1 base-repo 2
epel_shiying2 epel-repo 51


## 10)在其他机器上手写repo配置文件,哪台需要yum仓库,就在哪台上面写配置文件

#1)压缩所有系统中的其他yum源
[root@localhost <sub>]# gzip -r /etc/yum.repos.d/
[root@localhost </sub>]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 381 Oct 23 2020 CentOS-Media.repo.gz
-rw-r--r--. 1 root root 506 Oct 23 2020 CentOS-Sources.repo.gz
-rw-r--r--. 1 root root 813 Oct 23 2020 CentOS-Vault.repo.gz
-rw-r--r--. 1 root root 272 Oct 23 2020 CentOS-x86_64-kernel.repo.g

# 2)手写配置文件
[root@localhost <sub>]# vi /etc/yum.repos.d/base-epel.repo
[base_shiying1]
name=base-repo
baseurl=ftp://10.0.0.105/pub/base/
gpgcheck=0
enabled=1

[root@localhost </sub>]# vi /etc/yum.repos.d/epel.repo
[epel_shiying2]
name=epel-repo
baseurl=ftp://10.0.0.105/pub/epel/
gpgcheck=0
enabled=1

##压缩其他yum源
[root@localhost <sub>]# gzip -r /etc/yum.repos.d/
[root@localhost </sub>]# ll /etc/yum.repos.d/
total 32
-rw-r--r--. 1 root root 272 Oct 23 2020 CentOS-x86_64-kernel.repo.g

清除所有缓存
[root@localhost epel]# yum clean all
重新生成缓存
[root@localhost epel]# yum makecache
查看仓库内容
[root@localhost epel]# yum repolist

repo id repo name status
base_shiying1 base-repo 2
epel_shiying2 epel-repo 51

## 12)使用yum安装rpm包
[root@localhost yum.repos.d]# yum install ncdu


=================================================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================================================
Installing:
ncdu x86_64 1.16-1.el7 epel_shiying2 53 k

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

Total download size: 53 k

![1650872567527](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650872567527.png)
![1650878977517](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650878977517.png)
![1650881004174](C:\Users\59418\AppData\Roaming\Typora\typora-user-images\1650881004174.png)

举报

相关推荐

0 条评论