23. 文件系統——使用yum安裝軟件包

1、yum命令的基本安裝功能html

[root@localhost ~]# man yumcentos

command is one of:bash

 install package1 [package2] [...]  install + 包名服務器

yum -y: 安裝時自動回答爲yes session

 

reinstall package1 [package2] [...] 從新安裝ide

 

*** 補充rmp命令:rpm -ql + 包名 : 查詢包安裝生成的文件清單工具

 rpm -qf + /path/to/file_name: 查詢某文件是由哪一個軟件包生成的this

* provides | whatprovides feature1 [feature2] [...]spa

使用yum來查詢軟件包生成哪些文件,以及文件是由哪一個軟件包生成的。debug

 

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除了能夠自動安裝外,也能夠將軟件包下載到本地,而後手動安裝

  1RHEL 6 

統一使用yum install 來安裝便可

    2RHEL 5: 

    須要使用yum localinstall 來安裝,一樣手動升級可使用yum localupdateRHEL6處於兼容性需求,也支持這樣的用法。

  yum安裝軟件包最大的優點在於能夠自動解決依賴關係

 

-- nogpgcheck : 

對比rpm包,yum即便使用了localinstall,也會檢查軟件包的來源合法性,若是密鑰沒法匹配,則下載到本地的軟件包也沒法使用yum安裝,故可使用長選項 --nogpgcheck來避免檢查

 

history : 查看此前的安裝卸載等操做歷史

 

2、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!


安裝完成,如今可使用lftpping服務器了:

 

[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查看當前位置

相關文章
相關標籤/搜索