您的位置:首页 > 运维架构 > Linux

linux软件包管理——YUM仓库配置与使用

2016-08-24 23:19 531 查看
在Linux下安装过软件软件的朋友都知道,rpm只能安装单一软件包,而且解决依赖问题相当麻烦,所以YUM软件包管理系统也就就应运而生了,但要想正常使用YUM,首先得了解YUM的工作原理,YUM是一个C/S(客户端/服务器)架构的包管理系统,必须配置好yum仓库服务器,然后在客户端上做好服务器的指向配置才能正常使用。当然如何把一个已经制作好的YUM仓库服务器共享出来那是属于搭建服务器的范畴,在这里我只是给大家分享一些关于YUM源的配置以及YUM客户端的使用。

一、YUM: Yellowdog Update Modifier
rpm的前端程序,用来解决软件包相关依赖性,可以在多个库之间定位软件包,安装或更新软件包的工具

二、yum源两大配置文件
(一)yum客户端配置文件:/etc/yum.conf(为所有仓库提供公共配置)
cachedir=/var/cache/yum/$basearch/$releasever yum本地缓存路径
keepcache=0是否保存缓存(0为禁用,1为禁用,下同)
debuglevel=2 调试级别
logfile=/var/log/yum.log yum安装日志保存路径
exactarch=1 是否检查平台版本
obsoletes=1 是否对过时版本的RPM进行更新
gpgcheck=1 是否检查完整性
plugins=1 是否启用插件
installonly_limit=5 并发安装的RPM包的上限
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum(BUG反馈中心)
distroverpkg=centos-release 指定一个软件包,yum会根据这个包判断你的发行版本,可以是安装的任何针对自己发行版的rpm包

