yum的使用-实战篇

yum命令的使用实战php

(1)      安装程序包mysqlpython

命令格式:yum install package1 [package2] [...]mysql

[root@Bisc-lab01 ~]# yum -y install mysql

#提示:nginx

   1)当你使用第一次使用时yum要下载仓库的元数据库文件,网速慢请耐心的等待;es6

   2)当你已经安装了Mysql时,若是仓库中有新版的MysQL此时会进行更新的。web

   3)若是你想安装全部与php相关的程序包,这里还可使用通配符(*[])进行匹配安装。sql

(2)程序的卸载shell

    命令格式:yum remove| erase package1 [package2] [...]数据库

     在程序卸载时,yum会把所依赖的关系的程序包,没有别的程序所依赖的包一统卸载。centos

[root@Bisc-lab01 ~]# yum remove tree

(3)程序包的升级

    在进行升级以前你能够检查一下当前系统上有哪些程序包可升级的,使用yum check-update命令进行检查。

   命令格式:yum update[package1] [package2] [...]

[root@Bisc-lab01 ~]# yum update mysql    #<----更新mysql
Loaded plugins: fastestmirror,refresh-packagekit, security
Setting up Update Process
Repository base is listed morethan once in the configuration
Loading mirror speeds fromcached hostfile
Package(s) mysql available, butnot installed.
No Packages marked for Update

提示:若是没有要升级以前没有安装mysql程序包,yum是不会进行安装,会提示此程序包没有安装。

   省略后面的包名,即只有yum update命令,yum会对当前系统升级,包括内核版本,程序包等。

(4)程序包的查看

   程序包的查看能够是已安装的,能够安装的,可升级的,已废弃的包或系统上已经安装,但不是当前仓库中的程序包,即不知来源的程序包。

命令格式:yum list {available|updates|installed|extras|obsoletes}[glob_exp1] [...]

[root@Bisc-lab01 ~]# yum list extras    #查看当前系统上已安装的但不是仓库的程序包
Loaded plugins: fastestmirror,refresh-packagekit, security
Repository base is listed morethan once in the configuration
Loading mirror speeds fromcached hostfile
Extra Packages                 #这里指明了包的类型
Nessus.x86_64                6.3.4-es6                installed
nginx.x86_64                1.6.2-1.el6.ngx        installed

#提示:

1)显示的信息主要的格式为:name.arch[epoch:]version-release  repo or@installed-from-repo

即:包名.适合的平台  版本号:发行号    由哪一个仓库提供或已经安装在当前系统上的

2)当使用命令yum list all能够查看当前系统所安装的及yum仓库的包

5)列出已经配置的可用仓库

  命令格式:yum repolist[all|enabled|disabled]

[root@Bisc-lab01 ~]# yum repolist
Loaded plugins: fastestmirror,refresh-packagekit, security
Repository base is listed morethan once in the configuration
Loading mirror speeds from cached hostfile      #<----这些数据是来自本机的缓存
repo id        repo name                                status
base           CentOS-6 - Base - 163.com                       6,518
epel          Fedora EPEL for CentOS6 x86_64 onlocal server 172.16.0.1   12,922
extra         CentOS 6 x86_64                               2,334
extras         CentOS-6 - Extras - 163.com                       37
updates        CentOS-6 - Updates - 163.com                    965
repolist: 22,776                   #<---总的程序包数量

提示:(1)输出的格式即为/etc/yum.repos.d/.repo中的配置文件内容:

       [标识]   name   此仓库包的数量

[base]

name=CentOS-$releasever- Base - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

   2)当本地没有缓存或缓存已经很长时间没有更新,此行yumrepolist时会下载元数据库并缓存到本地

6yum缓存管理

    yum缓存管理能够对当前缓存进行清理,及手动的更新缓存。

  命令格式:yum clean[ packages | metadata | expire-cache | rpmdb | plugins | all ]

         yum makecache

[root@Bisc-lab01 ~]# yum cleanall     #清理全部的缓存
Loaded plugins: fastestmirror,refresh-packagekit, security
Repository base is listed morethan once in the configuration
Cleaning repos: base epel extraextras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@Bisc-lab01 ~]# yummakecache     #手动执行缓存建立

7)查询程序包的简要信息

  不论包是否安装只要仓库中有都会被显示出来,从中能够查询是否被安装还在仓库中。

[root@Bisc-lab01 ~]# yum info bash
Loaded plugins: fastestmirror,refresh-packagekit, security
Loading mirror speeds fromcached hostfile
Installed Packages         #提示程序包已安装,如未安装就会显示在哪一个仓库中。
Name        : bash
Arch        : x86_64
Version        : 4.1.2
Release        : 29.el6
Size        : 3.0 M
Repo        : installed
From repo        : anaconda-CentOS-201410241409.x86_64
Summary        : The GNU Bourne Again shell
URL        : http://www.gnu.org/software/bash
License        : GPLv3+
Description : The GNU BourneAgain shell (Bash) is a shell or command language
            : interpreter that is compatiblewith the Bourne shell (sh). Bash
            : incorporates useful features fromthe Korn shell (ksh) and the C shell
            : (csh). Most sh scripts can be runby bash without modification.

8)查找程序包,进行模拟查找

   若是你记得某个程序包的某关键字,能够经过使用yum search string1 [string2] [...]进行查找的

