简析yum使用

简介:
Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。
    yum的优点:
        1.安装方便,自动解决添加或删除rpm包时遇到的依赖问题。
        2.可以同是配置多个源。
    yum的缺点:
        需要yum源的支持。(没有源什么都做不了)多个yum源并存时,注意不能重名(.repo文件不可以重名,配置文件里面的库名也不可以重名)。避免产生冲突。
    yum的简单用法:
        安装和删除;
            安装:$yum install -y(加入-y选项的好处:所有的询问都会回答yes.减少安装的交互)
            在首次安装完系统特别是遵循最小化安装的可以扩展安装几个命令:
            # yum install  lrzsz tree telnet nmap sysstt -y (前提是可以上网,或者由本地yum源)
                  $ yum  install nginx --enablerepo=(指定yum源)
            删除:$ yum  remove  (这个需要注意:特别是关联系统库文件的看清楚在执行。不然。会删系统库)
        更新
            # yum  update (可以理解为win的打补丁)
            # yum  update kernel kernel-source (更新kernel和kernel source)
            # yum upgrade (相比update  还可以升级陈旧的软件包)
        查询
            查询rpm包的信息:以tree 举例
            [root@swallow yum.repos.d]# yum info tree*
            Loaded plugins: fastestmirror, security
            Loading mirror speeds from cached hostfile
            Installed Packages
            Name        : tree
            Arch        : x86_64
            Version     : 1.5.3
            Release     : 2.el6
            Size        : 65 k
            Repo        : installed
            From repo   : local
            Summary     : File system tree viewer
            URL         : http://mama.indstate.edu/users/ice/tree/
            License     : GPLv2+
            Description : The tree utility recursively displays the contents of directories in a
                        : tree-like format.  Tree is basically a UNIX port of the DOS tree
                        : utility.
            可以搜索匹配特定字符的rpm包的信息。以 wget 为例;
            [root@swallow yum.repos.d]# yum search wget
            Loaded plugins: fastestmirror, security
            Loading mirror speeds from cached hostfile
            ============================ N/S Matched: wget ===========================================
            wget.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
        yum源的缓存
            首先我们简单看一下:yum的相关配置文件:
            $ls -l /etc/yum*
            -rw-r--r--. 1 root root  969 Feb 22  2013 /etc/yum.conf

            /etc/yum:
            total 16
            drwxr-xr-x. 2 root root 4096 Jan 18 15:03 pluginconf.d
            drwxr-xr-x. 2 root root 4096 Feb 22  2013 protected.d
            drwxr-xr-x. 2 root root 4096 Feb 22  2013 vars
            -rw-r--r--. 1 root root  444 Feb 22  2013 version-groups.conf

            /etc/yum.repos.d:
            total 16
            -rw-r--r--. 1 root root 1926 Nov 27  2013 CentOS-Base.repo
            -rw-r--r--. 1 root root  638 Nov 27  2013 CentOS-Debuginfo.repo
            -rw-r--r--. 1 root root  630 Nov 27  2013 CentOS-Media.repo
            -rw-r--r--. 1 root root 3664 Nov 27  2013 CentOS-Vault.repo
        截取部分 /etc/yum.conf 文件解读:
        [root@swallow ~]# cat /etc/yum.conf 
        [main]
        cachedir=/var/cache/yum/$basearch/$releasever  # 缓存目录的由来
        keepcache=0        
        debuglevel=2    #debug级别
        logfile=/var/log/yum.log    #yum的日志文件
        exactarch=1      #代表只升级和你安装软件包cpu体系一致的包 。($ uname -m  查看CPU构架)
        obsoletes=1
        gpgcheck=1        #是否校验
        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

        # PUT YOUR REPOS HERE OR IN separate files named file.repo
        # in /etc/yum.repos.d     ###明确指出:你的yum源安装在  这个目录下并且 以.repo 结尾。
            查看缓存目录下有什么
            $ tree /var/cache/yum/ -L 3  (-L 3 是只显示前三级。后面的隐藏)
                /var/cache/yum/
                ├── timedhosts.txt
                └── x86_64
                    └── 6
                        ├── base
                        ├── extras
                        ├── timedhosts.txt
                        └── updates
            这些文件的由来;在启动新yum源是系统读取的时候,缓存生成的。
        为什么要清除这些缓存:当假设新源的时候。旧的yum源缓存会对新源产生性能的影响。
        清除缓存的命令: # yum  clean all
        生成缓存的命令: # yum  makecache
            # yum install tree
            Loaded plugins: fastestmirror, security
            Loading mirror speeds from cached hostfile
             * base: mirrors.btte.net
             * extras: mirrors.nwsuaf.edu.cn
             * updates: mirrors.nwsuaf.edu.cn
            base                                                         | 3.7 kB     00:00                                    
            extras                                                       | 3.4 kB     00:00                                    
            extras/primary_db                                   |  37 kB     00:00                                    
            updates                                                    | 3.4 kB     00:00                                    
            updates/primary_db                                | 4.3 MB     00:11                                   
            Setting up Install Process
            Package tree-1.5.3-3.el6.x86_64 already installed and latest version
    下面我们来看简单看下配置文件的写法并且搭建本地的yum源。
        这里以一个搭建好的源为例:
            [local]                             #库名称
            name=CentOS-$releasever - Base      #库名称的描述,方便区分不同的库
            baseurl=file:///mnt                 #关键位置**  源的地址
            enabled=1                           #***关键部分 1 代表启动源。0 关闭
            gpgcheck=1                          # 校验地址  一般本地源可以关闭
            gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6  # 系统提供的校验值
                                 # 此处如果开启校验。一定要确保这个文件存在于你的系统上
        制作方法:
            1.  挂载镜像光盘
                # mount /dev/cdrom /mnt
                # df -h  (检查是否挂载成功  )
                Filesystem      Size  Used Avail Use% Mounted on
                /dev/sr0        4.2G  4.2G     0 100% /mnt
                (这里需要说明的是: cdrom  和 sr0 的软链接。  /mnt 文件可以任意创建。
                # ll /dev/cdrom
                    lrwxrwxrwx. 1 root root 3 Jan 23  2017 /dev/cdrom -> sr0)
            2. 制作yum源
                # mv CentOS-Base.repo CentOS-Base.repo.BAK  (避免冲突,也为了更好看效果把原yum源备份)
                # vim local.repo
                把上面 的例子 录入即可。

        如果在操作的时候出现错误:
        Loaded plugins: fastestmirror, security
        Existing lock /var/run/yum.pid: another copy is running as pid 39746.
        我的解决方式:  # kill  -9  pid
