012 软件包rpm、yum、本地&远程仓库搭建

rpm包来源

1、来源网络下载
2、来源本地:自己的镜像自带的rpm包
  • rpm命令

    # 安装
    
    rpm -ivh xxx.rpm
    
    # http://nginx.org/packages/centos/7/x86_64/RPMS/
    
    -v : 显示安装过程
    -i :显示安装包的详细信息
    -h : 安装包哈希标记
    
    # 下载Nginx rpm安装包的全名
    [root@localhost ~]# wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
    --2021-03-17 12:16:47--  http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.18.0-1.el7.ngx.x86_64.rpm
    Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...
    Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 790284 (772K) [application/x-redhat-package-manager]
    Saving to: ‘nginx-1.18.0-1.el7.ngx.x86_64.rpm’
    
    100%[====================================================>] 790,284      339KB/s   in 2.3s   
    
    2021-03-17 12:16:51 (339 KB/s) - ‘nginx-1.18.0-1.el7.ngx.x86_64.rpm’ saved [790284/790284]
    
    # 安装rpm安装包
    [root@localhost ~]# rpm -ivh nginx-1.18.0-1.el7.ngx.x86_64.rpm 
    warning: nginx-1.18.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:nginx-1:1.18.0-1.el7.ngx         ################################# [100%]
    ----------------------------------------------------------------------
    
    Thanks for using nginx!
    
    Please find the official documentation for nginx here:
    * http://nginx.org/en/docs/
    
    Please subscribe to nginx-announce mailing list to get
    the most important news about nginx:
    * http://nginx.org/en/support.html
    
    Commercial subscriptions for nginx are available on:
    * http://nginx.com/products/
    
    ----------------------------------------------------------------------
    
    # 验证nginx是否安装成功
    [root@localhost ~]# nginx -v
    nginx version: nginx/1.18.0
    
    
    # 卸载
    [root@localhost ~]# rpm -e nginx (软件包名称)
    [root@localhost ~]# nginx -v
    -bash: /usr/sbin/nginx: No such file or directory
    [root@localhost ~]# 
    
    
    # 查看系统当中安装了哪些rpm软件包
    rpm -qa
    
    # 查看系统当中是否安装了某个rpm软件包
    [root@localhost ~]# rpm -q nginx(软件包名)
    nginx-1.18.0-1.el7.ngx.x86_64
    [root@localhost ~]# rpm -q safsdgsfdgfd
    package safsdgsfdgfd is not installed
    
    
    # 显示已经安装过的rpm包详细信息。
    [root@localhost ~]# rpm -qi nginx
    Name        : nginx
    Epoch       : 1
    Version     : 1.18.0
    Release     : 1.el7.ngx
    Architecture: x86_64
    Install Date: Wed 17 Mar 2021 04:18:55 PM CST
    Group       : System Environment/Daemons
    Size        : 2830028
    License     : 2-clause BSD-like license
    Signature   : RSA/SHA1, Tue 21 Apr 2020 11:19:18 PM CST, Key ID abf5bd827bd9bf62
    Source RPM  : nginx-1.18.0-1.el7.ngx.src.rpm
    Build Date  : Tue 21 Apr 2020 11:07:33 PM CST
    Build Host  : ip-10-1-17-101.eu-central-1.compute.internal
    Relocations : (not relocatable)
    Vendor      : Nginx, Inc.
    URL         : http://nginx.org/
    Summary     : High performance web server
    Description :
    nginx [engine x] is an HTTP and reverse proxy server, as well as
    a mail proxy server.
    
    # 查看安装包的内容
    [root@localhost nginx]# rpm -ql nginx
    /etc/logrotate.d/nginx
    /etc/nginx
    /etc/nginx/conf.d
    /etc/nginx/conf.d/default.conf
    /etc/nginx/fastcgi_params
    /etc/nginx/koi-utf
    /etc/nginx/koi-win
    /etc/nginx/mime.types
    /etc/nginx/modules
    /etc/nginx/nginx.conf
    /etc/nginx/scgi_params
    /etc/nginx/uwsgi_params
    /etc/nginx/win-utf
    /etc/sysconfig/nginx
    /etc/sysconfig/nginx-debug
    /usr/lib/systemd/system/nginx-debug.service
    /usr/lib/systemd/system/nginx.service
    /usr/lib64/nginx
    /usr/lib64/nginx/modules
    /usr/libexec/initscripts/legacy-actions/nginx
    /usr/libexec/initscripts/legacy-actions/nginx/check-reload
    /usr/libexec/initscripts/legacy-actions/nginx/upgrade
    /usr/sbin/nginx
    /usr/sbin/nginx-debug
    /usr/share/doc/nginx-1.18.0
    /usr/share/doc/nginx-1.18.0/COPYRIGHT
    /usr/share/man/man8/nginx.8.gz
    /usr/share/nginx
    /usr/share/nginx/html
    /usr/share/nginx/html/50x.html
    /usr/share/nginx/html/index.html
    /var/cache/nginx
    /var/log/nginx
    
    # 查看配置信息
    [root@localhost nginx]# rpm -qc nginx
    /etc/logrotate.d/nginx
    /etc/nginx/conf.d/default.conf
    /etc/nginx/fastcgi_params
    /etc/nginx/koi-utf
    /etc/nginx/koi-win
    /etc/nginx/mime.types
    /etc/nginx/nginx.conf
    /etc/nginx/scgi_params
    /etc/nginx/uwsgi_params
    /etc/nginx/win-utf
    /etc/sysconfig/nginx
    /etc/sysconfig/nginx-debug
    
    # 查看文件帮助信息
    [root@localhost nginx]# rpm -qd zlib
    /usr/share/doc/zlib-1.2.7/ChangeLog
    /usr/share/doc/zlib-1.2.7/FAQ
    /usr/share/doc/zlib-1.2.7/README
    
    # 
    [root@localhost ~]# rpm -qf /usr/sbin/nginx
    nginx-1.18.0-1.el7.ngx.x86_64
    
    # 用 -p 可以查看未安装软件包的详细信息
    [root@localhost ~]# rpm -qip nginx-1.18.0-1.el7.ngx.x86_64.rpm 
    warning: nginx-1.18.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
    Name        : nginx
    Epoch       : 1
    Version     : 1.18.0
    Release     : 1.el7.ngx
    Architecture: x86_64
    Install Date: (not installed)
    Group       : System Environment/Daemons
    Size        : 2830028
    License     : 2-clause BSD-like license
    Signature   : RSA/SHA1, Tue 21 Apr 2020 11:19:18 PM CST, Key ID abf5bd827bd9bf62
    Source RPM  : nginx-1.18.0-1.el7.ngx.src.rpm
    Build Date  : Tue 21 Apr 2020 11:07:33 PM CST
    Build Host  : ip-10-1-17-101.eu-central-1.compute.internal
    Relocations : (not relocatable)
    Vendor      : Nginx, Inc.
    URL         : http://nginx.org/
    Summary     : High performance web server
    Description :
    nginx [engine x] is an HTTP and reverse proxy server, as well as
    a mail proxy server.
    
    # 升级软件包
    [root@localhost ~]# rpm -Uvh nginx-1.18.0-1.el7.ngx.x86_64.rpm 
    warning: nginx-1.18.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:nginx-1:1.18.0-1.el7.ngx         ################################# [ 50%]
    Cleaning up / removing...
       2:nginx-1:1.14.0-1.el7_4.ngx       ################################# [100%]
    [root@localhost ~]# nginx -v
    nginx version: nginx/1.18.0
    
    
    # 强制删除软件包--nodeps
    [root@localhost ~]# rpm -e zlib --nodeps
    
    

