Linux软件包管理

软件包管理

软件包概述

  • 软件包:就是软件的安装程序
  • linux与windows软件包不兼容

分类

源码包
  • 源码包就是一大堆源代码程序,是由程序员按照特定的格式和语法编写出来的。计算机只能识别机器语言,也就是二进制语言,所以源码包安装之前需要编译

  • 一般可以在任何的计算机上安装使用

  • 编译过程耗时较长

  • 大多数用户不懂开发,编译过程中可能会有各种错误,用户无力解决。

源码安装 :下载软件的源代码 => 编译 => 安装(最麻烦,但也最稳定)

二进制包
  • 二进制包,也就是源码包经过成功编译之后产生的包,直接安装即可

  • 二进制包是 Linux 下默认的软件安装包,目前主要有以下 2 大主流的二进制包管理系统:

    • RPM 包管理系统:功能强大,安装、升级、査询和卸载非常简单方便,因此很多 Linux 发行版都默认使用此机制作为软件安装的管理方式,例如 Fedora、CentOS、RedHat、SUSE 等
      • rpm:先下载软件,本地安装
      • yum:在线安装,自动解决依赖关系
    • DEB 包管理系统:由 Debian Linux 所开发的包管理机制,通过 DPKG 包,Debian Linux 就可以进行软件包管理,主要应用在 Debian 和 Ubuntu 中。
      • dkpg
      • apt:在线安装,自动解决依赖关系
二进制源码包(.src.rpm)
  • 二进制源码包,是一个半成品,安装后不能直接使用

  • 需要使用rpmbuild工具重建成真正的rpm包或者重建成源码包才可安装使用

  • 命名方式一般为:

    • 软件包名.src.rpm

不管是源码包,还是二进制包,安装时都可能会有依赖关系

源码包管理

命名方式

  • 软件包名.tar.gz(多数为这个)
  • 软件包名.tar.bz2
  • 软件包名.tar.xz
  • 软件包名.zip

源码包获取

  • 可以去该软件的官网寻找,如Nginx、MySQL等

安装

步骤:软件配置./configure -->编译make–>安装make install

  • 软件配置./configure

    • 指定安装路径, --prefix=/usr/local/
    • 指定命令的目录,–bindir=/bin/
    • 指定配置文件的目录, --etcdir=/etc /
    • 启用或禁用某些功能,如 --enable-ssl 、 --disable-filter
    • 和其他软件关联,如 --with-pcre
    • 检查安装环境,例如是否有编译器gcc,是否满足软件的依赖需求
  • 编译make

    • make主要功能就是将其他语言的源代码打包成Linux可以识别安装的程序。编译过程需要gcc(gcc-c++)编译器
  • 实例1:代码雨安装

使用lrzsz工具,讲软件从windows导入linux
[root@server2 ~]# yum install -y  lrzsz
[root@server2 ~]# rz
#选择cmatrix-1.2a.tar.gz软件包
[root@server2 ~]# ll
总用量 80
-rw-------. 1 root root  1243 7月  24 17:35 anaconda-ks.cfg
-rw-r--r--. 1 root root 74376 8月  17 2021 cmatrix-1.2a.tar.gz

软件包解压
[root@server2 ~]# tar -zxf cmatrix-1.2a.tar.gz 
[root@server2 ~]# cd cmatrix-1.2a/
[root@server2 cmatrix-1.2a]# ls
acconfig.h  cmatrix.1        config.guess  configure.in  Makefile.am    missing        README
aclocal.m4  cmatrix.c        config.h.in   COPYING       Makefile.in    mkinstalldirs  stamp-h.in
AUTHORS     cmatrix.spec     config.sub    INSTALL       matrix.fnt     mtx.pcf        TODO
ChangeLog   cmatrix.spec.in  configure     install-sh    matrix.psf.gz  NEWS

软件配置(设置软件默认安装的位置等信息)
[root@server2 cmatrix-1.2a]# ./configure 
loading cache ./config.cache
checking for a BSD compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for tgetent in -ltermcap... no
configure: warning: 
*** No termcap lib available, consider getting the official ncurses
*** distribution from ftp://ftp.gnu.org/pub/gnu/ncurses if you get
*** errors compiling nano.
checking for use_default_colors in -l... no
checking for /usr/X11R6/lib/X11/fonts/misc... no
configure: warning:  

*** You do not appear to have an X window fonts directory in the standard
*** locations (/usr/lib/X11/fonts/misc or /usr/X11R6/lib/X11/fonts/misc). The
*** mtx.pcf font will not be installed.  This means you will probably not
*** be able to use the mtx fonts in your x terminals, and hence be unable
*** to use the -x command line switch.  Sorry about that...

