博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
RHEL6基础二十二之RHEL软件包管理②yum
阅读量:7199 次
发布时间:2019-06-29

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

YUM介绍和配置本地YUM源

简介

yum(全称为 Yellow dog Updater, Modified)是一个Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,并且可以同时配置多个资源库Repository(/etc/yum.repo.d目录下),全局配置文件(/etc/yum.conf)简洁,使用起来很方便。

常用命令组合

yum check-update 检查可更新包

yum update 更新所有包

yum update kernel 更新指定包:kernel

yum install httpd 安装指定软件

yum -y install httpd

yum remove httpd 删除软件apache

yum info packagename 获取软件包信息

yum provides filename查看特定文件属于哪个软件包 

eg:查询semanage命令对应的软件包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@Zabbix_server ~]
# semanage
-
bash
/usr/sbin/semanage
: No such 
file 
or directory
[root@Zabbix_server ~]
# yum provides /usr/sbin/semanage
Loaded plugins: fastestmirror, product-
id
, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
policycoreutils-python-2.0.83-19.39.el6.i686 : SELinux policy core python utilities
Repo        : base
Matched from:
Filename    : 
/usr/sbin/semanage
[root@Zabbix_server ~]
# yum install -y policycoreutils-python 
[root@Zabbix_server ~]
# which semanage
/usr/sbin/semanage
[root@Zabbix_server ~]
# rpm -qf /usr/sbin/semanage 
policycoreutils-python-2.0.83-19.39.el6.i686
[root@Zabbix_server ~]
#

yum缓存(/var/cache/yum/)的相关参数

yum clean packages  清除暂存中rpm包文件

yum clearn headers  清除暂存中rpm头文件
yum clean oldheaders  清除暂存中旧的rpm头文件
yum clearn 或#yum clearn all  清除暂存中旧的rpm头文件和包文件(相当于yum clean packages + yum clean oldheaders
包列表相关参数
yum list  列出资源库中所有可以安装或更新的rpm包

yum list mozilla  列出资源库中特定的可以安装或更新以及已经安装的rpm包

yum list mozilla*

yum list updates  列出资源库中所有可以更新的rpm包

yum list installed  列出已经安装的所有的rpm包

yum grouplist 查找组列表

yum groupinstall "Games and Entertainment"  安装特定的组包,名字必须用双引号选定

rpm包信息显示(info参数同list)

yum info  列出资源库中所有可以安装或更新的rpm包的信息

yum info mozilla  列出资源库中特定的可以安装或更新以及已经安装的rpm包的信息

yum info mozilla*  可以在rpm包名中使用匹配符,如列出所有以mozilla开头的rpm包的信息

yum info updates  列出资源库中所有可以更新的rpm包的信息

yum info installed  列出已经安装的所有的rpm包的信息
搜索rpm包
yum search mozilla  搜索匹配特定字符的rpm包
yum provides realplay  搜索有包含特定文件名的rpm包

配置文件

yum的配置文件分为两部分:main和repository
main部分定义了全局配置选项,整个yum配置文件应该只有一个main。常位于/etc/yum.conf中。
repository部分定义了每个源/服务器的具体配置,可以有一到多个。常位于/etc/yum.repo.d目录下的各文件中。

/etc/yum.conf

cachedir=/var/cache/yum/$basearch/$releasever

            yum下载文件的存放位置

keepcache=1 

               设置是否,保存1为保存 0为不保存

metadata_expire=1800

                设置过期时间

pkgpolicy=newest
一共有两个选项,newest和last,这个作用是如果你设置了多个repository,而同一软件在不同的repository中同 时存 在,yum应该安装哪一个,如果是newest,则yum会安装最新的那个版本。如果是last,则yum会将服务器id以字母表排序,并选择最后的那个 服务器上的软件安装。一般都是选newest。

tolerant=1
如果值为1,则yum会忽略任何的有关包的错误。举例来说,当执行yum来安装baz时,如果baz包已经安装在系统中了,则yum会继续重复安装baz,而不会报错。默认值为1。
exactarch=1
设置为1,则yum只会安装和系统架构匹配的软件包,例如,yum不会将i686的软件包安装在适合i386的系统中。默认为1

/etc/yum.repo.d

在/etc/yum.repo.d目录下会发现一些后缀是.repo的文件,这些文件都是官方源的repo文件

1
2
3
[root@justin yum.repos.d]
# ls
packagekit-media.repo  rhel-
source
.repo
[root@justin yum.repos.d]
#

查看yum是否安装(RHEL6系列默认在安装系统时候就已经安装了)

1
2
3
[root@justin ~]
# rpm -q yum
yum-3.2.29-30.el6.noarch
[root@justin ~]
#

