• 14-Linux之yum软件管理


    1.YUM

    1.1 什么是YUM
    Yum是RedHat以及CentOS中的软件包管理器, 能够通过互联网下载.
    rpm包安装, 可以自动处理依赖性关系并安装.
    PS: YUM是生产最佳实践
    
    • 1
    • 2
    • 3
    1.2 YUM源
    要成功的使用 YUM 工具安装更新软件或系统, 
    就需要有一个包含各种 rpm 软件包的repository(软件仓库), 
    这个软件仓库我们习惯称为 yum源.(可以是本地源、网络源)
    
    查看现在有多少yum源: yum repolist 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    # 查看yum源 (163网易源)
    [root@kid ~]#  yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                  repo name                             status
    base/7/x86_64            CentOS-7 - Base - 163.com             10,072
    extras/7/x86_64          CentOS-7 - Extras - 163.com              516
    updates/7/x86_64         CentOS-7 - Updates - 163.com           4,156
    repolist: 14,744
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    2. YUM源配置

    默认系统是国外源, 需要替换为国内的阿里yum源.  
    国内下载软件的速度要下的多...
    
    • 1
    • 2
    # 下载yum源
    [root@kid ~]#  wget -O /etc/yum.repos.d/CentOS-Base.repo  http://mirrors.aliyun.com/repo/Centos-7.repo  
    --2022-09-05 14:12:39--  http://mirrors.aliyun.com/repo/Centos-7.repo
    Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 180.130.119.240, 180.130.119.248, 180.130.119.238, ...
    Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|180.130.119.240|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 2523 (2.5K) [application/octet-stream]
    Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
    
    100%[===========================>] 2,523       --.-K/s   in 0.006s  
    
    2022-09-05 14:12:39 (386 KB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    # 查看源(被切换为阿里源)
    [root@kid ~]# 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_6 13,755
    extras/7/x86_64  CentOS-7 - Extras - mirrors.aliyun.com           516
    updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com        4,156
    repolist: 28,499
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    # 扩展epel源 (epel是扩展源 有很多软件在基本源中没有
    # 下载到/etc/yum.repos.d/epel.repo
    [root@www.lqz.com ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo  
    
    • 1
    • 2
    • 3
    # 在使用Nginx时需要使用官方的yum源来安装
    [root@lid ~]# vim /etc/yum.repos.d/nginx.repo  
    [nginx]  
    name=nginx repo   
    baseurl=http://nginx.org/packages/centos/7/$basearch/   
    gpgcheck=0  
    enabled=1  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    PS:源查找方式基本一致,zabbix, Docker、Nginx、saltstack、openstack
    
    • 1

    3. YUM的使用

    3.1 查询可安装软件
    yum list 列出所有可安装的安装包 
    
    • 1
    [root@kid ~]# yum list
    ...
    
    # 查询带ftp字眼可安装的软件
    [root@kid ~]# yum list|grep ftp 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    3.2 查询以安装软件
    yum list installed 列出已安装的安装包
    
    • 1
    [root@kid ~]# yum yum list installed
    ...
    
    • 1
    • 2
    3.3 查询软件信息
    yum info xx 查询指定软件的信息
    
    • 1
    [root@kid ~]# yum info ftp  
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    Available Packages
    Name        : ftp
    Arch        : x86_64
    Version     : 0.17
    Release     : 67.el7
    Size        : 61 k
    Repo        : base/7/x86_64
    Summary     : The standard UNIX FTP (File Transfer Protocol) client
    URL         : ftp://ftp.linux.org.uk/pub/linux/Networking/netkit
    License     : BSD with advertising
    Description : The ftp package provides the standard UNIX command-line
                : FTP (File Transfer Protocol) client.  FTP is a widely
                : used protocol for transferring files over the Internet
                : and for archiving files.
                : 
                : If your system is on a network, you should install ftp
                : in order to do file transfers.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    3.4 安装软件的方式
    网络安装:
    yum install xx      交互式
    yum install xx -y   非交互式
    
    在安装的时候回提示Is this ok [y/d/N]: 
    交互式需要手动输入y, 非交互式则不需要输入默认回复y.
    
    本地安装:
    yum localinstall  安装包路径
    使用yum安装本地的rpm包, 如果有依赖关系, 会自动从软件仓库中下载所需依赖  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    # 直接安装网络上的rpm包  
    [root@www.lqz.com ~]# yum install http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm  -y
    Loaded plugins: fastestmirror
    ...
    
    • 1
    • 2
    • 3
    • 4
    # 安装本地rpm软件
    [root@kid ~]# yum localinstall /mnt/Packages/bind-9.11.4-26.P2.el7.x86_64.rpm -y
    Loaded plugins: fastestmirror
    Examining /mnt/Packages/bind-9.11.4-26.P2.el7.x86_64.rpm: 32:bind-9.11.4-26.P2.el7.x86_64
    Marking /mnt/Packages/bind-9.11.4-26.P2.el7.x86_64.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package bind.x86_64 32:9.11.4-26.P2.el7 will be installed
    --> Processing Dependency: bind-libs(x86-64) = 32:9.11.4-26.P2.el7 for package: 32:bind-9.11.4-26.P2.el7.x86_64
    Loading mirror speeds from cached hostfile
    ...
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    3.4 重装软件包
    # 查询vsftpd配置文件  
    [root@kid ~]# rpm -qc vsftpd
    /etc/logrotate.d/vsftpd
    /etc/pam.d/vsftpd
    /etc/vsftpd/ftpusers
    /etc/vsftpd/user_list
    /etc/vsftpd/vsftpd.conf
    
    # 删除vsftpd的配置文件
    [root@kid ~]# rm -f /etc/vsftpd/vsftpd.conf 
    
    # 查询vsftpd配置文件  
    [root@kid ~]# rpm -qc vsftpd
    /etc/logrotate.d/vsftpd
    /etc/pam.d/vsftpd
    /etc/vsftpd/ftpusers
    /etc/vsftpd/user_list
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    # 可以对软件进行重新安装  
    [root@kid ~]# yum reinstall vsftpd  
      
    # 检查软件的配置文件  
    [root@kid ~]# rpm -qc vsftpd  
    /etc/logrotate.d/vsftpd  
    /etc/pam.d/vsftpd  
    /etc/vsftpd/ftpusers  
    /etc/vsftpd/user_list  
    /etc/vsftpd/vsftpd.conf  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    3.5 更新软件包
    # 查看可更新软件 (比Linux已安装的软件和yum仓库中的软件)   
    [root@kid ~]# yum check-update  
    ...
    
    • 1
    • 2
    • 3
    # 如下的执行很危险, 这代表更新整个系统所有的软件, 包括内核  
    [root@kidm ~]#  yum update -y  
    # 正常环境不要去执行, 如果服务器中跑这程序, 
    # 执行之后, 可能导致某个程序运行不了了.
    
    • 1
    • 2
    • 3
    • 4
    # 指定更新软件
    [root@python ~]#  yum update python -y  
    ...
    
    
    • 1
    • 2
    • 3
    • 4
    3.6 卸载软件
    # 安装软件
    [root@kid ~]# yum install samba -y 
      
    # 移除卸载
    [root@kid ~]# yum remove samba -y  
    
    # 或
    [root@kid ~]# yum erase samba -y
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    remove  erase 的一个别名. 使用yum help erase命令查看别名.
    
    • 1
    [root@kid ~]#  yum help erase
    Loaded plugins: fastestmirror
    erase PACKAGE...
    
    Remove a package or packages from your system
    
    aliases: remove, autoremove, erase-n, erase-na, erase-nevra, autoremove-n, autoremove-na, autoremove-nevra, remove-n, remove-na, remove-nevra
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    3.7 仓库相关指令
    # 列出yum源可用的软件仓库 (更新yum的配置会更新一次信息和数据)
    [root@kid ~]# yum repolist  
    
    
    • 1
    • 2
    • 3
    # 列出全部yum源可用和禁用的仓库  
    [root@kid ~]# yum repolist all  
    repo id                             repo name         status
    C7.0.1406-base/x86_64               CentOS-7.0.1406 - disabled
    zabbix-non-supported/x86_64         Zabbix Official R enabled:
    
    • 1
    • 2
    • 3
    • 4
    • 5
    # 查找某个命令或文件属于那个软件包(生产常用)  
    [root@kid ~]# yum provides /etc/my.cnf 
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    # mariadb-libs-5.5.68-1.el7.i686:所需的共享库
    1:mariadb-libs-5.5.68-1.el7.i686 : The shared libraries required for
    #                                :MariaDB/MySQL客户端
                                     : MariaDB/MySQL clients
    Repo        : base
    Matched from:
    Filename    : /etc/my.cnf
    
    [root@www.lqz.com ~]# yum provides cd 
    ...
    # bash-4.2.46-35.el7_9.x86_64:GNU Bourne的又一个shell
    bash-4.2.46-35.el7_9.x86_64 : The GNU Bourne Again shell
    Repo        : updates
    Matched from:
    Filename    : /usr/bin/cd
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    3.8 缓存相关指令
    # 缓存rpm包方式一, 修改yum全局配置文件  
    # 查看是否有缓存的rpm包, 没有.
    [root@kid ~]# find /var/cache/yum/x86_64/7/ -name '*.rpm'
    # 编辑yum的配置文件
    [root@kid ~]# vim /etc/yum.conf  
    [main]  
    # 缓存的地址 
    cachedir=/var/cache/yum/$basearch/$releasever  
    keepcache=1     # 启动缓存 
    ...
    
    # 下载安装软件并缓存(缓存地址默认是: /var/cache/yum/某个目录下)
    # 先卸载
    [root@kid ~]# yum remove tree -y
    # 安装
    [root@kid ~]# yum install tree -y
    # 查看缓存的rpm包 
    [root@kid ~]# find /var/cache/yum/x86_64/7/ -name '*.rpm'
    /var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    # 缓存rpm包方式二, 只下载不安装(已经安装的软件缓存不了)
    # 先下载yum的插件
    [root@kid ~]# yum install -y yum-plugin-downloadonly
    # --downloadonly 可下载参数  --downloaddir指定下载目录
    [root@kid ~]# yum install httpd -y --downloadonly --downloaddir=/tmp  
    ...
    
    [root@kid ~]# ls /tmp
    # 软件包
    httpd-2.4.6-97.el7.centos.5.x86_64.rpm
    # 一个下载记录文文件
    yum_save_tx.2022-09-05.16-25.5K9sIV.yumtx
    # 可是删除这个文件
    [root@kid ~]# cat /tmp/yum_save_tx.2022-09-05.16-25.5K9sIV.yumtx
    403:b329fd3879624934efe295c45620651fa73bddde
    0
    1
    installed:404:347c71ae57e5e43e5de1ad728b8255754562aa3a
    1
    mbr: httpd,x86_64,0,2.4.6,97.el7.centos.5 70
      repo: updates
      ts_state: u
      output_state: 20
      isDep: False
      reason: user
      reinstall: False
    
    
    # 如果想要安装则通过 yum localinstall  安装包路径 即可
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    # 只清除缓存的软件包  (不会删除方式二指定下载的软件包)
    [root@kid ~]# yum clean packages  
    
    # 清除所有yum缓存的软件包以及元数据 (不会删除方式二指定下载的软件包)
    [root@kid ~]# yum clean all  
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2022-09-05_00871

    yum 会把下载的软件包和header存储在cache中,而不自动删除.
    如果觉得占用磁盘空间,可以使用yum clean指令进行清除.
    yum clean headers 清除header.
    yum clean packages清除下载的rpm包.
    yum clean all一全部清除.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    3.9 组包相关指令
    # 列出环境组
    [root@kid ~]# yum groups list  
    可用环境组:
    最小安装
    计算节点
    基础结构服务器
    文件和打印服务器
    基本Web服务器
    带GUI的服务器
    GNOME桌面
    ...
    # 安装一整个组的软件  (安装桌面工具)
    [root@kid ~]# yum groups install  GNOME Desktop tools   
    ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    # yum删除包组  
    [root@kid ~]# yum groups remove  -y Base  
    
    • 1
    • 2
    3.10 历史记录指令
    # 查看历史执行yum命令  
    [root@kid ~]# yum history 
    Loaded plugins: fastestmirror
    ID     | Command line             | Date and time    | Action(s)      | Altered
    -------------------------------------------------------------------------------
        39 | install tree             | 2022-09-05 17:15 | Install        |    1   
        38 | remove tree              | 2022-09-05 17:13 | Erase          |    1   
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    # 查询历史执行yum命令ID详细信息  
    [root@www.lqz.com ~]# yum history info ID
      
    # 撤销历史执行过的yum命令  
    [root@www.lqz.com ~]# yum history undo ID 
    
    • 1
    • 2
    • 3
    • 4
    • 5

    4. 搭建本地仓库

    有的时候linux系统不能联网, 当然就不能很便捷的使用联网的yum源了, 
    这时候就需要你自己会利用linux系统光盘制作一个yum源.
    具体步骤如下:
    
    • 1
    • 2
    • 3
    # 1.挂载镜像  
    [root@kid ~]# mount /dev/cdrom /mnt   
    mount: /dev/sr0 is write-protected, mounting read-only
    
    • 1
    • 2
    • 3
    # 2. 下载yum-config-manager, 等会需要使用
    # yum-config-manager在 yum-utils 包里, 可以通过命令yum -y install yum-utils 安装就可以了
    [root@kid ~]# yum -y install yum-utils
    ...
    
    • 1
    • 2
    • 3
    • 4
    # 3.备份原有仓库 , 解压 gzip -d /etc/yum.repos.d/* 
    [root@kid ~]# gzip /etc/yum.repos.d/*  
    
    • 1
    • 2
    # 4.1 使用yum-config-manager命令添加本地仓库  
    [root@kid ~]# yum-config-manager --add-repo="file:///mnt"  
    Loaded plugins: fastestmirror
    adding repo from: file:///mnt
    
    [mnt]
    name=added from: file:///mnt
    baseurl=file:///mnt
    enabled=1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    # 4.2或者使用手动添加repo文件(备用方案, 设置了4.1则跳过这个)  
    [root@lqz ~]# vim /etc/yum.repos.d/cdrom.repo    
    [cdrom]        
    name=This is local cdrom  
    baseurl=file:///mnt  
    enabled=1  
    gpgcheck=0  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    []          仓库名称  
    name        仓库描述信息  
    baseurl     YUM源url地址 ,可以是file:// ftp:// http://  
    enabled     是否使用该YUM源(0代表禁用, 1代表激活)  
    gpgcheck    是否验证软件签名(0代表禁用, 1代表激活)  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    # 5.生成缓存  
    [root@kid ~]# yum makecache  
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    mnt                                                                                         | 3.6 kB  00:00:00     
    (1/4): mnt/group_gz                                                                         | 153 kB  00:00:00     
    (2/4): mnt/filelists_db                                                                     | 3.3 MB  00:00:00     
    (3/4): mnt/primary_db                                                                       | 3.3 MB  00:00:00     
    (4/4): mnt/other_db                                                                         | 1.3 MB  00:00:00     
    Metadata Cache Created
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    # 6. 列出可安装软件 (cdrom 本地)
    [root@kid ~]# yum list
    python2-ipalib.noarch                              4.6.8-5.el7.centos                  cdrom             
    python2-ipaserver.noarch                           4.6.8-5.el7.centos                  cdrom             
    python2-oauthlib.noarch                            2.0.1-8.el7                         cdrom  
    ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    # 使用本地yum源安装软件
    [root@kid ~]# yum install zsh
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Resolving Dependencies
    --> Running transaction check
    ---> Package zsh.x86_64 0:5.0.2-34.el7_8.2 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ===================================================================================================================
     Package               Arch                     Version                              Repository               Size
    ===================================================================================================================
    Installing:
     zsh                   x86_64                   5.0.2-34.el7_8.2                     cdrom                   2.4 M
    
    Transaction Summary
    ===================================================================================================================
    Install  1 Package
    
    Total download size: 2.4 M
    Installed size: 5.6 M
    Is this ok [y/d/N]: y
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : zsh-5.0.2-34.el7_8.2.x86_64                                                                     1/1 
      Verifying  : zsh-5.0.2-34.el7_8.2.x86_64                                                                     1/1 
    
    Installed:
      zsh.x86_64 0:5.0.2-34.el7_8.2                                                                            Complete!  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    5. 搭建服务端仓库

    很多时候不仅仅是一台机器无法上网, 而是很多机器都无法上网, 但都有联网下载软件的需求, 
    这个时候难道每台机器都挂在光盘则不合适了, 可以在本地搭建服务端仓库.
    
    • 1
    • 2

    仓库构建

    本地光盘提供基础软件包: Base  
    yum缓存提供常用软件包: nginx, zabbix, docker
    
    • 1
    • 2
    5.1 环境准备
    创建两台机器, 一台用于做yum仓库服务端
    
    • 1
    系统IP角色
    centos710.0.0.4yum仓库服务端
    centos710.0.0.3yum仓库客户端
    将虚拟机恢复至正确状态(不手动恢复yum环境了)
    
    • 1

    image-20220905181039712

     克隆机器
    
    • 1

    image-20220905181552349]GIF 2022-9-5 18-17-27

    5.2 服务器配置
    # 修改主机名
    [root@kid ~]# nmcli general hostname server
    # 查看主机名
    [root@kid ~]# nmcli general hostname 
    server
    # 重新连接后就改变了
    [root@server ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    # 将克隆机的ip改为 10.0.0.4
    [root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens32 
    IPADDR=10.0.0.4
    ...
    
    # 重启网卡
    [root@server ~]# service network restart
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    # 关闭防火墙、与selinux  
    [root@server ~]# systemctl stop firewalld  
    [root@server ~]# setenforce 0  
    
    • 1
    • 2
    • 3
    # 安装ftp服务, 启动并加入开机启动  
    [root@server ~]# yum -y install vsftpd   
    [root@server ~]# systemctl start vsftpd   
    [root@server ~]# systemctl enable vsftpd  
    
    • 1
    • 2
    • 3
    • 4
    # 开启yum缓存功能  
    [root@server ~]# vim /etc/yum.conf  
    [main] cachedir=/var/cache/yum/$basearch/$releasever 
    # 开启缓存
    keepcache=1  
    # 清除安装包与元数据
    [root@server ~]# yum clean all  
    Loaded plugins: fastestmirror
    Cleaning repos: base extras updates
    Cleaning up list of fastest mirrors
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    # 提供基础base软件包  
    # 创建目录用户存放rpm软件
    [root@server ~]# mkdir /var/ftp/centos7  
    # 挂载镜像文件
    [root@server ~]# mount /dev/cdrom /mnt  
    mount: /dev/sr0 is write-protected, mounting read-only
    # 将镜像文件的rpm软件复制到虚拟机的目录中
    [root@server ~]# cp -rp  /mnt/Packages/.rpm /var/ftp/centos7/ 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    # 安装nginx服务与docker容器
    [root@server ~]# yum -y install nginx docker  
    
    # 复制已缓存的 Nginx docker 及依赖包 到自定义 YUM 仓库目录中  
    [root@server ~]# find /var/cache/yum/x86_64/7/ \
    -iname "*.rpm" -exec cp -rf {} /var/ftp/ops \;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    # 安装createrepo并创建 reopdata仓库  
    [root@server ~]# yum -y install createrepo  
    # 创建目录
    [root@server ~]# mkdir /var/ftp/ops
    # createrepo /var/ftp/ops  创建仓库
    [root@server ~]# createrepo /var/ftp/ops  
    Saving Primary metadata
    Saving file lists metadata
    Saving other metadata
    Generating sqlite DBs
    Sqlite DBs complete
    
      
    # PS: 如果此仓库每次新增软件则需要重新生成一次  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    5.3 客户端配置
    # 客户端配置并使用 base 基础源  
    # 将原先的源全部压缩(没有可以使用的源)
    [root@kid ~]# gzip /etc/yum.repos.d/* 
    # 编辑一个yum源文件, 指定yum源地址
    [root@yum_client ~]# vim /etc/yum.repos.d/centos7.repo   
    [centos7]  
    name=centos7_base  
    baseurl=ftp://10.0.0.4/centos7  
    gpgcheck=0  
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    # 2.客户端配置并使用 ops 源  
    [root@yum_client ~]# vim /etc/yum.repos.d/ops.repo   
    [ops]  
    name=local ftpserver  
    baseurl=ftp://10.0.0.4/ops  
    gpgcheck=0  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    # 3. 查看可安装软件(base 基本库)
    [root@yum_client ~]# yum lisy
    yum-plugin-verify.noarch     1.1.31-54.el7_8     base 
    ...
    
    • 1
    • 2
    • 3
    • 4
    # 安装软件
    [root@server ~]# yum install zip.x86_64 
    Loaded plugins: fastestmirror, product-id, search-
                  : disabled-repos, subscription-manager
    
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    
    Loading mirror speeds from cached hostfile
    Resolving Dependencies
    --> Running transaction check
    ---> Package zip.x86_64 0:3.0-11.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ========================================================
     Package  Arch        Version           Repository
                                                       Size
    ========================================================
    Installing:
     zip      x86_64      3.0-11.el7        base      260 k
    
    Transaction Summary
    ========================================================
    Install  1 Package
    
    Total download size: 260 k
    Installed size: 796 k
    Is this ok [y/d/N]: y
    Downloading packages:
    zip-3.0-11.el7.x86_64.rpm          | 260 kB   00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : zip-3.0-11.el7.x86_64                1/1 
      Verifying  : zip-3.0-11.el7.x86_64                1/1 
    
    Installed:
      zip.x86_64 0:3.0-11.el7                               
    
    Complete!
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    6. epel源

    6.1 介绍
    在Centos下使用yum安装时往往找不到rpm的情况, 
    官方的rpm repository提供的rpm包也不够丰富, 很多时候需要自己编译很痛苦, 
    而EPEL恰恰可以解决这两方面的问题.
    EPEL的全称叫 Extra Packages for Enterprise Linux .
    EPEL是由 Fedora 社区打造,  RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目.装上了 EPEL之后, 就相当于添加了一个第三方源.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    6.2 安装epel源
    # 通过yum安装nginx
    [root@kid ~]# yum install nginx
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    No package nginx available.
    Error: Nothing to do
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    # 配置epel-7源
    # 下载阿里云的epel-7
    [root@kid ~]# wget -O /etc/yum.repos.d/epel-7.repo  http://mirrors.aliyun.com/repo/epel-7.repo
    
    # 安装 epel 
    [root@kid ~]# yum install -y epel-release     
    
    # 查看可用的yum源地址
    [root@kid yum.repos.d]# yum repolist  
    ...
    repo id                      repo name 
    epel/x86_64                  Extra Packages for Enterprise Linux 7 - x86_64   
    ...
    # 刷新缓存操作, 更新源之后, 更新下缓存使用新源的元数据
    # 清除系统所有的yum缓存
    [root@kid ~]# yum clean all   
     # 生成yum缓存
    [root@kid ~]# yum makecache     
    
    
    [root@kid ~]# yum  list | grep nginx*
    Repository epel is listed more than once in the configuration
    Repository epel-debuginfo is listed more than once in the configuration
    Repository epel-source is listed more than once in the configuration
    # epel  提供了 nginx.x86_64 
    nginx.x86_64                             1:1.20.1-9.el7                @epel   
    
    # 安装Nginx(自己会选 nginx.x86_64)
    [root@kid ~]# yum install nginx -y
    ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    6.3 epel文件
    [root@kid ~]# cd /etc/yum.repos.d/
    [root@kid yum.repos.d]# ll epel-7.repo
    -rw-r--r--. 1 root root  664 Aug  4 15:04 epel-7.repo
    [root@kid yum.repos.d]# cat epel-
    epel-7.repo        epel-testing.repo  
    [root@kid yum.repos.d]# cat epel-7.repo 
    [epel]
    name=Extra Packages for Enterprise Linux 7 - $basearch
    baseurl=http://mirrors.aliyun.com/epel/7/$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
     
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
    baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=0
     
    [epel-source]
    name=Extra Packages for Enterprise Linux 7 - $basearch - Source
    baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    gpgcheck=0
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    6.4 自定义epel源文件
    选一个可用的epel源仓库地址(下为腾讯的epel源):
    https://mirrors.cloud.tencent.com/epel/8/Everything/x86_64/
    * 软件存放在 Packages下
    
    • 1
    • 2
    • 3
    # 自定义epel源
    [root@kid ~]# cd /etc/yum.repos.d/
    [root@kid yum.repos.d]# vim my_epelc.repo
    # repo id
    [MY_EPEL]
    # 名称
    name=Tencent_EPEL
    # 地址
    baseurl=https://mirrors.cloud.tencent.com/epel/8/Everything/x86_64/
    # gpg签名是否开启, 0表示关闭
    gpgcheck=0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    # 查看可用的yum源地址
    [root@kid yum.repos.d]# yum repolist  
    ...
    repo id                      repo name 
    MY_EPEL                      Tencent_EPEL 
    ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    ————————————————
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    文章的段落全是代码块包裹的, 留言是为了避免文章提示质量低.
    ————————————————

  • 相关阅读:
    FPGA设计时序约束二、输入延时与输出延时
    linux nvidia 11.8 安装记录
    java调用方法之歌唱比赛六个评委打分【0~100分之间的整数】。要求去掉一个最高分和一个最低分后四个评委的平均分即为选手的得分。
    C++ 中的头文件和源文件
    C++中STL常用容器的用法详解
    Linux安装Anaconda和虚拟环境配置
    Kafka为什么这么快?它的高性能是如何实现的?
    windows系统安装python教程,以及PyCharm安装,新手入门详细
    超全整理——相机标定知识汇总
    opencv图像的本质
  • 原文地址:https://blog.csdn.net/qq_46137324/article/details/126726881