Linux 软件包管理

rpm和yum,类似,dnf(centos7版本没有)

rpm 命令(低级)yum(高级)

可以安装/卸载

查询(重点)

基本语法:

几种模式

  • rpm -q查询

  • rpm -i 安装

  • rpm -e卸载

  • rpm-u升级

 #下载
 [root@server ~ 11:32:33]# yum install vsftpd --downloadonly
 #ls发现不在当前目录下
 [root@server ~ 13:41:35]# ls
 [root@server ~ 13:41:36]# find / -name vsftpd-3.0.2-29.el7_9.x86_64.rpm
 /var/cache/yum/x86_64/7/updates/packages/vsftpd-3.0.2-29.el7_9.x86_64.rpm
 #复制当前目录.下
 [root@server ~ 13:41:55]# cp /var/cache/yum/x86_64/7/updates/packages/vsftpd-3.0.2-29.el7_9.x86_64.rpm .
 ​

 # 查询系统中安装了哪些软件包
 [root@client ~ 11:24:31]# rpm -qa
 libqmi-utils-1.18.0-2.el7.x86_64
 libmpcdec-1.2.6-12.el7.x86_64
 gtkmm30-3.22.2-1.el7.x86_64
 nss-sysinit-3.67.0-4.el7_9.x86_64
 google-crosextra-caladea-fonts-1.002-0.4.201302
 ......
 ​
 # 查询系统中某个软件包是否安装
 [root@client ~ 14:05:02]# rpm -q httpd
 httpd-2.4.6-99.el7.centos.1.x86_64
 ​
 [root@client ~ 14:05:05]# rpm -q coreutils
 coreutils-8.22-24.el7_9.2.x86_64
 ​
 #例如未安装软件包 httpd显示
 [root@centos7 ~]# rpm -q kernel
 kernel-3.10.0-1160.71.1.el7.x86_64
 ​
 # 查询系统中某个已安装的软件包元数据信息,-i是详细信息
 [root@client ~ 14:05:26]# rpm -q coreutils -i
 Name        : coreutils
 Version     : 8.22
 Release     : 24.el7_9.2
 Architecture: x86_64
 Install Date: 2025年07月18日 星期五 10时29分16秒
 Group       : System Environment/Base
 Size        : 14594210
 License     : GPLv3+
 Signature   : RSA/SHA256, 2020年11月18日 星期三 22时16分51秒, Key ID 24c6a8a7f4a80eb5
 Source RPM  : coreutils-8.22-24.el7_9.2.src.rpm
 Build Date  : 2020年11月17日 星期二 06时24分59秒
 Build Host  : x86-01.bsys.centos.org
 Relocations : (not relocatable)
 Packager    : CentOS BuildSystem <http://bugs.centos.org>
 Vendor      : CentOS
 URL         : http://www.gnu.org/software/coreutils/
 Summary     : A set of basic GNU tools commonly used in shell scripts
 Description :
 These are the GNU core utilities.  This package is the combination of
 the old GNU fileutils, sh-utils, and textutils packages.
 ​
 # 查询系统中某个已安装的软件包包涵哪些文件
 [root@client ~ 14:05:51]# rpm -q openssh-server -l
 /etc/pam.d/sshd
 /etc/ssh/sshd_config
 /etc/sysconfig/sshd
 /usr/lib/systemd/system/sshd-keygen.service
 /usr/lib/systemd/system/sshd.service
 ......
 # 查询系统中某个已安装的软件包包涵哪些配置文件
 [root@client ~ 14:06:21]# rpm -q openssh-server -c 
 /etc/pam.d/sshd
 /etc/ssh/sshd_config
 /etc/sysconfig/sshd
 ​
 # 查询系统中某个已安装的软件包包涵哪些文档文件
 [root@client ~ 14:06:42]#  rpm -q openssh-server -d
 /usr/share/man/man5/moduli.5.gz
 /usr/share/man/man5/sshd_config.5.gz
 /usr/share/man/man8/sftp-server.8.gz
 /usr/share/man/man8/sshd.8.gz
 ​
 # 查询系统中某个某个文件属于哪个已安装的软件包
 [root@client ~ 14:06:59]# rpm -q -f /etc/ssh/sshd_config 
 openssh-server-7.4p1-22.el7_9.x86_64
 ​
 # 查询系统中某个已安装的软件包包涵的脚本
 [root@client ~ 14:07:09]# rpm -q openssh-server --scripts 
 preinstall scriptlet (using /bin/sh):
 getent group sshd >/dev/null || groupadd -g 74 -r sshd || :
 getent passwd sshd >/dev/null || \
   useradd -c "Privilege-separated SSH" -u 74 -g sshd \
   -s /sbin/nologin -r -d /var/empty/sshd sshd 2> /dev/null || :
 postinstall scriptlet (using /bin/sh):
 ​
 if [ $1 -eq 1 ] ; then 
         # Initial installation 
         systemctl preset sshd.service sshd.socket >/dev/null 2>&1 || : 
 ......
 ​
 # 查询系统中某个已安装的软件包变更日志
 [root@centos7 ~]# rpm -q openssh-server --changelog
 * 二 2月 06 2024 Dmitry Belyavskiy <dbelyavs@redhat.com> - 8.0p1-24
 - Providing a kill switch for scp to deal with CVE-2020-15778
   Resolves: RHEL-22870
 ......
 ​
 # 下载 httpd 软件包,以及依赖的其他软件包
 [root@client ~ 14:09:18]# mkdir rpms
 [root@client ~ 14:13:51]# yum install httpd --downloadonly --downloaddir=rpms
 已加载插件:fastestmirror, langpacks
 Loading mirror speeds from cached hostfile
  * base: mirrors.aliyun.com
  * extras: mirrors.aliyun.com
  * updates: mirrors.aliyun.com
 软件包 httpd-2.4.6-99.el7.centos.1.x86_64 已安装并且是最新版本
 无须任何处理
 ​
 # 选项是数字1,展示下载,因为前面下过了依赖存在,五个包就下了一个
 [root@client ~ 14:18:35]# ls -1 rpms
 httpd-2.4.6-99.el7.centos.1.x86_64.rpm
 ​
 # 查询系统中某个软件包文件包涵哪些配置文件
 [root@client ~ 14:18:39]# rpm -q -p rpms/httpd-2.4.6-99.el7.centos.1.x86_64.rpm -c
 /etc/httpd/conf.d/autoindex.conf
 /etc/httpd/conf.d/userdir.conf
 /etc/httpd/conf.d/welcome.conf
 /etc/httpd/conf.modules.d/00-base.conf
 /etc/httpd/conf.modules.d/00-dav.conf
 ......
 # 查询系统中某个软件包组中包涵哪些软件包
 [root@client ~ 14:19:30]# rpm -qg 'System Environment/Base'
 grub2-common-2.02-0.87.0.1.el7.centos.9.noarch
 centos-release-7-9.2009.1.el7.centos.x86_64
 setup-2.8.71-11.el7.noarch
 filesystem-3.2-25.el7.x86_64
 telepathy-filesystem-0.0.2-6.el7.noarch
 ......