如果系统没有安装可以挂载安装盘手动安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@justin ~]
# mount /dev/cdrom /mnt/cdroom/
mount
: block device 
/dev/sr0 
is write-protected, mounting 
read
-only
[root@justin ~]
# cd /mnt/cdroom/Packages/
[root@justin Packages]
# ls | grep yum
anaconda-yum-plugins-1.0-5.1.el6.noarch.rpm
kabi-yum-plugins-1.0-2.el6.noarch.rpm
PackageKit-yum-0.5.8-20.el6.i686.rpm
PackageKit-yum-plugin-0.5.8-20.el6.i686.rpm
yum-3.2.29-30.el6.noarch.rpm
yum-metadata-parser-1.1.2-16.el6.i686.rpm
yum-plugin-aliases-1.1.30-14.el6.noarch.rpm
yum-plugin-changelog-1.1.30-14.el6.noarch.rpm
yum-plugin-downloadonly-1.1.30-14.el6.noarch.rpm
yum-plugin-security-1.1.30-14.el6.noarch.rpm
yum-plugin-tmprepo-1.1.30-14.el6.noarch.rpm
yum-plugin-verify-1.1.30-14.el6.noarch.rpm
yum-plugin-versionlock-1.1.30-14.el6.noarch.rpm
yum-presto-0.6.2-1.el6.noarch.rpm
yum-rhn-plugin-0.9.1-40.el6.noarch.rpm
yum-utils-1.1.30-14.el6.noarch.rpm
[root@justin Packages]
# rpm -ivh yum-3.2.29-30.el6.noarch.rpm

由于RHEL的yum在线更新是收费的,如果没有注册的话是不能使用的,即不能在线安装软件。在这种情况下,想使用RHEL系统,要么注册要么换用其他Yum源


RHEL配置本地Yum源

1
2
3
4
5
6
7
8
[root@justin yum.repos.d]
# yum install php
Loaded plugins: product-
id
, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Unable to 
read 
consumer identity
Setting up Install Process
No package php available.
Error: Nothing to 
do
[root@justin yum.repos.d]
#

挂载本地光盘

使用mount发现无法挂载,提示没有发现介质

1
2
[root@justin ~]
# mount /dev/cdrom /media/cdrom/
mount
: No medium found

查看VMware:VM---setting---Hardware---CD/DVD--右边Device里勾选Connected;Connection里Use ISO image file里选择iso文件后确定即可

配置本地yum源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@justin cdrom]rpm --
import 
RPM-GPG-KEY-redhat-legacy-release
[root@justin cdrom]rpm --
import 
RPM-GPG-KEY-redhat-beta
[root@justin cdrom]
# touch /etc/yum.repos.d/rhel-local.repo
[root@justin cdrom]
# vim /etc/yum.repos.d/rhel-local.repo
[rhel-
local
]
name=Red Hat Enterprise Linux 6.3
baseurl=
file
:
///mnt/cdrom
enabled=1
gpgcheck=1
gpgkey=
file
:
///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@justin cdrom]
# yum clean all
Loaded plugins: product-
id
, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Unable to 
read 
consumer identity
Cleaning repos: InstallMedia rhel-
local
Cleaning up Everything
[root@justin cdrom]
#yum makecache

[rhel-local]为库名称,在使用yum安装软件时显示仓库源时就是显示该项,而不是rhel-local.repo中的rhel-local;

如果要开启gpg验证,需要将光盘中自带的公钥RPM-GPG-KEY-redhat-legacy-release导入系统(通过rpm 导入系统后文件放在了/etc/pki/rpm-gpg/目录下),然后通过指定公钥地址 来和软件内部的私钥匹配,手动验证:rpm -K 软件全路径全称

1
2
3
4
5
6
7
8
9
10
[root@justin Packages]
# rpm -K zlib-devel-1.2.3-27.el6.i686.rpm
zlib-devel-1.2.3-27.el6.i686.rpm: RSA sha1 ((MD5) PGP) md5 NOT OK (MISSING KEYS: (MD5) PGP
#fd431d51)
[root@justin Packages]
# rpm -K zlib-devel
error: zlib-devel: 
open 
failed: No such 
file 
or directory
[root@justin Packages]
# cd
[root@justin ~]
# rpm -K zlib-devel-1.2.3-27.el6.i686.rpm
error: zlib-devel-1.2.3-27.el6.i686.rpm: 
open 
failed: No such 
file 
or directory
[root@justin ~]
# cd -
/media/Packages
[root@justin Packages]
#

使用yum时,首先搜索的是repodata文件,所以指定yum源路径时指定到repodata所在的目录即可,如果只有RPM软件包可以通过createrepo命令将一个包含RPM文件的文件夹转换为yum的仓库,也就是生成repodata文件,该命令默认未安装。

baseurl中指定本地文件路径时使用的file:///实为

enabled可不指定,默认为ebabled=1,即启用该库,0为不启用。

使用yum仓库出现的错误:nsufficient space in download directory /var/cache/yum/i386/6/c6-tong/packages

解决方法:

1
2
3
4
5
6
7
8
root@node1 ~]
# df -h      --查看磁盘空间,空间已满 
文件系统             容量  已用  可用 已用%% 挂载点 
/dev/mapper/VolGroup-lv_root
      
