博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
rpm、yum工具、yum搭建本地仓库
阅读量:7021 次
发布时间:2019-06-28

本文共 11519 字,大约阅读时间需要 38 分钟。

hot3.png

安装软件包的三种方法:

  • rpm工具
  • yum工具
  • 源码包

rpm工具使用

  • 设置光驱并挂载
  • rpm包格式,包名、版本号、发布版本号、平台
  • rpm -ivh rpm包文件 //安装
  • rpm -Uvh rpm包文件 //升级
  • rpm -e 包名 //卸载
  • rpm -qa //查询安装的包
  • rpm -q 包名 //查询指定包是否安装
  • rpm -qi 包名 //查询指定包信息
  • rpm -ql 包名 //列出包安装的文件
  • rpm -qf 文件绝对路径 //查看一个文件是由哪个包安装的
  1. 设置光驱并挂载 1)点击--虚拟机—设置—CD/DVD(ide)--右边设置iso映像文件路径。115334_j4wG_3791387.png

    2)挂载光驱

[root@yong-02 ~]# mount /dev/cdrom /mntmount: /dev/sr0 写保护,将以只读方式挂载[root@yong-02 ~]# ls /mntCentOS_BuildTag  GPL       LiveOS    RPM-GPG-KEY-CentOS-7EFI              images    Packages  RPM-GPG-KEY-CentOS-Testing-7EULA             isolinux  repodata  TRANS.TBL###   /mnt/Packages目录里面是rpm包

 查看/mnt/Packages 里面的包前5个

[root@yong-02 Packages]# ls |head -5389-ds-base-1.3.6.1-16.el7.x86_64.rpm389-ds-base-libs-1.3.6.1-16.el7.x86_64.rpmabattis-cantarell-fonts-0.0.25-1.el7.noarch.rpmabrt-2.1.11-48.el7.centos.x86_64.rpmabrt-addon-ccpp-2.1.11-48.el7.centos.x86_64.rpm

小知识: 每个rpm包的名称都是由-和.分成若干部分,比如abrt-2.1.11-48.el7.centos.x86_64.rpm Abrt:包名

2.1.11-48:版本号;2为主版本号,1为次版本号,11为修正版本
48-el7.centos:发布版本号
x86_64.:运行平台,64位 cpu目前分32位和64位,i386、i586、i686是32位,X86_64是64位。
64位系统可以安装32位软件,但是32位系统不能安装64为软件。

安装rpm包

  • rpm -ivh rpm包文件 //安装
  • -i:表示安装
  • -v:表示可视化
  • -h:表示显示安装进度
  • --force:表示强制安装,即使覆盖属于其他包的文件也要安装
  • --nodeps:表示当要安装的rpm包依赖于其他包时,即使其他包没有安装,也要安装这个包
[root@yong-02 Packages]# rpm -ivh zip-3.0-11.el7.x86_64.rpm 准备中...                          ################################# [100%]	软件包 zip-3.0-11.el7.x86_64 已经安装

升级rpm包

  • 命令:rpm -Uvh rpm 包文件
  • -U:表示升级

卸载rpm包

  • 命令:rpm –e 包名
[root@yong-02 Packages]# rpm -e zip

查询一个包是否已经安装

  • 命令:rpm –q 包名
[root@yong-02 ~]# rpm -q vim-enhanced vim-enhanced-7.4.160-2.el7.x86_64

查询当前系统所有已经安装的包

  • 命令:rpm –qa
[root@yong-02 Packages]# rpm -qa |headlinux-firmware-20170606-56.gitc990aae.el7.noarchcentos-release-7-4.1708.el7.centos.x86_64kbd-1.15.5-13.el7.x86_64setup-2.8.71-7.el7.noarchopen-vm-tools-10.1.5-3.el7.x86_64basesystem-10.0-7.el7.centos.noarchkexec-tools-2.0.14-17.el7.x86_64bind-license-9.9.4-50.el7.noarchgrub2-2.02-0.64.el7.centos.x86_64firewalld-filesystem-0.4.4.4-6.el7.noarch

查询指定包的信息

  • 命令:rpm –qi 包名