示例

 # 查看openssh-server软件安装是否有问题
 [root@client ~ 14:26:41]# rpm -V openssh-server
 S.5....T.  c /etc/ssh/sshd_config
 ​
 # 修改(change)
 [root@client ~ 14:29:16]# sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
 [root@client ~ 14:31:36]# rpm -V openssh-server
 S.5....T.  c /etc/ssh/sshd_config
 ​
 #移走 /etc/ssh/sshd_config 文件,再次查看
 [root@client ~ 14:31:55]# mv /etc/ssh/sshd_config .
 [root@client ~ 14:32:29]# rpm -V openssh-server
 遗漏   c /etc/ssh/sshd_config
 ​
 # 恢复该文件到原来位置
 [root@client ~ 14:32:35]# mv sshd_config /etc/ssh/sshd_config

安装/卸载

提取 RPM 包中文件

  • Linux 提取

 #提取rpm中文件,删除现有配置文件(可能已损坏)
 [root@client ~ 14:35:16]# rm -f /etc/ssh/sshd_config
 # 查询openssh-server包的下载URL
 [root@client ~ 14:49:37]# repoquery --location openssh-server
 http://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/openssh-server-7.4p1-23.el7_9.x86_64.rpm
 # 下载RPM包
 [root@client ~ 14:51:43]#  wget http://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/openssh-server-7.4p1-23.el7_9.x86_64.rpm
 ​
  # 确认文件类型(RPM包)
 [root@client ~ 14:52:20]# file openssh-server-7.4p1-23.el7_9.x86_64.rpm 
 openssh-server-7.4p1-23.el7_9.x86_64.rpm: RPM v3.0 bin i386/x86_64 openssh-server-7.4p1-23.el7_9
 ​
 # 将RPM转换为CPIO归档
 [root@client ~ 14:52:55]# rpm2cpio openssh-server-7.4p1-23.el7_9.x86_64.rpm > openssh-server-7.4p1-23.el7_9.x86_64.cpio
 ​
 # 确认转换后的文件类型(CPIO归档)
 [root@client ~ 14:54:48]# file openssh-server-7.4p1-23.el7_9.x86_64.cpio
 openssh-server-7.4p1-23.el7_9.x86_64.cpio: ASCII cpio archive (SVR4 with no CRC)
 ​
 # 列出CPIO归档中的所有文件
 [root@client ~ 14:55:39]# cpio -t < openssh-server-7.4p1-23.el7_9.x86_64.cpio
 ./etc/pam.d/sshd
 ./etc/ssh/sshd_config
 ./etc/sysconfig/sshd
 ./usr/lib/systemd/system/sshd-keygen.service
 ./usr/lib/systemd/system/sshd.service
 ./usr/lib/systemd/system/sshd.socket
 ......
 # 筛选出路径包含"etc"的文件
 [root@client ~ 14:55:53]# cpio -t < openssh-server-7.4p1-23.el7_9.x86_64.cpio | grep etc
 1946 块
 ./etc/pam.d/sshd
 ./etc/ssh/sshd_config
 ./etc/sysconfig/sshd
 ​
 # 提取sshd_config文件到当前目录,-d保存到当前目录结构,cpio要自己d建目录分层,tar自动创建分层
 [root@client ~ 14:56:57]# cpio -id ./etc/ssh/sshd_config < openssh-server-7.4p1-23.el7_9.x86_64.cpio 
 1946 块
 ​
 [root@client ~ 14:57:46]# tree etc
 etc
 └── ssh
     └── sshd_config
 ​
 1 directory, 1 file
 ​
 # 将提取的配置文件移动到系统目录
 [root@client ~ 14:57:55]# mv etc/ssh/sshd_config /etc/ssh/
 # 重启SSH服务使新配置生效
 [root@client ~ 15:02:43]# systemctl restart sshd
 ​