updating cache ./config.cache
creating ./config.status
creating Makefile
creating cmatrix.spec
creating config.h

准备编译环境
[root@server2 cmatrix-1.2a]# yum install -y gcc make

编译
[root@server2 cmatrix-1.2a]# make
gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -Wall -Wno-comment -c cmatrix.c
cmatrix.c:37:20: 致命错误:curses.h:没有那个文件或目录
 #include <curses.h>
                    ^
编译中断。
make: *** [cmatrix.o] 错误 1

报错:致命错误:curses.h:没有那个文件或目录

原因:主要因为系统中没有找到ncurses-devel软件包

解决:yum install -y ncurses-devel

[root@server2 cmatrix-1.2a]# yum install -y ncurses-devel
[root@server2 cmatrix-1.2a]# make
gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -Wall -Wno-comment -c cmatrix.c
gcc  -g -O2 -Wall -Wno-comment  -o cmatrix  cmatrix.o  
cmatrix.o:在函数‘finish’中:
/root/cmatrix-1.2a/cmatrix.c:86:对‘curs_set’未定义的引用
/root/cmatrix-1.2a/cmatrix.c:87:对‘stdscr’未定义的引用
/root/cmatrix-1.2a/cmatrix.c:509:对‘LINES’未定义的引用
/root/cmatrix-1.2a/cmatrix.c:516:对‘LINES’未定义的引用
collect2: 错误:ld 返回 1
make: *** [cmatrix] 错误 1

报错:make: *** [cmatrix] 错误 1

原因:少包,gcc-c++

解决:yum install -y gcc-c++

[root@server2 cmatrix-1.2a]# yum install -y  gcc-c++
[root@server2 cmatrix-1.2a]# make
gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -Wall -Wno-comment -c cmatrix.c
gcc  -g -O2 -Wall -Wno-comment  -o cmatrix  cmatrix.o  
cmatrix.o:在函数‘finish’中:
/root/cmatrix-1.2a/cmatrix.c:86:对‘curs_set’未定义的引用
/root/cmatrix-1.2a/cmatrix.c:87:对‘stdscr’未定义的引用
/root/cmatrix-1.2a/cmatrix.c:509:对‘LINES’未定义的引用
/root/cmatrix-1.2a/cmatrix.c:516:对‘LINES’未定义的引用
collect2: 错误:ld 返回 1
make: *** [cmatrix] 错误 1

报错:make: *** [cmatrix] 错误 1

原因:需要的包都安装了,可能是软件配置时出现了问题

解决:删除该目录,重新解压,重新配置

[root@server2 cmatrix-1.2a]# cd
[root@server2 ~]# rm -rf cmatrix-1.2a
[root@server2 ~]# ll
总用量 80
-rw-------. 1 root root  1243 7月  24 17:35 anaconda-ks.cfg
-rw-r--r--. 1 root root 74376 8月  17 2021 cmatrix-1.2a.tar.gz
[root@server2 ~]# tar -zxf cmatrix-1.2a.tar.gz 
[root@server2 ~]# cd cmatrix-1.2a/
[root@server2 cmatrix-1.2a]# ./configure
[root@server2 cmatrix-1.2a]# make
gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -Wall -Wno-comment -c cmatrix.c
gcc  -g -O2 -Wall -Wno-comment  -o cmatrix  cmatrix.o  -lncurses  -lncurses

安装
[root@server2 cmatrix-1.2a]# make install
make[1]: 进入目录“/root/cmatrix-1.2a”
/bin/sh ./mkinstalldirs /usr/local/bin
  /usr/bin/install -c  cmatrix /usr/local/bin/cmatrix
make  install-man1
make[2]: 进入目录“/root/cmatrix-1.2a”
/bin/sh ./mkinstalldirs /usr/local/man/man1
mkdir /usr/local/man
mkdir /usr/local/man/man1
 /usr/bin/install -c -m 644 ./cmatrix.1 /usr/local/man/man1/cmatrix.1
make[2]: 离开目录“/root/cmatrix-1.2a”
 Installing matrix fonts in /usr/lib/kbd/consolefonts...
make[1]: 离开目录“/root/cmatrix-1.2a”

测试:
[root@server2 cmatrix-1.2a]# cmatrix
[root@server2 cmatrix-1.2a]# cmatrix -b -C red #更改代码雨颜色

在这里插入图片描述

  • 实例2:多线程下载软件 axel安装
[root@server2 ~]# rz
传入axel-1.0a.tar.gz软件包
[root@server2 ~]# ls
anaconda-ks.cfg  axel-1.0a.tar.gz  cmatrix-1.2a  cmatrix-1.2a.tar.gz

