Linux學習之:yum程序包管理命令

1.yum簡述:  

       yum(全稱 Yellow dog Updater, Modified)是一個前端軟件包管理器。基於RPM包管理,能夠從指定的服務器自動下載RPM包並且安裝,可以自動處理依賴性關係,並且一次安裝所有依賴的軟件包,無須繁瑣地一次次下載、安裝。     
        文件服務器:
            ftp://、 htpp:// 、nfs://、 file://       
        yum客戶端:
        配置文件:
            /etc/yum.conf    #爲所有倉庫提供公共配置
            /etc/yum.repos.d/*.repo  #爲倉庫的指向提供配置
        倉庫指向的定義:
        [repositoryID]
        name=Some name for this repository #倉庫名稱(儘可能爲倉庫的功能描述)
        baseurl=url://path/to/repository/  =號左右不能有空個,否則會有語法錯誤
        enabled={1|0}  #是否啓用此倉庫,默認是啓用的
        gpgcheck={1|0}  #檢查包的完整性和來源合法性
        gpgkey=URL  #指明密鑰文件的URL
        enablegroups={1|0} #是否支持在此倉庫上使用組
        failovermethod={roundrobin|priority}    #故障轉義方法,默認爲:roundrobin(隨機挑選)
        cost=        #開銷數字,默認爲1000,值越小,優先級越高



   

2.yum命令的用法:
             yum [options] [command] [package ...] 

          顯示倉庫列表:
               repolist [all|enabled|disabled]       

     [root@shakura ~]# yum repolist all     #顯示所有的倉庫列表
     [root@shakura ~]# yum repolist enabled   #顯示可用的倉庫列表
     [root@shakura ~]# yum repolist disabled   #顯示不可用的倉庫列表

        顯示程序包:                 

     [root@shakura ~]# yum list [all | glob_exp1]  [...]   #顯示安裝包列表,支持glob通配符
     [root@shakura ~]# yum list {available|installed|updates} [glob_exp1] [...]

        安裝程序包:                      

     [root@shakura ~]# yum install package1 [package2] [...]
     [root@shakura ~]# yum reinstall package1 [package2] [...]  #重新安裝

        升級程序包:                      

     [root@shakura ~]# yumupdate [package1] [package2] [...]   #更新          
     [root@shakura ~]# yum downgrade package1 [package2] [...]    #降級

       檢查可用升級:            

     [root@shakura ~]# yum check-update

        卸載程序包:         

     [root@shakura ~]# yum remove | erase package1 [package2] [...]

        查看程序包information:            

     [root@shakura ~]# yum info [...]

        查看指定的特性(可以是某文件)是由哪個程序包所提供:            

     [root@shakura ~]# yum provides | whatprovides feature1 [feature2] [...]

        清理本地緩存:              

     [root@shakura ~]# yum clean

         #all:所有; packages:下載的rpm包;metadata:元數據;

         #expire-cache:過期緩存; rpmdb :rpm數據庫;plugins :插件。

        構建緩存:            

     [root@shakura ~]# yum makecache

        搜索:    

     [root@shakura ~]# yumsearch string1 [string2] [...]

        #模糊搜索以指定的關鍵字搜索程序包名及summary信息;

        查看指定包所依賴的capabilities:             

     [root@shakura ~]# yum deplist packag_NAME

        查看yum事務歷史:                       

     [root@shakura ~]# yum history

        安裝及升級本地程序包:       

     * localinstall rpmfile1 [rpmfile2] [...]
     (maintained for legacy reasons only - use install)
     * localupdate rpmfile1 [rpmfile2] [...]
     (maintained for legacy reasons only - use update)

        包組管理的相關命令:          

     * groupinstall group1 [group2] [...]  
     * groupupdate group1 [group2] [...]       
     * grouplist [hidden] [groupwildcard] [...]       
     * groupremove group1 [group2] [...]        
     * groupinfo group1 [...]




3.如何使用光盤當作本地yum倉庫:
        (1) 掛載光盤至某目錄,例如/media/cdrom             
        

     [root@shakura ~]d]# mount -r /dev/cdrom /media/cdrom/

        (2) 編輯或者創建配置文件vim  /etc/yum.repos.d/CentOS-CR.repo                     

     [root@shakura ~]# vim /etc/yum.repos.d/CentOS-CR.repo
     # CentOS-CR.repo
     [cr]      
     name=CentOS-7.1 localCDROM
     baseurl=file:///media/cdrom                
     gpgcheck=1                
     gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7                
     enabled=1

         (3)查看可用的yum倉庫顯示如下            

     [root@shakura ~]# yum repolist
     已加載插件:fastestmirror, langpacks
     Loading mirror speeds from cached hostfile
     源標識                         源名稱                      狀態
     cr                            CentOS-7 - cr               8,652
     repolist: 8,652

     yum的命令行選項:    

     --nogpgcheck:禁止進行gpg check;
     -y: 自動回答爲“yes”;
     -q:quite靜默模式;
     --disablerepo=repoidglob:臨時禁用此處指定的repo;
     --enablerepo=repoidglob:臨時啓用此處指定的repo;
     --noplugins:禁用所有插件;

    yum的repo配置文件中可用的變量:

     $releasever: 當前OS的發行版的主版本號;
     $arch: 平臺;
     $basearch:基礎平臺;
     $YUM0-$YUM9:提供的10個可以自定義的變量$YUM0-$YUM10。
     http://mirrors.magedu.com/centos/$releasever/$basearch/os

    創建yum倉庫:
        createrepo [options] <directory>

        



4. 程序包編譯安裝:       
           第一步:configure腳本
                選項:指定安裝位置、指定啓用的特性
                --help: 獲取其支持使用的選項
                    選項分類:
                        安裝路徑設定:
                            --prefix=/PATH/TO/SOMEWHERE: 指定默認安裝位置;默認爲/usr/local/
                            --sysconfdir=/PATH/TO/SOMEWHERE:配置文件安裝位置;
                       System types:
                        Optional Features: 可選特性
                            --disable-FEATURE
                            --enable-FEATURE[=ARG]

                        Optional Packages: 可選包(依賴到的程序包)
                            --with-PACKAGE[=ARG] 
                            --without-PACKAGE
            第二步:make
            第三步:make install
        安裝後的配置:
            (1) 導出二進制程序目錄至PATH環境變量中;
                編輯文件/etc/profile.d/NAME.sh
                    export PATH=/PATH/TO/BIN:$PATH
            (2) 導出庫文件路徑
                編輯/etc/ld.so.conf.d/NAME.conf
                    添加新的庫文件所在目錄至此文件中;
                讓系統重新生成緩存:
                    ldconfig [-v]
            (3) 導出頭文件
                基於鏈接的方式實現:
                    ln -sv
            (4) 導出幫助手冊
                編輯/etc/man.config文件
                    添加一個MANPATH




5.練習:編譯安裝Apache2.2,並啓動httpd服務

    (1)準備工作

        ●從Apache官網獲取安裝包            

    [root@shakura ~]# wget http://apache.dataguru.cn/httpd/httpd-2.2.31.tar.gz

        ●解壓安裝包      

    [root@shakura ~]# tar xf httpd-2.2.31.tar.gz

        ●進入到httpd-2.2.32查看安裝手冊顯示安裝步驟:    

    [root@shakura ~]# cd httpd-2.2.31 && cat INSTALL
    APACHE INSTALLATION OVERVIEW

      Quick Start - Unix
      ------------------

      For complete installation documentation, see [ht]docs/manual/install.html or
      http://httpd.apache.org/docs/2.2/install.html

         $ ./configure --prefix=PREFIX    #
         $ make
         $ make install
         $ PREFIX/bin/apachectl start

         NOTES: * Replace PREFIX with the filesystem path under which 
              Apache should be installed.  A typical installation
              might use "/usr/local/apache2" for PREFIX (without the
              quotes).

           #此步驟可省略,但是建議其查看。

     ●--help選項,,獲取其支持的選項

    [root@shakura httpd-2.2.31]# ./configure --help
    `configure' configures this package to adapt to many kinds of systems.
    Usage: ./configure [OPTION]... [VAR=VALUE]...
    To assign environment variables (e.g., CC, CFLAGS...), specify them as
    VAR=VALUE.  See below for descriptions of some of the useful variables.
    Defaults for the options are specified in brackets.
    Configuration:
      -h, --help              display this help and exit
          --help=short        display options specific to this package
          --help=recursive    display the short help of all the included packages
      -V, --version           display version information and exit
      -q, --quiet, --silent   do not print `checking ...' messages
          --cache-file=FILE   cache test results in FILE [disabled]
      -C, --config-cache      alias for `--cache-file=config.cache'
      -n, --no-create         do not create output files
          --srcdir=DIR        find the sources in DIR [configure dir or `..']
    Installation directories:
      --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/apache2]
      --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

    (2)開始編譯安裝  

     [root@shakura httpd-2.2.31]# ./configure --prefix=/tmp/apache2
     checking for chosen layout... Apache
     checking for working mkdir -p... yes
     checking build system type... x86_64-unknown-linux-gnu
     checking host system type... x86_64-unknown-linux-gnu
     checking target system type... x86_64-unknown-linux-gnu

    (3)make and make install並啓動httpd服務      

    [root@shakura httpd-2.2.31]# make && makeinstall

    (4)查看httpd服務是否運行

 wKioL1Z_qs2zqGM3AAPuSaxbK9M775.jpg

        至此,Apache服務安裝成功。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章