yum管理软件包

 [root@client ~ 15:02:46]# yum help
 ​
 [root@client ~ 15:38:19]# yum info httpd
 已加载插件:fastestmirror, langpacks
 Loading mirror speeds from cached hostfile
  * base: mirrors.aliyun.com
  * extras: mirrors.aliyun.com
  * updates: mirrors.aliyun.com
 可安装的软件包
 名称    :httpd
 架构    :x86_64
 版本    :2.4.6
 发布    :99.el7.centos.1
 大小    :2.7 M
 源    :updates/7/x86_64
 简介    : Apache HTTP Server
 网址    :http://httpd.apache.org/
 协议    : ASL 2.0
 描述    : The Apache HTTP Server is a powerful, efficient, and extensible
          : web server.
 ​
 # 查看仓库中http开头的包有哪些
 [root@client ~ 15:38:21]# yum list 'http*'
 已加载插件:fastestmirror, langpacks
 Loading mirror speeds from cached hostfile
  * base: mirrors.aliyun.com
  * extras: mirrors.aliyun.com
  * updates: mirrors.aliyun.com
 已安装的软件包
 httpd-tools.x86_64                         2.4.6-99.el7.centos.1        @updates
 可安装的软件包
 http-parser.i686                           2.7.1-9.el7                  base    
 http-parser.x86_64                         2.7.1-9.el7                  base    
 ​
 # 查看仓库中httpd包有哪些版本
 [root@client ~ 15:39:28]# yum list httpd --showduplicates
 已加载插件:fastestmirror, langpacks
 Loading mirror speeds from cached hostfile
  * base: mirrors.aliyun.com
  * extras: mirrors.aliyun.com
  * updates: mirrors.aliyun.com
 可安装的软件包
 httpd.x86_64                    2.4.6-95.el7.centos                      base   
 httpd.x86_64                    2.4.6-97.el7.centos                      updates
 httpd.x86_64                    2.4.6-97.el7.centos.1                    updates
 httpd.x86_64                    2.4.6-97.el7.centos.2                    updates
 httpd.x86_64                    2.4.6-97.el7.centos.4                    updates
 httpd.x86_64                    2.4.6-97.el7.centos.5                    updates
 httpd.x86_64                    2.4.6-98.el7.centos.6                    updates
 httpd.x86_64                    2.4.6-98.el7.centos.7                    updates
 httpd.x86_64                    2.4.6-99.el7.centos.1                    updates
 ​
 # 查看简介包含关键字的软件包
 [root@client ~ 15:40:21]# yum search 'web server'
 已加载插件:fastestmirror, langpacks
 Loading mirror speeds from cached hostfile
  * base: mirrors.aliyun.com
  * extras: mirrors.aliyun.com
  * updates: mirrors.aliyun.com
 ......
 # 查看描述和简介包含关键字的软件包
 [root@client ~ 15:41:33]# yum search all 'web server'
 已加载插件:fastestmirror, langpacks
 Loading mirror speeds from cached hostfile
  * base: mirrors.aliyun.com
  * extras: mirrors.aliyun.com
  * updates: mirrors.aliyun.com
 ......
 ​
 # 查看仓库中哪个包可以提供文件sar程序
 [root@client ~ 15:42:05]# yum provides sar
 已加载插件:fastestmirror, langpacks
 Loading mirror speeds from cached hostfile
  * base: mirrors.aliyun.com
  * extras: mirrors.aliyun.com
  * updates: mirrors.aliyun.com
 base/7/x86_64/filelists_db                               | 7.2 MB     00:01     
 epel/x86_64/filelists_db                                 |  15 MB     00:02     
 extras/7/x86_64/filelists_db                             | 305 kB     00:00     
 sysstat-10.1.5-19.el7.x86_64 : Collection of performance monitoring tools for
                              : Linux
 源    :base
 匹配来源:
 文件名    :/usr/bin/sar
 ​
 ​
 ​
 sysstat-10.1.5-20.el7_9.x86_64 : Collection of performance monitoring tools for
                                : Linux
 源    :updates
 匹配来源:
 文件名    :/usr/bin/sar
 ​
 ​
 ​
 sysstat-10.1.5-19.el7.x86_64 : Collection of performance monitoring tools for
                              : Linux
 源    :@anaconda
 匹配来源:
 文件名    :/usr/bin/sar
 ​
 # 安装sar工具对应的软件包
 [root@client ~ 15:42:17]# yum install -y sysstat
 ​
 # 只下载不安装
 [root@client ~ 15:43:31]# yum install vsftpd --downloadonly --downloaddir=/root/
 [root@client ~ 15:44:04]# ls vsftpd-*
 vsftpd-3.0.2-29.el7_9.x86_64.rpm
 ​
 # 安装本地文件系统中vsftpd包
 [root@client ~ 15:44:11]# yum localinstall ./vsftpd-3.0.2-29.el7_9.x86_64.rpm 
 ​
 # 降级vsftpd版本为3.0.2-28.el7
 [root@client ~ 15:45:12]# yum downgrade -y vsftpd-3.0.2-28.el7
 ​
 # 降级vsftpd版本为3.0.2-29.el7_9
 [root@client ~ 15:45:14]# yum update vsftpd-3.0.2-29.el7_9
 ​
 # 升级系统中所有软件为最新版本
 [root@client ~ 15:48:24]# yum update 
 ​
 # 卸载软件包
 [root@client ~ 15:49:17]# yum remove httpd