解压
[root@server2 ~]# tar -xzf axel-1.0a.tar.gz 
[root@server2 ~]# ls
anaconda-ks.cfg  axel-1.0a  axel-1.0a.tar.gz  cmatrix-1.2a  cmatrix-1.2a.tar.gz
[root@server2 ~]# cd axel-1.0a/

配置:指定安装目录为/opt/axel
[root@server2 axel-1.0a]# ./configure --prefix=/opt/axel
The strip option is enabled. This should not be a problem usually, but on some
systems it breaks stuff.

Configuration done:
  Internationalization disabled.
  Debugging disabled.
  Binary stripping enabled.

编译
[root@server2 axel-1.0a]# make
gcc -c axel.c -o axel.o -Wall -O3
gcc -c conf.c -o conf.o -Wall -O3
gcc -c conn.c -o conn.o -Wall -O3
gcc -c ftp.c -o ftp.o -Wall -O3
gcc -c http.c -o http.o -Wall -O3
gcc -c search.c -o search.o -Wall -O3
gcc -c tcp.c -o tcp.o -Wall -O3
gcc -c text.c -o text.o -Wall -O3
gcc axel.o conf.o conn.o ftp.o http.o search.o tcp.o text.o -o axel  -lpthread
strip axel

安装
[root@server2 axel-1.0a]# make install
mkdir -p /opt/axel/bin/
cp axel /opt/axel/bin/axel
mkdir -p /opt/axel/etc/
cp axelrc.example /opt/axel/etc/axelrc
mkdir -p /opt/axel/share/man/man1/
cp axel.1 /opt/axel/share/man/man1/axel.1

测试
[root@server2 ~]# ls /opt/axel/
bin  etc  share
[root@server2 ~]# axel http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
-bash: axel: 未找到命令

报错:-bash: axel: 未找到命令

原因:未采用默认的安装目录,命令已安装,/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin(环境变量)中都找不到

[root@server2 ~]# whereis axel
axel: /opt/axel/bin/axel
[root@server2 ~]# which axel
/usr/bin/which: no axel in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

解决:①直接使用命令完整路径;②建立软链接;③使用环境变量;

方法一:直接使用命令完整路径
[root@server2 ~]# /opt/axel/bin/axel http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
Initializing download: http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
File size: 1690 bytes
Opening output file RPM-GPG-KEY-CentOS-7
Starting download

[  0%]  .
Connection 0 finished

Downloaded 1.7 kilobytes in 0 seconds. (15.78 KB/s)

方法二:给/opt/axel/bin/axel创建一个软连接指向/usr/local/bin
[root@server2 ~]# ln -s /opt/axel/bin/axel /usr/local/bin/axel
[root@server2 ~]# ll /usr/local/bin/axel 
lrwxrwxrwx. 1 root root 18 7月  24 22:01 /usr/local/bin/axel -> /opt/axel/bin/axel
[root@server2 ~]# axel http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
Initializing download: http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
File size: 1690 bytes
Opening output file RPM-GPG-KEY-CentOS-7.0
Starting download

[  0%]  .
Connection 0 finished

Downloaded 1.7 kilobytes in 0 seconds. (15.62 KB/s)

终端 => 命令 => 系统的环境变量(PATH => /etc/profile) => 定义了一些命令的存放路径