例如:查找以包含有php关键字的包

[root@Bisc-lab01 ~]# yum searchphp
Loaded plugins: fastestmirror,refresh-packagekit, security
Loading mirror speeds fromcached hostfile
=================================N/S Matched: php =============================================
cups-php.x86_64 : Common UnixPrinting System - php module
eclipse-phpeclipse.noarch : PHPEclipse plugin
……………省略………………………

提示:其中的关键字包括在包名中的与Summary中的字符串。

9)安装本地的程序包

  若是你想使用的程序包在当前的仓库中没有,而你已经把程序包下载到本地了,你可使用如下命令进行安装,yum会自动的解决其依赖关系。

 命令格式:yuminstall 包文件

[root@Bisc-lab01 ~]# yuminstall zabbix-web-2.4.0-1.el6.noarch.rpm   #<---安装zabbix-web程序,yum自动解决依赖关系
Loaded plugins: fastestmirror,refresh-packagekit, security
Setting up Install Process
Examiningzabbix-web-2.4.0-1.el6.noarch.rpm: zabbix-web-2.4.0-1.el6.noarch
Markingzabbix-web-2.4.0-1.el6.noarch.rpm to be installed
Loading mirror speeds fromcached hostfile
Resolving Dependencies
--> Running transactioncheck
---> Package zabbix-web.noarch0:2.4.0-1.el6 will be installed
--> Processing Dependency:zabbix-web-database = 2.4.0-1.el6 for package: zabbix-web-2.4.0-1.el6.noarch
--> Processing Dependency:php >= 5.3 for package: zabbix-web-2.4.0-1.el6.noarch
--> Processing Dependency:php-bcmath for package: zabbix-web-2.4.0-1.el6.noarch
--> Processing Dependency:php-gd for package: zabbix-web-2.4.0-1.el6.noarch
……………省略………………………

10)程序包组的管理

    yum能够对程序进行安装、卸载、升级、查看等的操做,其命令就是在相应的命令前面加下group便可:

   命令格式:

          yumgrouplist

          yum groupinstall group1[group2] [...]

          yumgroupremove group1 [group2] [...]

         yumgroupupdate group1 [group2] [...]

例如:查看当前全部的程序包组

[root@Bisc-lab01 ~]# yum grouplist
Loaded plugins: fastestmirror,refresh-packagekit, security
Setting up Group Process
Loading mirror speeds fromcached hostfile
Installed Groups:            #表示已安装的程序包组
   Additional Development
   Base
……………省略………………………
Installed Language Groups:      #表示已安装的语言包组
   Arabic Support [ar]
   Armenian Support [hy]
……………省略………………………
Available Groups:             #可安装的程序包组
   Backup Client
   Backup Server
……………省略………………………
Available Language Groups:       #可安装的语言包组
   Afrikaans Support [af]
……………省略………………………

11)查询某文件是由哪一个程序包所产生的

   你是否是还记到上次咱们说过rpm也能够查看某文件是由哪一个程序包所产生的。

命令格式:yum provides|whapprovides/PATH/TO/SOME_FILE

[root@Bisc-lab01 ~]# yum provides /etc/passwd     #<---查看/etc/passwd由哪一个程序包产生的
Loaded plugins: fastestmirror,refresh-packagekit, security
Loading mirror speeds fromcached hostfile      #<---表示调用的是本地缓存信息
setup-2.8.14-20.el6_4.1.noarch: A set of system configuration and setup files   #<---/etc/passwd是由setup所产生
Repo        : base                      #<---程序包所在的仓库
Matched from:
Filename    : /etc/passwd
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/passwd

(12)使用yum命令出错

[root@Bisc-lab01 ~]# yum install httpd*
Loaded plugins: fastestmirror, refresh-packagekit, security
Existing lock /var/run/yum.pid: another copy is running as pid 12652.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :  48 M RSS (342 MB VSZ)
    Started: Sun Apr 12 20:31:04 2015 - 00:23 ago
    State  : Sleeping, pid: 12652

#提示:这说明有一个进程正在使用yum命令,若是你打开了多个终端窗口请查看。或者是当前你只开了一个终端窗口,在保证没有另外的正在使用时你能够强行的kill进程,操做方法以下:

[root@Bisc-lab01 ~]# ps -ef|grep yum

root     12652  3643  0 20:31 pts/1    00:00:02 /usr/bin/python /usr/bin/yum install mysql

root     12735  6659  0 20:36 pts/4    00:00:00 grep --color yum

[root@Bisc-lab01 ~]# kill 12652         #数字“12652”为进程的PID

#kill以后从新运行yum命令,由于yum命令不运行时,不容许在yum命令,这样说吧,一个yum命令在安装mysql程序,而别一个yum命令恰好卸载了mysql依赖的某个程序包,一边报mysql安装完成,一边报卸载完成,这不是乱套了吗?

小结:

   yum命令是一个很基础的命令,在生产环境中也是用得比较多的一个命令,从理论的原理知识去剖析它,会让你从另一个层次去了解它,从而对它的执行作到内心有数,也会让你更轻松的使用它,你会发现慢慢的你会爱上它的哦!!!

  咱们能够运行用上面说到的yum工做原理,去搭建一个属于本身的yum源,由于在生产环境中不是每一台服务器都能上互联网的,因此你须要一台属于本身的yum服务器。

相关文章
相关标签/搜索