依赖降级示例
 # 环境准备:安装最新版httpd
 [root@server ~ 16:35:55]# yum install -y httpd
 ​
 # 降级到特定版本:降级失败,因为已安装的 httpd-tools 无法满足当前httpd版本
 [root@server ~ 16:37:31]# yum downgrade -y httpd-2.4.6-97.el7.centos 
 ​
  # 解决方法:httpd-tools与httpd一起降级到相同版本
  [root@server ~ 16:37:52]# yum downgrade -y httpd-tools-2.4.6-97.el7.centos httpd-2.4.6-97.el7.centos

软件包组管理

 # 查看仓库中软件包组清单
 [root@centos7 ~]# yum grouplist
 ......
 可用的环境分组:
    最小安装
    基础设施服务器
    ......
    带 GUI 的服务器
    GNOME 桌面
    KDE Plasma Workspaces
    开发及生成工作站
 可用组:
    Cinnamon
    Fedora Packager
    Haskell
    ......
    通用桌面
 完成
 ​
 [root@centos7 ~]# yum grouplist -v
 ......
 可用的环境分组:
    最小安装 (minimal)
    基础设施服务器 (infrastructure-server-environment)
    ......
    带 GUI 的服务器 (graphical-server-environment)
    GNOME 桌面 (gnome-desktop-environment)
    KDE Plasma Workspaces (kde-desktop-environment)
    开发及生成工作站 (developer-workstation-environment)
 可用组:
    Cinnamon (cinnamon-desktop)
    Fedora Packager (fedora-packager)
    Haskell (haskell)
    ......
    通用桌面 (general-desktop)
 完成
 ​
 [root@centos7 ~]# unset LANG
 [root@centos7 ~]# yum group list -v
 ......
 Available Environment Groups:
    Minimal Install (minimal)
    Compute Node (compute-node-environment)
    ......
    Server with GUI (graphical-server-environment)
    GNOME Desktop (gnome-desktop-environment)
    KDE Plasma Workspaces (kde-desktop-environment)
    Development and Creative Workstation (developer-workstation-environment)
 Available Groups:
    Cinnamon (cinnamon-desktop)
    Compatibility Libraries (compat-libraries)
    Console Internet Tools (console-internet)
    ......
    Xfce (xfce-desktop)
 Done
 ​
 # 查看仓库中软件包组信息
 [root@centos7 ~]# yum groupinfo <tab><tab>
 [root@centos7 ~]# yum groupinfo 'Server with GUI'
 ​
 # 安装仓库中软件包组
 [root@centos7 ~]# yum groupinstall 'Server with GUI'
 ​
 # 卸载仓库中软件包组
 [root@centos7 ~]# yum groupremove 'Server with GUI'