输出当前系统的环境变量
[root@server2 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

方法三:把axel所在目录追加到环境变量文件/etc/profile中
[root@server2 ~]# echo 'export PATH=$PATH:/opt/axel/bin' >> /etc/profile
[root@server2 ~]# source /etc/profile #让配置立即生效
[root@server2 ~]# axel http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
Initializing download: http://mirrors.163.com/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
File size: 1690 bytes
Opening output file RPM-GPG-KEY-CentOS-7.1
Starting download

[  0%]  .
Connection 0 finished

Downloaded 1.7 kilobytes in 0 seconds. (14.21 KB/s)

卸载

[root@server2 ~]# ls
anaconda-ks.cfg  axel-1.0a  axel-1.0a.tar.gz  cmatrix-1.2a  cmatrix-1.2a.tar.gz
[root@server2 ~]# cd axel-1.0a/

卸载软件包
[root@server2 axel-1.0a]# make uninstall
rm -f /opt/axel/bin/axel
rm -f /opt/axel/etc/axelrc
rm -f /opt/axel/share/man/man1/axel.1

卸载编译与配置过程
[root@server2 axel-1.0a]# make distclean
rm -f *.o axel search core *.mo
rm -f Makefile.settings config.h

删除软件安装目录
[root@server2 axel-1.0a]# rm -rf /opt/axel/

RPM包管理

软件包获取

  • 官网下载

    • https://www.rpmfind.net/
    • http://rpm.pbone.net
      在这里插入图片描述
      在这里插入图片描述
      在这里插入图片描述
  • 从系统光盘(或镜像文件)中获取,版本可能有点老

RPM命名

如:httpd-2.4.6-93.el7.centos.x86_64.rpm

  • 软件包名

  • 版本号

  • 发布版本

  • 系统平台

  • rpm包

查询已安装的软件包

# rpm -qa  <--查询所有安装包
# rpm -qa | grep 软件名
# rpm -qf 文件名 <--查询指定的文件由哪个程序包安装生成
# rpm -ql 软件名 <--查看指定的程序文件安装后生成的所有文件
选项说明:
-q :query,查询
rpm ‐q [query‐options]
	‐a:查询所有安装包
	‐f:查询指定的文件由哪个程序包安装生成
	‐c:查询程序的配置文件
	‐l:查看指定的程序文件安装后生成的所有文件

软件安装完成后,一共生成了以下几类文件

  • 配置文件类:/etc
  • 程序文件本身,二进制文件命令:/usr/bin或/usr/sbin
  • 文档手册:/usr/share/doc或man目录

卸载

# rpm -e 软件名
选项说明:
--nodeps :强制卸载,忽略依赖关系

安装

# rpm -ivh rpm软件包
选项说明:
-i:install,安装
-v:显示进度条
-h:表示以"#"形式显示进度条
  • 安装时需要考虑:

    • os版本:不同版本不兼容
    • 依赖关系
    • rpm包的版本
    • 注意:
      • x86_64包,只能安装在64位的系统上
      • i386,i586,i686的软件包可以安装在32和64位系统上
      • noarch表示这个软件包与硬件构架无关,可以通用
  • 常见报错

错误:依赖检测失败: 
	libgpm.so.2()(64bit) 被 vim-enhanced-2:7.4.629-6.el7.x86_64 需要 	
	libperl.so()(64bit) 被 vim-enhanced-2:7.4.629-6.el7.x86_64 需要 
	perl(:MODULE_COMPAT_5.16.3) 被 vim-enhanced-2:7.4.629-6.el7.x86_64 需
	vim-common = 2:7.4.629-6.el7 被 vim-enhanced-2:7.4.629-6.el7.x86_64 需要
  • 解决方法:
    • 手动解决依赖关系,将软件安装需要的其他软件先安装
    • 使用yum方法安装,详细用法见后文

更新

# rpm -Uvh 最新版软件包
选项说明:
-U :Update,更新操作
-v:显示进度条
-h:表示以"#"形式显示进度条

YUM包管理

优点:在线安装,自动解决依赖关系

yum源:基于rpm包

yum源底层还是基于RPM进行软件安装操作的,所以

  • rpm -qa |grep 软件名

依旧适用

常用命令

清空&重建缓存
清空缓存及其他文件
[root@server2 ~]# yum clean all
重建缓存
[root@server2 ~]# yum makecache
安装
[root@server2 ~]# yum install -y httpd
#安装图形化界面
[root@server2 ~]# yum groupinstall "GNOME 桌面" 
#从本地安装
[root@server2 ~]# yum -y install /root/httpd-2.4.6- 93.el7.centos.x86_64.rpm 
卸载
[root@server2 ~]# yum -y remove httpd 
[root@server2 ~]# yum -y groupremove "GNOME 桌面"
查询
查询软件包是否存在
[root@server2 ~]# yum list httpd
已安装的软件包
httpd.x86_64                                       2.4.6-97.el7.centos                                        @updates

查询软件包信息
[root@server2 ~]# yum info httpd
已安装的软件包
名称    :httpd
架构    :x86_64
版本    :2.4.6
发布    :97.el7.centos
大小    :9.4 M
源    :installed
来自源:updates
简介    : Apache HTTP Server
网址    :http://httpd.apache.org/
协议    : ASL 2.0
描述    : The Apache HTTP Server is a powerful, efficient, and extensible
         : web server.

根据配置文件查找软件包
[root@server2 ~]# yum provides /etc/ssh/ssh_config 
openssh-clients-7.4p1-21.el7.x86_64 : An open source SSH client applications
源    :base
匹配来源:
文件名    :/etc/ssh/ssh_config

查找命令属于哪个包
[root@server2 ~]# yum provides tree
tree-1.6.0-10.el7.x86_64 : File system tree viewer
源    :base[root@server2 ~]# yum -y remove httpd 
[root@server2 ~]# yum -y groupremove "GNOME 桌面"

YUM源管理

分类
本地yum源备份
[root@server2 ~]# cd /etc/yum.repos.d/

将所有本地源打包压缩
[root@server2 yum.repos.d]# tar -zcf repo.tar.gz *.repo
[root@server2 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo          repo.tar.gz
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  CentOS-x86_64-kernel.repo

删除所有本地源
[root@server2 yum.repos.d]# rm -rf *.repo
[root@server2 yum.repos.d]# ls
repo.tar.gz
[root@server2 yum.repos.d]# yum repolist 
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0
搭建本地yum源
[root@server2 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sr0              11:0    1  973M  0 rom  

将光盘挂载到/mnt目录下(临时挂载,重启后失效)
[root@server2 ~]# mount -o ro /dev/sr0 /mnt/
选项说明:
-o :指定挂载方式,
	ro:readonly,只读
	rw:read/write,读写
[root@server2 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sr0              11:0    1  973M  0 rom  /mnt

解挂:umount /mnt

光盘挂载添加到开机启动文件 /etc/rc.local中,实现每次开机自动挂载
[root@server2 ~]# echo 'mount -o ro /dev/sr0 /mnt/' >> /etc/rc.local 
[root@server2 ~]# chmod +x /etc/rc.local 

配置本地yum 
[root@server2 ~]# cat > /etc/yum.repos.d/local.repo <<EOF
> [local]
> name=local_yum
> baseurl=file:///mnt
> enabled=1
> gpcheck=0
> EOF
[root@server2 ~]# cat /etc/yum.repos.d/local.repo
[local]  #仓库标识名称
name=local_yum #仓库名称
baseurl=file:///mnt #仓库的路径,支持多种格式,file://本地路径,ftp://,http://或https://
enabled=1 #是否开机自启
gpcheck=0 #gpg密钥,值是0(代表不检测),1(代表检测,如果是1,下方还要定义一个gpgkey=密钥链接)

启用
[root@server2 ~]# yum clean all
[root@server2 ~]# yum makecache
[root@server2 ~]# yum repolist all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识                                                  源名称                                                     状态
local                                                   local_yum                                                  启用: 447
repolist: 447

配置阿里云的yum源

  • 键入:阿里 mirror镜像源,搜索yum源https://developer.aliyun.com/mirror/
    在这里插入图片描述

  • 选择合适的配置方法
    在这里插入图片描述

  • 根据官方提示去操作

1. 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
yum install -y wget
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

3.运行 yum makecache 生成缓存
yum clean all
yum makecache

EPEL源

  • EPEL是对官网源的一个扩展,存放了官方源中获取不到的软件包

  • CentOS-Base.repo => 基础源

    epel.repo => 扩展源,是对官方基础源的一个补充

[root@server2 ~]# yum install -y epel-release.noarch 

nginx在扩展源中存在
[root@server2 ~]# yum provides nginx
1:nginx-1.20.1-2.el7.x86_64 : A high performance web server and reverse proxy server
源    :epel

zabbix在扩展源中存在
[root@server2 ~]# yum provides zabbix
zabbix30-3.0.31-1.el7.x86_64 : Open-source monitoring solution for your IT infrastructure
源    :epel
匹配来源:
提供    :zabbix = 3.0.31-1.el7


会跑的小火车sl软件包,也是在扩展源中存在
[root@server2 ~]# yum install sl -y
[root@server2 ~]# sl

在这里插入图片描述

自建YUM源仓库

缓存软件安装包
[root@server2 ~]# vim /etc/yum.conf 
[root@server2 ~]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever  #定义软件包的缓存路径
keepcache=1  #1开启缓存;0关闭
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
下载但不安装软件
下载samba软件及依赖软件,但不安装
[root@server2 ~]# mkdir /soft
[root@server2 ~]# yum install --downloadonly --downloaddir=/soft samba
将下载的软件做成仓库
安装createrepo软件用于制作仓库
[root@server2 ~]# yum install -y createrepo

选择自建仓库文件夹
[root@server2 ~]# createrepo /soft
Spawning worker 0 with 10 pkgs
Spawning worker 1 with 9 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

在/etc/yum.repos.d目录中创建一个soft.repo的仓库
[root@server2 ~]# cd /etc/yum.repos.d/
[root@server2 yum.repos.d]# vim soft.repo
[root@server2 yum.repos.d]# cat soft.repo 
[soft]
name=soft yum
baseurl=file:///soft
gpgcheck=0
enabled=1

清理并重建缓存
[root@server2 ~]# yum clean all
[root@server2 ~]# yum makecache 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值