yum

yum是CentOS的软件包管理工具,自动为我们解决软件依赖问题。yum包管理工具必须使用yum源指定软件下载地址去下载需要安装的软件包。配置的路径是:/etc/yum.repos.d

# 清空本机所有的yum源
[root@www yum.repos.d]# rm -rf /etc/yum.repos.d/*
  • yum源命令

    # 查看当前系统的yum源列表
    [root@www yum.repos.d]# yum repolist 
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                   repo name                                           status
    base                      "This is local repo, and 非常屌"                    10,072
    repolist: 10,072
    
    # yum清空缓存
    [root@www yum.repos.d]# yum clean all
    Loaded plugins: fastestmirror
    Cleaning repos: base
    Cleaning up list of fastest mirrors
    Other repos take up 76 M of disk space (use --verbose for details)
    
    # 建立yum缓存
    [root@www yum.repos.d]# yum makecache
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    
    
  • yum源的执行原理

    1、需要在/etc/yum.repos.d目录下配置yum源地址
    2、清空缓存建立新的缓存
    3、安装软件(自动解决依赖关系)
    
  • yum常用的基础命令

    # 安装软件包的命令
    yum install 软件包名称
    	-y : 免交互安装
    
    # 卸载软件(直接将软件的依赖包一起删除)
    yum remove 软件包名称
    [root@www yum.repos.d]# yum remove httpd
    	-y : 免交互移除
    
    # 查看当前系统需要更新软件
    yum check-update
    
    # 更新所有的需要更新的软件
    yum update 
    	-y : 免交互
    
    # 更新某一个软件
    yum update (软件包名称)
    
    # 重装软件
    yum reinstall (软件包名称)
    
    # 搜索软件包
    [root@www httpd]# yum search (软件包名称)
    -------------------------------------------------------
    
    # 查看yum执行历史
    yum history
    [root@www httpd]# yum history info (历史ID号)
    [root@www httpd]# yum history undo (历史ID号)
    # 查看当前系统当中可更新的软件包
    [root@www yum.repos.d]# yum check-update 
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    
    postfix.x86_64                                        2:2.10.1-9.0.1.el7.centos.plus                                      centosplus
    python-perf.x86_64                                    3.10.0-1160.15.2.el7.centos.plus                                    centosplus
    [root@www yum.repos.d]# 
    
    # 查看系统中有哪些仓库地址
    yum repolist    # 正在启用的yum仓库
    [root@www yum.repos.d]# yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                   repo name                                           status
    base/7/x86_64             CentOS-7 - Base - repo.huaweicloud.com              10,072
    extras/7/x86_64           CentOS-7 - Extras - repo.huaweicloud.com               453
    updates/7/x86_64          CentOS-7 - Updates - repo.huaweicloud.com            1,729
    
    yum repolist all # 查看系统中所有的yum仓库
    [root@www yum.repos.d]# yum repolist all
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    repo id                                        repo name                                                             status
    base/7/x86_64                                  CentOS-7 - Base - repo.huaweicloud.com                                enabled: 10,072
    centosplus/7/x86_64                            CentOS-7 - Plus - repo.huaweicloud.com                                disabled
    extras/7/x86_64                                CentOS-7 - Extras - repo.huaweicloud.com                              enabled:    453
    updates/7/x86_64                               CentOS-7 - Updates - repo.huaweicloud.com                             enabled:  1,72
    
    
    # 启用repo仓库
    yum install yum-utils -y
    
    启用一个yum仓库:yum-config-manager --enable (仓库名称)
    关闭一个yum仓库:yum-config-manager --disable (仓库名称)
    
    
    # 查看一个仓库中的软件包列表
    [root@www yum.repos.d]# yum list
    
    # 查看软件包组
    [root@www yum.repos.d]# yum grouplist
    
    # 安装软件包组
    [root@www yum.repos.d]# yum groupinstall "Development Tools"
    
    
    
  • 本地yum源配置

    1、备份/etc/yum.repos.d/下的所文件
    	rm -rf /etc/yum.repos.d/*
    
    2、编写本地yum源
    [root@www yum.repos.d]# cat test.repo 
    [base] # yum源名称
    name="This is repo infomation" #yum源的简介
    baseurl=file:///opt    # 指定yum源地址
    enabled=1				# 是否启用yum源
    gpgcheck=0				# 是否检查gpg秘钥
    
    3、更新缓存
    yum makecache
    
    4、安装软件
    yum install dos2unix
    

    本地&远程仓库搭建

本地&远程仓库搭建

原文地址:https://www.cnblogs.com/zhaokunhao/p/14554172.html