制作阿里云和网易的源的方法:
    网易源做法:
        首先备份/etc/yum.repos.d/CentOS-Base.repo
              # mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
        新建163的yum源
              # wget -O /etc/yum.repos.d/CentOS6-Base-163.repo  http://mirrors.163.com/.help/CentOS6-Base-163.repo 
        生成新的缓存。
              # yum  clean all
              # yum makecache
    阿里云源做法:
        1、备份
            # mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
        2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
        CentOS 5
        # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo

        CentOS 6
        # wget -O /etc/yum.repos.d/CentOS-Base-aliyun.repo http://mirrors.aliyun.com/repo/Centos-6.repo

        CentOS 7
        # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
        3、之后运行yum  clean up ;yum makecache生成缓存
    在使用的时候,你可以选择开启那个源:
        进入.repo 文件中找到enabled=1  把参数改为0 就关闭了该源。









本文转自 swallow_zys  51CTO博客,原文链接:http://blog.51cto.com/12042068/1894028,如需转载请自行联系原作者
目录
相关文章
|
8月前
Yum工具详解(二)-----Yum配置阿里源
Yum工具详解(二)-----Yum配置阿里源
2194 1
|
4月前
|
JSON 资源调度 JavaScript
【源码共读】编程式安装依赖 install-pkg
【源码共读】编程式安装依赖 install-pkg
41 2
|
8月前
Yum工具详解(一)-----Yum配置本地源
Yum工具详解(一)-----Yum配置本地源
166 0
|
8月前
|
Linux
Yum工具详解(三)----- Yum配置阿里源CentOS 6.x
Yum工具详解(三)----- Yum配置阿里源CentOS 6.x
2204 0
|
Linux
RPM包是干什么的?底层原理是什么?
RPM包是干什么的?底层原理是什么?
951 0
|
存储 关系型数据库 应用服务中间件
gitlab是编译安装好还是yum安装好?底层原理是什么?
gitlab是编译安装好还是yum安装好?底层原理是什么?
142 0
|
NoSQL Linux 开发工具
【Linux操作系统】yum三板斧和yum源的配置
【Linux操作系统】yum三板斧和yum源的配置
432 0
【Linux操作系统】yum三板斧和yum源的配置
|
Ubuntu Linux Shell
安装及管理程序(RPM、YUM、源码编译安装)(上)
1 Linux 应用程序基础 1.1 应用程序与系统命令的关系
136 0
|
缓存 前端开发 Linux
安装及管理程序(RPM、YUM、源码编译安装)(下)
1 Linux 应用程序基础 1.1 应用程序与系统命令的关系
117 1