[root@yong-02 Packages]# rpm -qi vim-enhanced Name        : vim-enhancedEpoch       : 2Version     : 7.4.160Release     : 2.el7Architecture: x86_64Install Date: 2018年03月12日 星期一 15时57分38秒Group       : Applications/EditorsSize        : 2292098License     : VimSignature   : RSA/SHA256, 2017年08月11日 星期五 04时15分38秒, Key ID 24c6a8a7f4a80eb5Source RPM  : vim-7.4.160-2.el7.src.rpmBuild Date  : 2017年08月02日 星期三 08时46分12秒Build Host  : c1bm.rdu2.centos.orgRelocations : (not relocatable)Packager    : CentOS BuildSystem 
Vendor : CentOSURL : http://www.vim.org/Summary : A version of the VIM editor which includes recent enhancementsDescription :VIM (VIsual editor iMproved) is an updated and improved version of thevi editor. Vi was the first real screen-based editor for UNIX, and isstill very popular. VIM improves on vi by adding new features:multiple windows, multi-level undo, block highlighting and more. Thevim-enhanced package contains a version of VIM with extra, recentlyintroduced features like Python and Perl interpreters.

列出一个rpm包的安装文件

  • 命令:rpm –ql 包名
[root@yong-02 Packages]# rpm -ql vim-enhanced /etc/profile.d/vim.csh/etc/profile.d/vim.sh/usr/bin/rvim/usr/bin/vim/usr/bin/vimdiff/usr/bin/vimtutor

根据一个文件的绝对路径,查看这个文件是由哪个包安装的

  • 命令:rpm –qf 绝对路径
[root@yong-02 Packages]# rpm -qf /usr/bin/cd bash-4.2.46-28.el7.x86_64
[root@yong-02 Packages]# rpm -qf `which cd`bash-4.2.46-28.el7.x86_64注意:``(esc下面那个键)里面which cd 显示只有一行,如果是which ls 显示2行,这里就不能使用这条命令。

Yum工具

Yum比rpm工具更方便,yum工具最大的优势在于可以联网去下载所需要的的rpm包,然后自动安装,安装所有相关的rpm包,解决依赖关系。

  • yum list //列出可用rpm包
  • ls /etc/yum.repos.d/
  • yum search vim //搜索包
  • yum install [-y]
  • yum grouplist
  • yum groupinstall [-y]
  • yum remove [-y]
  • yum update [-y]
  • yum provides “/*/vim”

列出所有可用的rpm包

  • 命令:yum list
[root@yong-02 Packages]# yum list |head -20已加载插件:fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.shu.edu.cn已安装的软件包GeoIP.x86_64                                1.5.0-11.el7               @anacondaNetworkManager.x86_64                       1:1.8.0-9.el7              @anacondaNetworkManager-libnm.x86_64                 1:1.8.0-9.el7              @anacondaNetworkManager-team.x86_64                  1:1.8.0-9.el7              @anacondaNetworkManager-tui.x86_64                   1:1.8.0-9.el7              @anacondaNetworkManager-wifi.x86_64                  1:1.8.0-9.el7              @anacondaacl.x86_64                                  2.2.51-12.el7              @anacondaaic94xx-firmware.noarch                     30-6.el7                   @anacondaalsa-firmware.noarch                        1.0.28-2.el7               @anacondaalsa-lib.x86_64                             1.1.3-3.el7                @anacondaalsa-tools-firmware.x86_64                  1.1.0-1.el7                @anacondaaudit.x86_64                                2.7.6-3.el7                @anacondaaudit-libs.x86_64                           2.7.6-3.el7                @anacondaauthconfig.x86_64                           6.2.8-30.el7               @anaconda

左边是包名,中间是版本信息,右边是仓库名,仓库这边显示@base、@anaconda表示已经安装。如果未安装这显示base或者anaconda,如果是updates表示已安装但是需要升级。

yum的配置文件:/etc/yum.repos.d/Centos-Base.repo 里面可以配置仓库名,yum源地址

[root@yong-02 Packages]# ls /etc/yum.repos.d/CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repoCentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo[root@yong-02 Packages]# cat /etc/yum.repos.d/CentOS-Base.repo # CentOS-Base.repo## The mirror system uses the connecting IP address of the client and the# update status of each mirror to pick mirrors that are updated to and# geographically close to the client.  You should use this for CentOS updates# unless you are manually picking other mirrors.## If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead.##[base]name=CentOS-$releasever - Basemirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#released updates [updates]name=CentOS-$releasever - Updatesmirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#additional packages that may be useful[extras]name=CentOS-$releasever - Extrasmirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages[centosplus]name=CentOS-$releasever - Plusmirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/gpgcheck=1enabled=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

name=CentOS-$releasever - Extras

mirrorlist=http://mirrorlist.centos.org/release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

搜索rpm包

  • 命令:yum search 包名
[root@yong-02 Packages]# yum search vim已加载插件:fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.shu.edu.cn================================= N/S matched: vim ==================================protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers                    : descriptionsvim-X11.x86_64 : The VIM version of the vi editor for the X Window Systemvim-common.x86_64 : The common files needed by any version of the VIM editorvim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancementsvim-filesystem.x86_64 : VIM filesystem layoutvim-minimal.x86_64 : A minimal version of the VIM editor  名称和简介匹配 only,使用“search all”试试。
  • 或者:yum list |grep 'vim'
[root@yong-02 Packages]# yum list |grep 'vim' vim-common.x86_64                           2:7.4.160-2.el7            @base    vim-enhanced.x86_64                         2:7.4.160-2.el7            @base    vim-filesystem.x86_64                       2:7.4.160-2.el7            @base    vim-minimal.x86_64                          2:7.4.160-2.el7            @anacondaprotobuf-vim.x86_64                         2.5.0-8.el7                base     vim-X11.x86_64                              2:7.4.160-2.el7            base

安装rpm包

  • 命令:yum install –y 包名
  • yum grouplist 列出可用组
  • yum groupinstall [-y] 安装组

列出套件

[root@yong-02 Packages]# yum grouplist已加载插件:fastestmirror没有安装组信息文件Maybe run: yum groups mark convert (see man yum)Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.tuna.tsinghua.edu.cn可用的环境分组:   最小安装   基础设施服务器   计算节点   文件及打印服务器   基本网页服务器   虚拟化主机   带 GUI 的服务器   GNOME 桌面   KDE Plasma Workspaces   开发及生成工作站可用组:   传统 UNIX 兼容性   兼容性程序库   图形管理工具   安全性工具   开发工具   控制台互联网工具   智能卡支持   科学记数法支持   系统管理   系统管理工具完成

LANG=en 切换英文

卸载rpm包 

yum remove [-y]

命令:yum remove –y  包名[root@yong-02 Packages]# yum remove vim 已加载插件:fastestmirror正在解决依赖关系--> 正在检查事务---> 软件包 vim-enhanced.x86_64.2.7.4.160-2.el7 将被 删除--> 解决依赖关系完成依赖关系解决===================================================================================== Package               架构            版本                     源              大小=====================================================================================正在删除: vim-enhanced          x86_64          2:7.4.160-2.el7          @base          2.2 M事务概要=====================================================================================移除  1 软件包安装大小:2.2 M是否继续?[y/N]:nExiting on user command您的事务已保存,请执行: yum load-transaction /tmp/yum_save_tx.2018-04-18.17-26.1qYdG1.yumtx 重新执行该事务

安装套件

  • 命令:yum groupinstall –y 套件名

升级rpm包

  • 命令:yum update –y 包名 注意:如果不加包名,会把系统所有的包包括系统本身升级。

搜索一个命令是哪个包安装的

  • 命令:yum provides "/*/vim"
  • 或者:rpm -qf /usr/bin/vim

