设为首页 收藏本站
查看: 2047|回复: 0

[经验分享] Linux yum相关

[复制链接]

尚未签到

发表于 2018-5-22 13:28:33 | 显示全部楼层 |阅读模式
  一、yum命令
  二、yum源配置文件
  三、将光驱配置为yum源
  四、其他
  一、yum命令
  1.安装
  yum install package_name    #用yum安装程序,可一次安装多个,彼此间用空格隔开
  yum reinstall package_name    #重新安装程序,类似的有rpm -ivh packages_name --replacepkgs
  yum groupinstall group_name    #用yum安装包组,可一次安装多个,彼此间用空格隔开
  CentOS 6中,yum可以用来安装本地rpm包,yum install –y /path/to/package_name,安装的同时利用yum的特性可以解决依赖关系
  CentOS 5中,本地安装rpm包需要使用yum localinstall
  关于包组的安装,在生产环境中会要求安装开发环境
  RHEL6,CentOS6:"Development tools" "Server Platform Development" "Desktop Platform Development"   
    RHEL5,CentOS5:"Development tools" "Development Libraries"
[root@IPOSSERVER ~]# yum groupinstall -y "Development tools" "Server Platform Development" "Desktop Platform Development"
1

  

  2.升级、降级
  yum update package_name    #升级
  yum update-to    #指定升级到的版本
  yum groupupdate group_name     #升级
  yum downgrade package_name    #降级
  yum check-update    #检查是否有可以升级的程序
  3.卸载
  yum remove package_name   #卸载程序
  yum  groupremove group_name    #卸载包组
  4.显示yum源信息
  yum repolist enabled    #显示启用的yum源信息
  yum repolist disabled    #显示禁用的yum源信息
  yum repolist all    #显示所有yum源信息
  

1
2
3
C6.3-updates                      CentOS-6.3 - Updates                      disabled    #禁用的yum源
base                              CentOS-6 - Base                           enabled: 6,518    #启用的yum源
c6-media                          CentOS-6 - Media                          disabled
  

  5.显示yum源中的程序包、包组的信息
  yum list    #查看yum源中的包,支持globbing
  yum grouplist    #查看yum源中的包组
  ------------------------------------------------   
  yum list available    #显示未安装的包
  yum list extras    #不是通过yum源安装的、无法识别来源的且已安装的包
  yum list obsoletes    #废弃的包
  yum list recent    #刚添加进yum源的包
  yum list updates    #可更新的包
  ------------------------------------------------   
   yum list installed    #显示已安装的包
[root@TESTHOST ~]# yum list install bas*    #globbing
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: centos.ustc.edu.cn
Installed Packages    #已安装
basesystem.noarch         10.0-4.el6              @anaconda-CentOS-201311272149.x86_64/6.5
bash.x86_64               4.1.2-15.el6_4          @anaconda-CentOS-201311272149.x86_64/6.5
Available Packages    #未安装
bash.x86_64               4.1.2-29.el6            base                                    
bash-doc.x86_64           4.1.2-29.el6            base  ------------------------------------------------   
  yum list all    #获取yum源所有rpm包信息
  

1
2
3
4
5
ConsoleKit.x86_64                        0.4.1-3.el6                    @base   #表示已经安装,@后的信息为程序安装基于的yum源
ConsoleKit-libs.x86_64                   0.4.1-3.el6                    @base   
MAKEDEV.x86_64                           3.24-6.el6                     @anaconda-CentOS-201311272149.x86_64/6.5    #表示已经安装
389-ds-base-libs.x86_64                  1.2.11.15-48.el6_6             updates    #表示未安装,可升级
ConsoleKit-devel.i686                    0.4.1-3.el6                    base    #表示未安装,可以安装
  
  

  6.显示yum源中程序包、包组的摘要
   yum info package_name    #类似rpm –qi,yum源中程序的摘要信息
  yum groupinfo group_name    #显示yum源中包组的摘要
[root@TESTHOST ~]# yum info bash
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
Installed Packages    #已安装的
Name        : bash
Arch        : x86_64
Version     : 4.1.2
Release     : 15.el6_4
Size        : 3.0 M
Repo        : installed
From repo   : anaconda-CentOS-201311272149.x86_64
Summary     : The GNU Bourne Again shell
URL         : http://www.gnu.org/software/bash
License     : GPLv3+
Description : The GNU Bourne Again shell (Bash) is a shell or command language
            : interpreter that is compatible with the Bourne shell (sh). Bash
            : incorporates useful features from the Korn shell (ksh) and the C shell
            : (csh). Most sh scripts can be run by bash without modification.
