您的位置:首页 > 其它

23. 文件系统――使用yum安装软件包

2015-02-25 08:44 323 查看
一、yum命令的基本安装功能[root@localhost ~]# man yumcommand is one of: * install package1 [package2] [...]: install + 包名yum -y: 安装时自动回答为yes * reinstall package1 [package2] [...]: 重新安装 *** 补充rmp命令:rpm -ql + 包名 : 查询包安装生成的文件清单 rpm -qf + /path/to/file_name: 查询某文件是由哪个软件包生成的* provides | whatprovides feature1 [feature2] [...]使用yum来查询软件包生成哪些文件,以及文件是由哪个软件包生成的。 * update [package1] [package2] [...]: 升级版本,可加多个包* update-to [package1] [package2] [...]: 指定升级到哪个版本
* downgrade package1 [package2] [...] : 降级 * check-update: 安装前检查有哪些可以升级的软件包 * upgrade [package1] [package2] [...]* upgrade-to [package1] [package2] [...] 这两个命令已经被update取代了 * remove | erase package1 [package2] [...] 清除软件包:使用yum来清除包会同时清除它被依赖的包
* search string1 [string2] [...] : 只记得部分字符,可以进行模糊查询 * groupinstall group1 [group2] [...] :组安装: 1) 针对RHEL 6: Development tools + Server Platform Development + Desktop Platform Development 2) 针对RHEL 5: Development tools + development libraries 安装了这些这些组之后,就可以编译rpm包了,即将源码制作成二进制格式包 * groupupdate group1 [group2] [...] 升级组 * groupremove group1 [group2] [...] 移除组 * localinstall yum除了可以自动安装外,也可以将软件包下载到本地,然后手动安装 1)RHEL 6: 统一使用yum install 来安装即可 2)RHEL 5: 需要使用yum localinstall 来安装,同样手动升级可以使用yum localupdate,RHEL6处于兼容性需求,也支持这样的用法。 yum安装软件包最大的优势在于可以自动解决依赖关系 -- nogpgcheck : 对比rpm包,yum即使使用了localinstall,也会检查软件包的来源合法性,如果密钥无法匹配,则下载到本地的软件包也无法使用yum安装,故可以使用长选项 --nogpgcheck来避免检查 * history : 查看此前的安装卸载等操作历史 二、yum命令安装实例演示/*-------- (1) 基本安装 --------*/[root@localhost ~]# yum install bind-chroot
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Package 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64 already installed and latest version
Nothing to do
# 已经安装了最新版,无需安装

现在先卸载这个软件包[root@localhost ~]# rpm -e bind-chroot
grep: /etc/sysconfig/named: No such file or directory

[root@localhost ~]# rpm -e bind-chroot --force
rpm: only installation, upgrading, rmsource and rmspec may be forced

[root@localhost ~]# rpm -e bind-chroot
error: package bind-chroot is not installed

[root@localhost ~]# yum install bind-chroot
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed
--> Processing Dependency: bind = 32:9.8.2-0.17.rc1.el6_4.6 for package: 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed
--> Finished Dependency Resolution
#依赖关系自动解决

Dependencies Resolved

=============================================================================
Package                  Arch                Version                                  Repository         Size
==============================================================================
Installing:
bind-chroot              x86_64              32:9.8.2-0.17.rc1.el6_4.6                base               71 k
Installing for dependencies:
bind                     x86_64              32:9.8.2-0.17.rc1.el6_4.6                base              4.0 M

Transaction Summary
=========================================================================
Install       2 Package(s)

Total download size: 4.0 M
Installed size: 7.3 M
Is this ok [y/N]:

# 输入y表示安装,N表示不安装,默认为不安装,yum可以使用-y自动回答安装

Is this ok [y/N]: y
Downloading Packages:
--------------------------------------------------------------------------------
Total                                                                           42 MB/s | 4.0 MB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64                                                       1/2
Installing : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64                                                2/2
Verifying  : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64                                                       1/2
Verifying  : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64                                                2/2

Installed:
bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6

Dependency Installed:
bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6

Complete!

/*-------- (2) 重新安装 --------*/ [root@localhost ~]# yum install bind
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Package 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 already installed and latest version
Nothing to do
# 提示已经安装过了