6.5G  6.1G    0 100% /      --根分区空间已满,清除文件 
tmpfs                504M    0  504M  0% 
/dev/shm
/dev/sda1            
485M  46M  414M  10% 
/boot
/dev/sr0              
3.6G  3.6G    0 100% 
/mnt
[root@node1 home]
#

清理磁盘空间,可以先使用yum clean all尝试、删除目录下安装包、扩充空间

使用yum安装软件包出现进程占用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@localhost src]
# yum grouplist
Loaded plugins: product-
id
, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Existing lock 
/var/run/yum
.pid: another copy is running as pid 2395.
Another app is currently holding the yum lock; waiting 
for 
it to 
exit
...
  
The other application is: PackageKit
    
Memory :  53 M RSS (374 MB VSZ)
    
Started: Mon Dec 14 18:08:43 2015 - 02:04 ago
    
State  : Sleeping, pid: 2395
Another app is currently holding the yum lock; waiting 
for 
it to 
exit
...
  
The other application is: PackageKit
    
Memory :  53 M RSS (374 MB VSZ)
    
Started: Mon Dec 14 18:08:43 2015 - 02:06 ago
    
State  : Sleeping, pid: 2395
Another app is currently holding the yum lock; waiting 
for 
it to 
exit
...

此时直接杀掉pid2395

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost src]
# ps -ef|grep 2395
root      2395  2393  0 18:08 ?        00:00:01 
/usr/bin/python 
/usr/share/PackageKit/helpers/yum/yumBackend
.py get-packages unknown
root      2427  2399  0 18:11 pts
/1    
00:00:00 
grep 
2395
[root@localhost src]
# kill -9 2395
[root@localhost src]
# yum grouplist
Loaded plugins: product-
id
, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Existing lock 
/var/run/yum
.pid: another copy is running as pid 2395.
Another app is currently holding the yum lock; waiting 
for 
it to 
exit
...
Another app is currently holding the yum lock; waiting 
for 
it to 
exit
...
Another app is currently holding the yum lock; waiting 
for 
it to 
exit
...
Another app is currently holding the yum lock; waiting 
for 
it to 
exit
...
[root@localhost src]
# ps -ef|grep 2395
root      2395  2393  0 18:08 ?        00:00:01 [yumBackend.py] <defunct>
root      2431  2399  0 18:11 pts
/1    
00:00:00 
grep 
2395
[root@localhost src]
#

直接杀进程啥不掉

1
2
3
4
5
6
7
8
[root@localhost src]
# rm -f /var/run/yum.pid 
[root@localhost src]
# yum grouplist
Loaded plugins: product-
id
, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Group Process
Installed Groups:
   
Additional Development
   
Base

此时可以通过强制关掉yum进程:rm -rf /var/run/yum.pid

本文转自 justin_peng 51CTO博客,原文链接:http://blog.51cto.com/ityunwei2017/1318617,如需转载请自行联系原作者

你可能感兴趣的文章
Windows Server 2008遗忘管理员密码后的解决方法
查看>>
传统电脑与终端机的区别优势
查看>>
"廖雪峰的Git教程"学习笔记
查看>>
mysql插入数据后返回自增ID的方法,last_insert_id(),selectkey
查看>>
sublime text 2 替换ue
查看>>
Android模拟器横屏切换方法
查看>>
使用node.js启动React
查看>>
python中time.time()和 time.strftime()
查看>>
Collection源码分析(八):Stack源码分析
查看>>
OK-在RedHat Server 5.5上使用163的源
查看>>
ibatIS中的isNotNull、isEqual、isEmpty
查看>>
组策略部署Bginfo
查看>>
黑盒测试方法揭密
查看>>
MongoDb Mmap引擎分析
查看>>
MBR详解
查看>>
mapreduce如何使用本地文件
查看>>
Takeown、Cacls、Icacls-文件、文件夹夺权用法
查看>>
centos7的新特性
查看>>
我的程序员之路(一)
查看>>
Spring事务管理(二) 声明式事务管理
查看>>