Redhat rpm常用命令以及如何配置yum软件仓库使用yum install

一、RPM(红帽软件包管理器)

在 RPM(红帽软件包管理器)公布之前,要想在 Linux 系统中安装软件只能采取源码包的方式安装。早期在 Linux 系统中安装程序是一件非常困难、耗费耐心的事情,而且大多数的服务程序仅仅提供源代码,需要运维人员自行编译代码并解决许多的软件依赖关系,因此要安装好一个服务程序,运维人员需要具备丰富知识、高超的技能,甚至良好的耐心。而且在安装、升级、卸载服务程序时还要考虑到其他程序、库的依赖关系,所以在进行校验、安装、卸载、查询、升级等管理软件操作时难度都非常大。

RPM 机制则为解决这些问题而设计的。 RPM 有点像 Windows 系统中的控制面板,会建立统一的数据库文件,详细记录软件信息并能够自动分析依赖关系。目前 RPM 的优势已经被公众所认可,使用范围也已不局限在红帽系统中了。下面是一些常用的 RPM 软件包命令,当前不需要记住它们,大致混个“脸熟”就足够了。

常用的 RPM 软件包命令:

  • 安装软件的命令格式 rpm -ivh filename.rpm
  • 升级软件的命令格式 rpm -Uvh filename.rpm
  • 卸载软件的命令格式 rpm -e filename.rpm
  • 查询软件描述信息的命令格式 rpm -qpi filename.rpm
  • 列出软件文件信息的命令格式 rpm -qpl filename.rpm
  • 查询文件属于哪个 RPM 的命令格式 rpm -qf filename

二、Yum 软件仓库简介

尽管 RPM 能够帮助用户查询软件相关的依赖关系,但问题还是要运维人员自己来解决,而有些大型软件可能与数十个程序都有依赖关系,在这种情况下安装软件会是非常痛苦的。Yum 软件仓库便是为了进一步降低软件安装难度和复杂度而设计的技术。 Yum 软件仓库可以根据用户的要求分析出所需软件包及其相关的依赖关系,然后自动从服务器下载软件包并安装到系统。

Yum 软件仓库中的 RPM 软件包可以是由红帽官方发布的,也可以是第三方发布的,当然也可以是自己编写的。

20221221121937

常见的 Yum 命令:

  • yum repolist all 列出所有仓库
  • yum list all 列出仓库中所有软件包
  • yum info 查看软件包信息
  • yum install 安装软件包
  • yum reinstall 重新安装软件包
  • yum update 升级软件包
  • yum remove 移除软件包
  • yum clean all 清除所有仓库缓存
  • yum check-update 检查可更新的软件包
  • yum grouplist 查看系统中已经安装的软件包组
  • yum groupinstall 安装指定的软件包组
  • yum groupremove 移除指定的软件包组
  • yum groupinfo 查询指定的软件包组信息

三、注册Red Hat开发者

Red Hat Enterprise Linux(RHEL)是收费的,如果不买订阅将无法试用yum软件仓库,安装软件的时候多有不便。

  1. 第一个办法,最简单,使用CentOS。

    现在分CentOS Linux版和CentOS Stream版,简单理解就是以前的CentOS Linux版发布根据RHEL更新的内容进行更新并修复其中可能的漏洞,比RHEL要晚,缺点是补丁更新慢,可能安全性差一点,好处是稳定性强一点。而现在的CentOS Stream版似乎成了RHEL的试验场,新东西新想法都是先在CentOS Stream版上发布然后再到RHEL。

  2. 第二个办法,注册红帽的开发者订阅

    subscription-manager register --username <username> --password <password> --auto-attach
    

    20221221150237

    20221221150250

四、配置 Yum 软件仓库