[root@localhost ~]# yum reinstall bind
# 不论是否安装,都会重新安装一遍
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Reinstall Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================
Package             Arch                  Version                                   Repository           Size
===========================================================================
Reinstalling:
bind                x86_64                32:9.8.2-0.17.rc1.el6_4.6                 base                4.0 M

Transaction Summary
===============================================================================
Reinstall     1 Package(s)

Total download size: 4.0 M
Installed size: 7.3 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64                                                       1/1
Verifying  : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64                                                       1/1

Installed:
bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6

Complete!

/*-------- (3) 卸载软件包 --------*/[root@localhost ~]# yum remove bind
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be erased
--> Processing Dependency: bind = 32:9.8.2-0.17.rc1.el6_4.6 for package: 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64
--> Running transaction check
---> Package bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package                  Arch                Version                                 Repository          Size
==============================================================================
Removing:
bind                     x86_64              32:9.8.2-0.17.rc1.el6_4.6               @base              7.3 M
Removing for dependencies:
bind-chroot              x86_64              32:9.8.2-0.17.rc1.el6_4.6               @base              0.0
# 清除bind的同时会清除bind-chroot,因为bind-chroot是依赖于bind的

Transaction Summary
==============================================================================
Remove        2 Package(s)

Installed size: 7.3 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing    : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64                                            1/2
Erasing    : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64            2/2
warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave
Verifying  : 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64                                                       1/2
Verifying  : 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64                                                2/2

Removed:
bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6

Dependency Removed:
bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6

Complete!

/*-------- (4)软件包安装信息查询 --------*/[root@localhost ~]# rpm -qf /etc/inittab
initscripts-9.03.40-2.el6.centos.x86_64
[root@localhost ~]# rpm -qf /etc/fstab
setup-2.8.14-20.el6_4.1.noarch

[root@localhost ~]# yum provides /etc/fstab
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files
# 此包生成了/etc/fstab
Repo        : base
Matched from:
Filename    : /etc/fstab

setup-2.8.14-20.el6_4.1.noarch : A set of system configuration and setup files
Repo        : installed
Matched from:
Other       : Provides-match: /etc/fstab

[root@localhost ~]# yum provides /etc/named.conf
#也可以显示没有安装的文件
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64 : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System)
: server
# 这个包之前被卸载了,这里显示的是服务器仓库上的包
Repo        : base
Matched from:
Filename    : /etc/named.conf

/*-------- (5) 模糊匹配查询 --------*/[root@localhost ~]# yum search init
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
==============================N/S Matched: init ===============================
initscripts.x86_64 : The inittab file and the /etc/init.d scripts
iscsi-initiator-utils-devel.x86_64 : Development files for
...
upstart.x86_64 : An event-driven init system
xhtml1-dtds.noarch : XHTML 1.0 document type definitions
xorg-x11-xinit-session.x86_64 : Display manager support for ~/.xsession and ~/.Xclients