Available Packages    #未安装的
Name        : bash
Arch        : x86_64
Version     : 4.1.2
Release     : 29.el6
Size        : 907 k
Repo        : base
Summary     : The GNU Bourne Again shell
URL         : http://www.gnu.org/software/bash
License     : GPLv3+
Description : The GNU Bourne Again shell (Bash) is a shell or command language
            : interpreter that is compatible with the Bourne shell (sh). Bash
            : incorporates useful features from the Korn shell (ksh) and the C shell
            : (csh). Most sh scripts can be run by bash without modification.  7.查看程序是由yum源中哪个包安装的
  yum provides | yum whatprovides    #类似的有rpm –qf /path/to/some_file
  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@TESTHOST ~]# yum provides /bin/bash
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.skyshe.cn
* extras: mirrors.skyshe.cn
* updates: centos.ustc.edu.cn
bash-4.1.2-29.el6.x86_64 : The GNU Bourne Again shell
Repo        : base
Matched from:
Filename    : /bin/bash

bash-4.1.2-15.el6_4.x86_64 : The GNU Bourne Again shell
Repo        : installed    #显示已安装
Matched from:
Other       : Provides-match: /bin/bash
  8.清理
      yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
  packages:本地缓存包
  metadata:本地源数据
  expire-cache:过期的数据
  rpmdb:yum管理的rpm数据库
  plugins:缓存
  all:所有
  手动在本地生成缓存
      yum makecache
  9.在yum源中模糊搜索含有关键字的程序
  yum search支持globbing
  

1
2
3
4
5
6
7
8
9
10
11
[root@TESTHOST ~]# yum search bash
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.skyshe.cn
* extras: mirrors.skyshe.cn
* updates: centos.ustc.edu.cn
=================================== N/S Matched: bash ====================================
bash-doc.x86_64 : Documentation files for bash
bash.x86_64 : The GNU Bourne Again shell

  Name and summary matches only, use "search all" for everything.
  10.查看yum操作历史
  yum history
  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@IPOSSERVER ~]# yum history
Loaded plugins: fastestmirror
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    11 | root <root>              | 2015-04-23 00:28 | Install        |    1   
    10 | root <root>              | 2015-04-22 10:50 | I, U           |  231   
     9 | root <root>              | 2015-01-27 11:49 | Install        |    2   
     8 | root <root>              | 2015-01-27 11:26 | Install        |    1   
     7 | root <root>              | 2013-10-30 15:14 | Install        |    2   
     6 | root <root>              | 2013-10-30 15:11 | Erase          |    2   
     5 | root <root>              | 2013-10-29 18:17 | I, U           |   89   
     4 | root <root>              | 2013-10-29 18:08 | Install        |    1  <
     3 | root <root>              | 2013-10-29 18:04 | Install        |    1 >
     2 | root <root>              | 2013-10-29 18:00 | Install        |   44   
     1 | System <unset>           | 2013-10-29 17:08 | Install        |  210   
history list
  
  二、yum源配置文件
  yum源核心配置文件:/etc/yum.conf
  

1
2
3
4
5
6
7
8
9
10
11
12
[main]
cachedir=/var/cache/yum/$basearch/$releasever    #定义缓存目录
keepcache=0    #rpm包是否需要长久保存
debuglevel=2    #调试级别,级别越高,信息越详细
logfile=/var/log/yum.log    #定义日志文件路径
exactarch=1    #是否与本地平台精确匹配,0表示“否”
obsoletes=1    #
gpgcheck=1    #来源合法性检测,0表示“否”
plugins=1    #
installonly_limit=5    #
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
  或者在目录/etc/yum.repos.d/中创建*.repo文件,每一个*.repo文件都相当于/etc/yum.conf的组成部分
  

1
[root@TESTHOST ~]# vim /etc/yum.repos.d/CentOS6.repo
  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[sohu]
name=CentOS 6.5 x86_64
baseurl=http://······
enabled=1    #是否启用,1为启用,0为不启用
gpgcheck=0    #0为不检测来源合法性
#gpgkey=http://mirrors.sohu.com/centos/RPM-GPG-KEY-CentOS-6    #指定验证源来源合法性的key文件
cost=100    #当启用多个yum源时,cost值越小,使用yum安装程序时则优先从cost值小的源下载安装

[epel]
name=Fedora EPEL
baseurl=http://
enabled=1
gpgcheck=0
cost=200
  baseurl链接中的变量
  例如:baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
  $releasever    #取得版本号,CentOS6时变量为6,6是指向该版本的最新发行版yum路径,例如更新到6.5时,6指向6.5的yum源  
Thisis replaced with the package's version, as listed in distroverpkg. Thisdefaults to the version of the redhat-release package.
  $arch  
