天天看點

簡析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

            ============================ 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:

            -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

             * 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.  挂載鏡像CD光牒

                # 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,如需轉載請自行聯系原作者

上一篇: shell體驗一
下一篇: shell體驗三

繼續閱讀