配置 yum 仓库

yum 仓库配置

yum 工具的配置文件是 /etc/yum/yum.conf,该文件包括两部分:

  • main,yum全局配置,提供每个仓库部分参数默认值。

  • 每个仓库的独立配置。

 [root@server ~ 16:41:37]# cat /etc/yum.conf
 [main]
 cachedir=/var/cache/yum/$basearch/$releasever
 keepcache=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
 ......

使用如下命令查看完整的配置内容:

 [root@server ~ 16:42:28]# yum install -y yum-utils
 [root@server ~ 16:42:33]# yum-config-manager
 =================================== main =====================================
 [main]
 ......
 cachedir = /var/cache/yum
 ......
 config_file_path = /etc/yum/yum.conf
 ......
 enabled = 1
 ......
 gpgcheck = 1
 ......
 keepcache = 0
 localpkg_gpgcheck = 0
 log_compress = 0
 log_rotate = 4
 log_size = 1048576
 logdir = /var/log
 logfilelevel = 9
 max_parallel_downloads = 3
 metadata_expire = 172800
 metadata_timer_sync = 10800
 ......
 protected_packages = yum, setup, yum, systemd, systemd-udev, yum, sudo, setup, yum, systemd, systemd-udev, yum, sudo
 ......
 repo_gpgcheck = 0
 reposdir = /etc/yum.repos.d, /etc/yum/repos.d, /etc/distro.repos.d
 ......

main 部分需要关注的参数:

  • enabled = 1,仓库默认启用。

  • gpgcheck = 1,仓库默认启用gpg校验。

  • keepcache = 0,不保存缓存。

  • cachedir = /var/cache/yum,缓存文件保存的位置。

  • reposdir = /etc/yum.repos.d, /etc/yum/repos.d, /etc/distro.repos.d,yum仓库配置文件。

yum管理的软件包存放在yum仓库,yum仓库配置文件存放在/etc/yum.repos.d目录。

 [root@server ~ 16:43:08]# ls /etc/yum.repos.d/
 CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo
 CentOS-CR.repo         CentOS-Media.repo      CentOS-x86_64-kernel.repo
 CentOS-Debuginfo.repo  CentOS-Sources.repo    epel.repo
 [root@server ~ 16:44:43]# ls  /etc/yum/repos.d /etc/distro.repos.d
 ls: 无法访问/etc/yum/repos.d: 没有那个文件或目录
 ls: 无法访问/etc/distro.repos.d: 没有那个文件或目录

yum 仓库管理