This is replaced with your system's architecture, as listed by os.uname() in Python.
  $basearch    #取得系统平台版本  
This is replaced with your base architecture. For example, if $arch=i686 then $basearch=i386.
  $YUM0-9  
Thisis replaced with the value of the shell environment variable of the
same name. If the shell environment variable does not exist, then the
configuration file variable will not be replaced.
  三、将光驱配置为yum源
  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@TESTHOST ~]# mkdir /media/cdrom    #创建一个目录方便挂载光驱
[root@TESTHOST ~]# lsblk    #获取块设备名,光驱为sr0
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0  4.9G  0 part /
├─sda3   8:3    0    2G  0 part [SWAP]
├─sda4   8:4    0    1K  0 part
└─sda5   8:5    0    2G  0 part /usr
sr0     11:0    1 1024M  0 rom  
[root@TESTHOST ~]# mount /dev/sr0 /media/cdrom/    #将sr0挂载到/media/cdrom下
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@TESTHOST ~]# vim /etc/yum.repos.d/cdrom.repo    #编辑yum源配置文件
----------------------------------
[cdrom]
name=CentOS 6 x86_64
baseurl=file:///media/cdrom/    #本地文件路径
enabled=1
gpgcheck=0
----------------------------------    #保存退出vim
[root@TESTHOST ~]# yum clean all    #清楚本地yum所有缓存
[root@TESTHOST ~]# yum makecache    #手动生成缓存
······    #显示过程省略
[root@TESTHOST ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: mirror01.idc.hinet.net
repo id                             repo name                                       status
base                                CentOS-6 - Base                                 6,518
cdrom                               CentOS 6 x86_64                                 6,346    #添加成功!
extras                              CentOS-6 - Extras                                  37
updates                             CentOS-6 - Updates                              1,027
repolist: 13,928
  :如果自建本地yum源,则需要使用createrepo命令创建repodata,然后参照上述方法即可
  

1
[root@TESTHOST ~]# createrepo /localyum/    #指向rpm包所在的文件夹路径即可,命令执行成功后,会在目录下生成repodata文件夹
  repodata文件夹
  

1
2
3
4
5
6
7
8
9
10
11
[root@TESTHOST ~]# ls /localyum/repodata/
018dd5e8db1fe55ccd4fd96d3b1daaa5782b34d254cc7766a0eb9d1ac7e1be0d-primary.sqlite.bz2    #各rpm包的依赖关系
0dae8d32824acd9dbdf7ed72f628152dd00b85e4bd802e6b46e4d7b78c1042a3-c6-x86_64-comps.xml
30154de288eb7b171a2b176fa0a3a27e4bb6d86bc85bbb9f7222731e061cdbe0-other.xml.gz    #rpm的改变日志
5543021d0abe9b87103b25a5107ca4881a1c7e889aba73a6744ee1d02990b06a-c6-x86_64-comps.xml.gz
5d39cc05a54a2306e5b42bc9d09b41c64ac9b1df71fcfffc9006d3f39a1c82d6-filelists.sqlite.bz2    #所有rpm包的文件列表
7ae992116f3faf2ea94dd136eb1a3a16e287a8ddd0f17f8f6d2b123ca81e93b9-c6-x86_64-comps.xml.gz
7ce6c7ad226d8fe6fdcd707299e05780e0e2b53d6c5b501d0202c8250543c3b9-other.sqlite.bz2    #rpm的改变日志
91ab3d63ada0012acb696d7ac13374bc9f8874cb259054d6fddca99cd154a429-filelists.xml.gz    #所有rpm包的文件列表
974e3eb45ed520d2538c232807b90b605ceeea27a29a832a60119a45447d6d69-primary.xml.gz    #各rpm包的依赖关系
repomd.xml    #保留以上文件时间戳,yum运行时用本地/var/cache/yum/中缓存文件对比此文件,如有不同,则更新本地缓存
  四、其他
  1.lftp
  lftp+IP:登录ftp服务器
  查看服务器文件:ls
  查看处于服务器目录:pwd
  切换服务器所在目录:cd
  下载文件命令:get FILENAME
  下载多个文件:mget
  下载目录命令:mirror DIRNAME/
  退出lftp:bye
  下载的文件在进入lftp时的目录,例如在处在root目录时,登录lftp,则下载的文件存放在root目录下
  执行bash命令,加符号!,例如!ls,!pwd
  本文出自 “Arvin Lau” 博客,请务必保留此出处http://64314491.blog.51cto.com/2784219/1637404
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-479131-1-1.html 上篇帖子: linux的基本管理 下篇帖子: Linux简介及系统安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表