(二)仓库指向配置文件:/etc/yum.repos.d/*.repo
[repository_name] 注意:[REPO_name]中不能有空格,否则报错
name=some description about repository 关于yum源的描述信息
baseurl= http:// web服务器仓库 ftp:// ftp服务器仓库
file:// 本地文件路径(包括光盘)
enabled={1|0} 是否启用 (启用为1,禁用为0,下同)
gpgcheck={1|0} 是否检查完整性
gpgkey=URL 密钥文件路径,如果启用检查完整性,就必须赋值
enablegroups={1|0} 是否开启包组
failovermethod={roundrobin|priority} 默认为:roundrobin,意为随机挑选yum仓库源
cost=1000 yum源优先级,默认1000,值越大,优先使用级越低

(三)yum的repo配置文件中可用的变量:
$releasever: 当前OS的发行版的主版本号
$arch: 平台,i386,i486,i586,x86_64等
$basearch:基础平台;i386
$YUM0-$YUM9:自定义变量

示例代码: http://server/centos/$releasever/$basearch/ 变量转换后:http://server/centos/7/x86_64
变量转换后:http://server/centos/6/i384

(四)手动创建yum仓库时生成仓库根目录配置文件命令:
createrepo [options] <directory>

三、YUM客户端的使用
1、显示仓库列表:
yum repolist [all|enabled|disabled] 可以查看所有的、启用的、禁用的

示例代码:
[root@centos7 test]# yum repolist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id repo name status
cdrom cdrom yum source 9,007
http http yum source 9,007
repolist: 18,014
[root@centos7 test]#

2、显示已启用的yum仓库里面的程序包:
yum list
yum list [all | glob_exp1] [glob_exp2] [...] 支持使用通配搜索所有程序包
yum list {available|installed|updates} [glob_exp1] [...]支持使用通配搜索所有(有效的、已安装的、可更新的)程序包

示例代码:
[root@centos7 test]# yum list httpd*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
httpd.x86_64 2.4.6-40.el7.centos cdrom
httpd-devel.x86_64 2.4.6-40.el7.centos cdrom
httpd-manual.noarch 2.4.6-40.el7.centos cdrom
httpd-tools.x86_64 2.4.6-40.el7.centos cdrom
[root@centos7 test]#

3、安装程序包:
yum install package1 [package2] [...]
yum reinstall package1 [package2] [...] 重新安装

示例代码:
[root@centos7 test]# yum install autofs.x86_64
Loaded plugins: fastestmirror, langpacks
cdrom
http
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autofs.x86_64 1:5.0.7-54.el7 will be instal
--> Processing Dependency: libhesiod.so.0()(64bit) for p
--> Running transaction check
---> Package hesiod.x86_64 0:3.2.1-3.el7 will be install
--> Finished Dependency Resolution

Dependencies Resolved

========================================================
Package Arch Ver
========================================================
Installing:
autofs x86_64 1:5
Installing for dependencies:
hesiod x86_64 3.2

Transaction Summary
========================================================
Install 1 Package (+1 Dependent package)

Total download size: 823 k
Installed size: 5.1 M
Is this ok [y/d/N]: y^CExiting on user command
Your transaction was saved, rerun it with:
yum load-transaction /tmp/yum_save_tx.2016-08-24.21-26.
[root@centos7 test]# cls
[root@centos7 test]# cls
[root@centos7 test]# yum install autofs.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package autofs.x86_64 1:5.0.7-54.el7 will be installed
--> Processing Dependency: libhesiod.so.0()(64bit) for package: 1:autofs-5.0.7-54.el7.x86_64
--> Running transaction check
---> Package hesiod.x86_64 0:3.2.1-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================
Package Arch Version Repository
Size
=======================================================
Installing:
autofs x86_64 1:5.0.7-54.el7 cdrom 794 k
Installing for dependencies:
hesiod x86_64 3.2.1-3.el7 cdrom 30 k

Transaction Summary
=======================================================
Install 1 Package (+1 Dependent package)

Total download size: 823 k
Installed size: 5.1 M
Is this ok [y/d/N]: y
Downloading packages:
-------------------------------------------------------
Total 2.1 MB/s | 823 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : hesiod-3.2.1-3.el7.x86_64 1/2
Installing : 1:autofs-5.0.7-54.el7.x86_64 2/2
Verifying : 1:autofs-5.0.7-54.el7.x86_64 1/2
Verifying : hesiod-3.2.1-3.el7.x86_64 2/2

Installed:
autofs.x86_64 1:5.0.7-54.el7

Dependency Installed:
hesiod.x86_64 0:3.2.1-3.el7

Complete!
[root@centos7 test]#

4、yum安装过程中的命令行选项:
--nogpgcheck:禁止进行gpg check
-y: 自动回答为“yes”
-q:静默模式
--disablerepo=repoidglob:临时禁用此处指定的repo
--enablerepo=repoidglob:临时启用此处指定的repo
--noplugins:禁用所有插件

5、查看程序包信息:
yum info package_name

示例代码:
[root@centos7 test]# yum info httpd.x86_64
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
Name : httpd
Arch : x86_64
Version : 2.4.6
Release : 40.el7.centos
Size : 2.7 M
Repo : base
Summary : Apache HTTP Server
URL : http://httpd.apache.org/ License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible web server.

6、查看指定的特性(可以是某文件)是由哪个程序包所提供:
yum provides | whatprovides feature1 [feature2][...]

示例代码:
[root@centos7 test]# yum provides autofs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
1:autofs-5.0.7-54.el7.x86_64 : A tool for automatically
...: mounting and unmounting filesystems
Repo : cdrom
1:autofs-5.0.7-54.el7.x86_64 : A tool for automatically
...: mounting and unmounting filesystems
Repo : http
1:autofs-5.0.7-54.el7.x86_64 : A tool for automatically
...: mounting and unmounting filesystems
Repo : @cdrom
[root@centos7 test]#

7、到yum仓库检查程序可用升级:
yum check-update

8、升级或阶级程序包:
yum update [package1] [package2] [...] 升级安装
yum downgrade package1 [package2] [...] 降级安装

9、卸载程序包:
yum remove | erase package1 [package2] [...]

示例代码:
[root@centos7 test]# yum remove tree
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================
Package Arch Version Repository Size
=======================================================
Removing:
tree x86_64 1.6.0-10.el7 installed 87 k

Transaction Summary
=======================================================
Remove 1 Package

Installed size: 87 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Removed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@centos7 test]#

10、清理本地yum缓存:
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]

11、创建本地yum缓存:
yum makecache

12、指定的关键字搜索程序包名及summary信息:
yum search string1 [string2] [...]

示例代码:
[root@centos7 test]# yum search ftp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
================================== N/S matched: ftp ===================================
ftp.x86_64 : The standard UNIX FTP (File Transfer Protocol) client
lftp-scripts.noarch : Scripts for lftp
syslinux-tftpboot.x86_64 : SYSLINUX modules in /var/lib/tftpboot, available for network
: booting
tftp.x86_64 : The client for the Trivial File Transfer Protocol (TFTP)
tftp-server.x86_64 : The server for the Trivial File Transfer Protocol (TFTP)
vsftpd.x86_64 : Very Secure Ftp Daemon
vsftpd-sysvinit.x86_64 : SysV initscript for vsftpd daemon
curl.x86_64 : A utility for getting files from remote servers (FTP, HTTP, and others)
lftp.i686 : A sophisticated file transfer program
lftp.x86_64 : A sophisticated file transfer program
wget.x86_64 : A utility for retrieving files using the HTTP or FTP protocols

Name and summary matches only, use "search all" for everything.
[root@centos7 test]#

13、查看指定包所依赖的capabilities:
yum deplist package1 [package2] [...]

示例代码:
[root@centos7 test]# yum deplist tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
package: tree.x86_64 1.6.0-10.el7
dependency: libc.so.6(GLIBC_2.14)(64bit)
provider: glibc.x86_64 2.17-105.el7
dependency: rtld(GNU_HASH)
provider: glibc.x86_64 2.17-105.el7
provider: glibc.i686 2.17-105.el7
package: tree.x86_64 1.6.0-10.el7
dependency: libc.so.6(GLIBC_2.14)(64bit)
provider: glibc.x86_64 2.17-105.el7
dependency: rtld(GNU_HASH)
provider: glibc.x86_64 2.17-105.el7
provider: glibc.i686 2.17-105.el7
[root@centos7 test]#

14、查看yum事务历史:
日志文件保存路径 :/var/log/yum.log
yum history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
yum history
yum history info 6 查看具体某项历史操作
yum history undo 6 撤消某项操作

示例代码:
[root@centos7 test]# yum history
Loaded plugins: fastestmirror, langpacks
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
5 | <root> | 2016-08-24 21:32 | Erase | 1
4 | <root> | 2016-08-24 21:27 | Install | 2
3 | <root> | 2016-08-22 17:29 | Install | 3
2 | <root> | 2016-08-22 15:22 | Install | 52 <
1 | System <unset> | 2016-07-21 12:17 | Install | 1243 >
history list
[root@centos7 test]# yum history info 5
Loaded plugins: fastestmirror, langpacks
Transaction ID : 5
Begin time : Wed Aug 24 21:32:39 2016
Begin rpmdb : 1306:d11bc5d2be008a4ef6a4b40725e4d041e93aac8d
End time : 21:32:40 2016 (1 seconds)
End rpmdb : 1305:bd2b79ace3e7148c8285452fabcf96d1248d19fe
User : hacker,10,183530300 <root>
Return-Code : Success
Command Line : remove tree
Transaction performed with:
Installed rpm-4.11.3-17.el7.x86_64 @anaconda
Installed yum-3.4.3-132.el7.centos.0.1.noarch @anaconda
Installed yum-plugin-fastestmirror-1.1.31-34.el7.noarch @anaconda
Packages Altered:
Loading mirror speeds from cached hostfile
Erase tree-1.6.0-10.el7.x86_64 @?cdrom
history info
[root@centos7 test]# yum history undo 5
Loaded plugins: fastestmirror, langpacks
Undoing transaction 5, from Wed Aug 24 21:32:39 2016
Loading mirror speeds from cached hostfile
Erase tree-1.6.0-10.el7.x86_64 @?cdrom
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================
Package Arch Version Repository Size
=======================================================================================
Installing:
tree x86_64 1.6.0-10.el7 cdrom 46 k

Transaction Summary
=======================================================================================
Install 1 Package

Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
Installed:
tree.x86_64 0:1.6.0-10.el7
Complete!
[root@centos7 test]#

15、安装及升级本地程序包:
yum localinstall rpmfile1 [rpmfile2] [...] 可用install替代
yum localupdate rpmfile1 [rpmfile2] [...] 可用update替代

16、包组管理的相关命令:
yum grouplist [hidden] [groupwildcard] [...] 查看YUM源里面包组列表(支持通配符)
yum groupinfo group1 [...] 查看YUM源里面指定包组的信息
yum groupinstall group1 [group2] [...] 使用YUM安装包组
yum groupupdate group1 [group2] [...] 使用YUM升级包组
yum groupremove group1 [group2] [...] 使用YUM卸载包组

示例代码
[root@centos7 test]# yum grouplist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Installed Groups:
Development Tools
Available Groups:
Compatibility Libraries
Console Internet Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
[root@centos7 test]#

四、YUM仓库配置实例:
使用光盘创建本地yum仓库:
(1) 挂载光盘至/media/cdrom目录
mount /dev/cdrom /media/cdrom
(2) 编辑/etc/yum.repos.d/base.repo配置文件
[cdrom]
name=cdrom yum source
baseurl=file:///media
enabled=1
gpgcheck=0
gpgkey=file:///media/cdrom/RPM-GPG-KEY-CentOS-7
(3)使用yum repolist验证是否添加正确
(4)使用yum list查看光盘yum源里面的安装包
学到这里的同时,你已经可以使用自己配置的光盘YUM源去解决一些常用软件的依赖性问题,如果是在实际生产环境中,要想方便的使用,最好把你需要用到的安装包下载到一个专业的包目录,然后使用手动创建yum仓库时生成仓库根目录配置文件命令createrepo,制作一个仓库信息配置文件,再把自己的包目录通过http或者ftp方式共享出去,别人就可以通过网络使用你的YUM仓库服务器了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  配置文件 yum