查看 yum 仓库
 # 查看yum仓库,默认不包括未启用的仓库
 [root@server ~ 16:44:47]# yum repolist
 # 查看yum所有仓库,包括未启用的仓库
 [root@server ~ 16:45:18]# yum repolist all
启用和禁用仓库
 [root@server ~ 16:46:08]# vim /etc/yum.repos.d/epel.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设置为1,设置为0禁用
 enabled=1
 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
仓库缓存管理
  • 更新缓存后,yum install命令可补全软件包名称。

 # 清理缓存数据
 [root@server ~ 16:46:32]# yum clean 
 all           dbcache       headers       packages      
 cache         expire-cache  metadata 
 # 清理所有缓存数据
 [root@server ~ 16:48:11]# yum clean all
 已加载插件:fastestmirror, langpacks
 正在清理软件源: base epel epel-debuginfo extras updates
 Cleaning up list of fastest mirrors
 ​
 # 创建缓存数据
 [root@server ~ 16:48:17]# yum makecache
 已加载插件:fastestmirror, langpacks
 Determining fastest mirrors
 .......

添加 kubernetes 仓库

 [root@server ~ 16:50:56]# yum-config-manager --add-repo=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
 ​
 [root@server ~ 16:50:56]# cat /etc/yum.repos.d/mirrors.aliyun.com_kubernetes_yum_repos_kubernetes-el7-x86_64_.repo 
 ​
 # 安装 kubectl 包
 [root@server ~ 16:51:37]# yum install kubectl --nogpgcheck
 ​

添加 docker-ce 仓库

[root@server ~ 16:54:09]#  cat << 'EOF' > /etc/yum.repos.d/docker-ce.repo
> [docker-ce-stable]
> name=Docker CE Stable - $basearch
> baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
> enabled=1
> gpgcheck=0
> EOF

# 查看docker版本
[root@server ~ 16:54:24]# yum list docker-ce
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
docker-ce-stable                                         | 3.5 kB     00:00     
(1/2): docker-ce-stable/7/x86_64/updateinfo                |   55 B   00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db                | 152 kB   00:01     
可安装的软件包
docker-ce.x86_64                 3:26.1.4-1.el7                 docker-ce-stable

epel 仓库

  • EPEL(Extra Packages for Enterprise Linux),是由Fedora Special Interest Group维护的Enterprise Linux(RHEL、CentOS)中经常用到的包。

 # 直接使用aliyun的源
 [root@server ~ 16:54:41]# curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

源码安装软件

源码安装 nginx
介绍

Nginx是一个高性能的HTTP和反向代理web服务器。

官方地址:https://nginx.org

 #将nginx-1.28.0.tar.gz拖入安装
 #查看
 [root@server ~ 17:11:12]# ls
 etc.tar.bz2      nginx-1.28.0.tar.gz
 ......
 #解压
 [root@server ~ 17:11:15]# tar -xf nginx-1.28.0.tar.gz 
 etc.tar.bz2      nginx-1.28.0         
 etc.tar.gz       nginx-1.28.0.tar.gz
 .......
 ​
 [root@server ~ 17:11:48]# cd nginx-1.28.0 
 [root@server nginx-1.28.0 17:12:09]# ls
 auto        CODE_OF_CONDUCT.md  contrib          LICENSE    SECURITY.md
 CHANGES     conf                CONTRIBUTING.md  man        src
 CHANGES.ru  configure           html             README.md
 ​
 #安装gcc
 [root@server 17:14:52]# yum install -y gcc
 # 安装依赖
 [root@centos7 ~]# yum install gcc make pcre-devel zlib-devel
 # 编译安装
 [root@server 17:24:32]# make && make install
 ​
 [root@server ~ 17:26:46]# ls /usr/local/nginx/
 conf  html  logs  sbin
 ​
 # 配置环境变量
 [root@server ~ 17:26:50]# cd nginx-1.28.0 
 [root@server nginx-1.28.0 17:27:34]# export PATH=$PATH:/usr/local/nginx/sbin/
 [root@server nginx-1.28.0 17:27:38]# echo 'export PATH=$PATH:/usr/local/nginx/sbin/' >> ~/.bashrc
 ​
 #使用
 #启动服务
 [root@server ~ 17:28:18]# nginx
 # 验证
 [root@server ~ 17:40:48]# systemctl daemon-reload
 [root@server ~ 17:40:48]# systemctl start nginx
 [root@server ~ 17:40:48]# systemctl status nginx.service
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值