如果系统原有的repo不能用的话,可以自己进行配置。

  1. 进入到/etc/yum.repos.d/目录中(因为该目录存放着 Yum 软件仓库的配置文件)

  2. 使用 Vim 编辑器创建一个名为 rhel7.repo 的新配置文件(文件名称可随意,但后
    缀必须为.repo),逐项写入下面加粗的配置参数并保存退出(不要写后面的中文注释)。

    • [rhel-media] : Yum 软件仓库唯一标识符,避免与其他仓库冲突。

    • name=Extra Packages for Enterprise Linux 7 - $basearch
      软件仓库的名称描述,易于识别仓库用处。

    • baseurl=http://mirrors.aliyun.com/epel/7/$basearch
      提供的方式包括 FTP( ftp://…)、 HTTP( http://…)、本地
      ( file:///…)。

    • enabled=1
      设置此源是否可用; 1 为可用, 0 为禁用

    • gpgcheck=0
      设置此源是否校验文件; 1 为校验, 0 为不校验

    • gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
      若上面参数开启校验,那么请指定公钥文件地址

这里有两个老早以前的repo,刚试了下还能用,直接将这两个文件拷贝到/etc/yum.repos.d/目录下即可。如果不能用的话,可以自己在网上找找其他的repo。

20221221151259

elrepo.repo

### Name: ELRepo.org Community Enterprise Linux Repository for el7
### URL: http://elrepo.org/

[elrepo]
name=ELRepo.org Community Enterprise Linux Repository - el7
baseurl=http://elrepo.org/linux/elrepo/el7/$basearch/
	http://mirrors.coreix.net/elrepo/elrepo/el7/$basearch/
	http://mirror.rackspace.com/elrepo/elrepo/el7/$basearch/
	http://repos.lax-noc.com/elrepo/elrepo/el7/$basearch/
	http://mirror.ventraip.net.au/elrepo/elrepo/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo.el7
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0

[elrepo-testing]
name=ELRepo.org Community Enterprise Linux Testing Repository - el7
baseurl=http://elrepo.org/linux/testing/el7/$basearch/
	http://mirrors.coreix.net/elrepo/testing/el7/$basearch/
	http://mirror.rackspace.com/elrepo/testing/el7/$basearch/
	http://repos.lax-noc.com/elrepo/testing/el7/$basearch/
	http://mirror.ventraip.net.au/elrepo/testing/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-testing.el7
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0

[elrepo-kernel]
name=ELRepo.org Community Enterprise Linux Kernel Repository - el7
baseurl=http://elrepo.org/linux/kernel/el7/$basearch/
	http://mirrors.coreix.net/elrepo/kernel/el7/$basearch/
	http://mirror.rackspace.com/elrepo/kernel/el7/$basearch/
	http://repos.lax-noc.com/elrepo/kernel/el7/$basearch/
	http://mirror.ventraip.net.au/elrepo/kernel/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-kernel.el7
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0

[elrepo-extras]
name=ELRepo.org Community Enterprise Linux Extras Repository - el7
baseurl=http://elrepo.org/linux/extras/el7/$basearch/
	http://mirrors.coreix.net/elrepo/extras/el7/$basearch/
	http://mirror.rackspace.com/elrepo/extras/el7/$basearch/
	http://repos.lax-noc.com/elrepo/extras/el7/$basearch/
	http://mirror.ventraip.net.au/elrepo/extras/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-extras.el7
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0

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=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

现在试下通过yum install能不能正常下载安装吧,我这里下载并安装了python3,可以正常安装。
20221221151444

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Redhat 使用CentOS的yum源进行升级或软件安装 分类: linux 2012-07-19 15:54 1113人阅读 评论(0) 收藏 举报 Redhat默认的源不但速度不给力,而且软件版本陈旧,今天试着将Redhat默认源替换为CentOS的163源,发现速度能达到2M/s左右,而且版本都比较新,非常给力,与大家分享! (目前可以使用CentOS0-6.3软件仓库软件) 1. 删除原有的yum源 1. # rpm -aq | grep yum|xargs rpm -e --nodeps 2.下载新的yum安装包,这里使用centos-6.3 1. # wget http://mirror.centos.org/centos/6.3/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm 2. # wget http://mirror.centos.org/centos/6.3/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm 3. # wget http://mirror.centos.org/centos/6.3/os/x86_64/Packages/yum-3.2.29-30.el6.centos.noarch.rpm 4. # wget http://mirror.centos.org/centos/6.3/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm 3.安装yum软件包 1. #rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm 2. # rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm 3. #rpm -ivh yum-3.2.29-30.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm 4. 更改yum源 在/etc/yum.repos.d/新建文件centos.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-6 - Base - 163.com baseurl=http://mirrors.163.com/centos/6/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-6 - Updates - 163.com baseurl=http://mirrors.163.com/centos/6/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-6 - Extras - 163.com baseurl=http://mirrors.163.com/centos/6/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-6 - Plus - 163.com baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #contrib - packages by Centos Users [contrib] name=CentOS-6 - Contrib - 163.com baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 5.清理yum缓存 1. # yum clean all 2. # yum makecache #将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度 3. # yum install software_name #测试新源是否可用 6.更新系统 #yum update -y # yum install nginx chkconfig --level 345 nginx on /etc/init.d/nginx start yum --enablerepo=remi install php php-fpm chkconfig --level 345 php-fpm on /etc/init.d/php-fpm restart vi /etc/nginx/nginx.conf /etc/init.d/nginx reload vi /usr/share/nginx/html/info.php 1.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

smart_cat

你的鼓励将是我写作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值