使用本地光盘制作yum源

  • 挂载镜像到/mnt目录
[root@linux-128 ~]# mount /dev/cdrom /mntmount: /dev/sr0 写保护,将以只读方式挂载
  • cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
  • rm -f /etc/yum.repos.d/*
  • vim /etc/yum.repos.d/dvd.repo //内容如下

[dvd] //仓库名字

name=install dvd
baseurl=file:///mnt //本地源地址
enable=1 //本地是否可用,1可用,0不可以
gpgcheck=0 //是否检测,1检测,0不检测

  • yum clean all //清除缓存
  • yum list |tail 后十行可以看dvd 里面的包
[root@yong-02 yum.repos.d]# yum list |tailyum-plugin-changelog.noarch             1.1.31-42.el7                  dvd      yum-plugin-tmprepo.noarch               1.1.31-42.el7                  dvd      yum-plugin-verify.noarch                1.1.31-42.el7                  dvd      yum-plugin-versionlock.noarch           1.1.31-42.el7                  dvd      yum-utils.noarch                        1.1.31-42.el7                  dvd      zenity.x86_64                           3.22.0-1.el7                   dvd      zip.x86_64                              3.0-11.el7                     dvd      zlib-devel.x86_64                       1.2.7-17.el7                   dvd      zsh.x86_64                              5.0.2-28.el7                   dvd      zziplib.x86_64                          0.13.62-5.el7                  dvd

在安装软件时如果出现以下报错:

跑大量高负载程序,造成cpu soft lockup

 151903_iZ5a_3791387.png

解决方法 :1,echo 30 > /proc/sys/kernel/watchdog_thresh

                 2,sysctl -w kernel.watchdog_thresh=30

 

 

转载于:https://my.oschina.net/u/3791387/blog/1797120

你可能感兴趣的文章