Name and summary matches only, use "search all" for everything.
/*-------- (6) 安装包组 --------*/ 通常安装开发环境,为避免依赖关系,通常需要安装三个组:Development tools; Server Platform Development; Desktop Platform Development[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
base/group_gz                                                                | 220 kB     00:00 ...
Installed Groups:
Additional Development
Base
Debugging Tools
...
Web Server
X Window System
Installed Language Groups:
Arabic Support [ar]
...
Venda Support [ve]
Available Groups:
Backup Client
...
iSCSI Storage Client
Available Language Groups:
Afrikaans Support [af]
...
Zulu Support [zu]
Done

[root@localhost~]#yum -y groupinstall "Development tools" "Server Platform Development" "Desktop Platform Development"
...
pixman-devel              x86_64         0.26.2-5.el6_4                             base          18 k
ppl                       x86_64         0.10.2-11.el6                              base         1.3 M
systemtap-client            x86_64         2.3-3.el6                                  base         3.4 M
systemtap-devel            x86_64         2.3-3.el6                                  base         1.4 M
xorg-x11-proto-devel       noarch         7.6-25.el6                                 base         274 k
yajl                      x86_64         1.0.7-3.el6                                base          27 k

Transaction Summary
==============================================================================
Install     115 Package(s)

Total download size: 123 M
Installed size: 404 M
...
systemtap-devel.x86_64 0:2.3-3.el6              xorg-x11-proto-devel.noarch 0:7.6-25.el6
yajl.x86_64 0:1.0.7-3.el6

Complete!

/*-------- (7) 通过yum下载到本地,然后手动安装软件包 --------*/[root@localhost ~]# cd /media/cdrom/Packages/[root@localhost Packages]# yum install bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm
# 这个包已经下载到本地了,因此不再从服务器下载
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Examining bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm: 32:bind-9.8.2-0.17.rc1.el6_4.6.x86_64
Marking bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================
Package     Arch          Version                            Repository                                  Size
==========================================================================================
Installing:
bind        x86_64        32:9.8.2-0.17.rc1.el6_4.6          /bind-9.8.2-0.17.rc1.el6_4.6.x86_64        7.3 M

Transaction Summary
==========================================================================================
Install       1 Package(s)

Total size: 7.3 M
Installed size: 7.3 M
Is this ok [y/N]: N

[root@localhost Packages]# yum localinstall bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Local Package Process
Examining bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm: 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64
Marking bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm to be installed
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package bind-chroot.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed
--> Processing Dependency: bind = 32:9.8.2-0.17.rc1.el6_4.6 for package: 32:bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64
--> Running transaction check
---> Package bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 will be installed
--> Finished Dependency Resolution

# 可以看到使用localinstall 也会自动解决依赖关系

Dependencies Resolved

=========================================================================================
Package         Arch       Version                       Repository                                      Size
==========================================================================================
Installing:
bind-chroot     x86_64     32:9.8.2-0.17.rc1.el6_4.6     /bind-chroot-9.8.2-0.17.rc1.el6_4.6.x86_64     0.0
Installing for dependencies:
bind            x86_64     32:9.8.2-0.17.rc1.el6_4.6     base                                   4.0 M

Transaction Summary
==========================================================================================
Install       2 Package(s)

Total download size: 4.0 M
Installed size: 7.3 M
Is this ok [y/N]: n
Exiting on user Command

/*-------- (8) 查看yum命令的历史记录 --------*/ [root@localhost ~]# yum history
Loaded plugins: fastestmirror, refresh-packagekit, security
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
5 | root <root>              | 2014-08-17 06:53 | Install        |  115
4 | root <root>              | 2014-08-17 06:37 | Erase          |    2 EE
3 | root <root>              | 2014-08-17 06:20 | Reinstall      |    1
2 | root <root>              | 2014-08-17 06:16 | Install        |    2  <
1 | System <unset>           | 2014-07-09 21:22 | Install        | 1205 >
history list

/*-------- (9) 使用yum安装lftp工具包 --------*/ 现在来安装一个比较常用的ftp工具包 lftp:

[root@localhost ~]# rpm -ql lftp
# 首先检查这个软件包有没有安装
package lftp is not installed

[root@localhost ~]# yum install lftp
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package lftp.x86_64 0:4.0.9-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package            Arch                 Version                     Repository                   Size
=================================================================================
Installing:
lftp               x86_64               4.0.9-1.el6                 cdrom-centos6               753 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 753 k
Installed size: 2.5 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : lftp-4.0.9-1.el6.x86_64                                                             1/1
Verifying  : lftp-4.0.9-1.el6.x86_64                                                             1/1

Installed:
lftp.x86_64 0:4.0.9-1.el6

Complete!


安装完成,现在可以使用lftp来ping服务器了:

[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:CA:DF:46
inet addr:192.168.56.103  Bcast:192.168.56.255  Mask:255.255.255.0
# 本机的IP地址
inet6 addr: fe80::a00:27ff:feca:df46/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:114790 errors:0 dropped:0 overruns:0 frame:0
TX packets:46931 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10065569 (9.5 MiB)  TX bytes:12450568 (11.8 MiB)


[root@localhost ~]# lftp 192.168.56.103
lftp 192.168.56.103:~> pwd ftp://192.168.56.103 # 查看登陆的站点
lftp 192.168.56.103:~> !pwd
/root
#查看本地目录


lftp可以使用的基本命令有:
get: 下载单个文件
mget:下载多个文件
mirror:镜像一个目录到本地
bye:退出
cd:切换目录
pwd:查看当前位置

本文出自 “重剑无锋 大巧不工” 博客,请务必保留此出处http://wuyelan.blog.51cto.com/6118147/1615130
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: