yum安裝 源碼安裝實例

 yum安裝 源碼安裝實例

§·源碼安裝 http 2.2.29實例 1

    1.下載源碼包。 1

    2.配置系統需要的編譯環境。 2

    3 ./configure ; make  ; make install 3

    4 .configure 生成makefile文件 4

    5  make 與make install 5

    6 設置二進制程序 庫文件 頭文件 幫助文件的路徑。 5

        *設置二進制程序加入PATH環境變量中(/etc/profile.d/) 6

    *設置lib加載到系統中(/etc/ld.so.conf.d/) 6

    *設置include映射到系統頭文件路徑(/usr/include/) 6

    *設置man幫助 7

§·Centos 7  yum基礎知識 7

        ※·什么是rpm? 8

    ※·什么是yum? 8

    ※·為什么使用yum? 8

    ※·yum的基礎操作? 8

◎·如何配置yum倉庫(以阿里云 yum服務器為例) 9

◎·搭建單機的yum倉庫(以光盤鏡像為例) 12

    ※yum配置管理(yum命令的使用) 13

    *Yum 命令創建repo文件 13

    *Yum 命令顯示倉庫列表與安裝軟件 14

    *Yum 升級軟件包v降級 卸載軟件包 15

    *Yum 軟件包查詢v 16

    *Yum 搜索  依賴  事務日志 17

    *Yum 命令使用6 19

§·數組課后練習 20

 

 

 

§·源碼安裝 http 2.2.29實例

(源碼包的基本只是可以參看博客 程序源碼基礎知識

centos上有RPM包,有yum可以幫助我們解決依賴關系,為什么我們還需要使用源碼安裝呢?

1.RPM是傻瓜式的安裝,我們有時候需要制定我們安裝的文件的主目錄文件位置;

2.RPM包中沒有我們需要的功能,

3.最新版的軟件沒有RPM,

4.我們需要個性化我們的安裝。

等等,我們需要源碼安裝我們的軟件。

1.下載源碼包。

通過實驗環境下載 http 2.2.29的源碼包。

使用工具有: lftp  get 工具:

[root@Centos7 testdir]# lftp 10.1.0.1
lftp 10.1.0.1:~> cd pub/Sources/sources/httpd/
lftp 10.1.0.1:/pub/Sources/sources/httpd> ls   #進入源碼目錄
-rwxr--r--    1 500      500        785724 Mar 11  2012 apr-1.4.6.tar.bz2
-rwxr--r--    1 500      500        813976 Mar 18  2014 apr-1.5.0.tar.bz2
-rwxr--r--    1 500      500        992859 Aug 08  2012 apr-iconv-1.2.1.tar.bz2
-rwxr--r--    1 500      500        635000 Mar 11  2012 apr-util-1.4.1.tar.bz2
-rwxr--r--    1 500      500        693258 Apr 11  2013 apr-util-1.5.2.tar.bz2
-rwxr--r--    1 500      500        695303 Mar 18  2014 apr-util-1.5.3.tar.bz2
-rwxr--r--    1 500      500       5625498 Dec 16  2014 httpd-2.2.29.tar.bz2
-rwxr--r--    1 500      500       5031834 Dec 16  2014 httpd-2.4.10.tar.bz2
-rwxr--r--    1 500      500       4949897 Aug 20  2013 httpd-2.4.6.tar.bz2
-rwxr--r--    1 500      500       4994460 Mar 18  2014 httpd-2.4.9.tar.bz2
-rwxr--r--    1 500      500         18739 Mar 09  2012 mod_bw-0.7.tgz
-rwxr--r--    1 500      500      10057503 Sep 18  2015 phpMyAdmin-4.4.14.1-all-languages.zip
-rwxr--r--    1 500      500       7518362 Sep 18  2015 wordpress-4.3.1-zh_CN.zip
lftp 10.1.0.1:/pub/Sources/sources/httpd>  get httpd-2.2.29.tar.bz2  #下載文件到當前目錄下
5625498 bytes transferred                          
lftp 10.1.0.1:/pub/Sources/sources/httpd> exit   #退出ftp服務器
[root@Centos7 testdir]# ls
functions   httpd-2.2.29.tar.bz2  shells
[root@Centos7 testdir]#

2.配置系統需要的編譯環境。

httpd-2.2.29.tar.bz2需要使用gcc的編譯環境,我們通過包組安裝 “Development Tools”,在centos7 上安裝這個開發工具包組即可。

[root@Centos7 testdir]# yum groups install "Development Tools"  #直接安裝即可。
[root@Centos7 testdir]# tar -jxvf httpd-2.2.29.tar.bz2   #解壓包到當前目錄。
[root@Centos7 testdir]# cd httpd-2.2.29/  #進入解壓同名目錄
[root@Centos7 httpd-2.2.29]# ls  #查看目錄下的文件,我們編譯之前看看RAEDME 或 INSTALLl.
ABOUT_APACHE  CHANGES        httpd.dsp       libhttpd.dep  NOTICE            server
acinclude.m4  config.layout  httpd.mak       libhttpd.dsp  NWGNUmakefile     srclib
Apache.dsw    configure      httpd.spec      libhttpd.mak  os                support
build         configure.in   include         LICENSE       README            test
BuildAll.dsp  docs           INSTALL         Makefile.in   README.platforms  VERSIONING
BuildBin.dsp  emacs-style    InstallBin.dsp  Makefile.win  README-win32.txt
buildconf     httpd.dep      LAYOUT          modules       ROADMAP
[root@Centos7 httpd-2.2.29]#

 

我們首先來看看兩個文件的內容能給我們什么幫助。

 找到一個比較重要的說明

 

[root@Centos7 httpd-2.2.29]# less 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   #啟動服務

 3 ./configure ; make  ; make install

生成makefile文件前,我們先看看看 ./configure  –help  的幫助說明

 

[root@Centos7 httpd-2.2.29]# ./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]
 
By default, `make install' will install all the files in
`/usr/local/apache2/bin', `/usr/local/apache2/lib' etc.  You can specify
an installation prefix other than `/usr/local/apache2' using `--prefix',
for instance `--prefix=$HOME'.
 
For better control, use the options below.
 
Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

4 .configure 生成makefile文件

#設置安排目錄為 /usr/local/http2  ,配置文件路徑為: /etc/http2

#.configure 的選項特別多,不一一舉例說明。一般設置這兩項就可以使用http服務

[root@centos68 httpd-2.2.29]# ./configure  --prefix=/usr/local/http2 --sysconfdir=//etc/http2
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
 
Configuring Apache Portable Runtime library ...
 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to " -g -O2 -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
 
Configuring Apache Portable Runtime Utility library...
 
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes

5  make make install

確保 ./configure 沒有問題才可以編譯 make,make使用的是./configure生成的makefile進行編譯的,

記得一定確保 echo $? 0才繼續下一步,不然后面是無法安裝成功的。

[root@centos68 httpd-2.2.29]# echo $?
0
[root@centos68 httpd-2.2.29]# make
Making all in srclib
make[1]: Entering directory `/testdir/httpd-2.2.29/srclib'
Making all in apr
make[2]: Entering directory `/testdir/httpd-2.2.29/srclib/apr'
make[3]: Entering directory `/testdir/httpd-2.2.29/srclib/apr'
/testdir/httpd-2.2.29/srclib/apr/build/mkdir.sh tools
/bin/sh /testdir/httpd-2.2.29/srclib/apr/libtool --silent --mode=compile gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I./include -I/testdir/httpd-2.2.29/srclib/apr/include/arch/unix -I./include/arch/unix -I/testdir/httpd-2.2.29/srclib/apr/include/arch/unix -I/testdir/httpd-2.2.29/srclib/apr/include -I/testdir/httpd-2.2.29/srclib/apr/include/private -I/testdir/httpd-2.2.29/srclib/apr/include/private  -o tools/gen_test_char.lo -c tools/gen_test_char.c && touch tools/gen_test_char.lo
/bin/sh /testdir/httpd-2.2.29/srclib/apr/libtool --silent --mode=link gcc -g -O2 -pthread   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I./include -I/testdir/httpd-2.2.29/srclib/apr/include/arch/unix -I./include/arch/unix -I/testdir/httpd-2.2.29/srclib/apr/include/arch/unix -I/testdir/httpd-2.2.29/srclib/apr/include -I/testdir/httpd-2.2.29/srclib/apr/include/private -I/testdir/httpd-2.2.29/srclib/apr/include/private   -no-install    -o tools/gen_test_char tools/gen_test_char.lo    -lrt -lcrypt  -lpthread
/testdir/httpd-2.2.29/srclib/apr/build/mkdir.sh include/private
[root@centos68 httpd-2.2.29]# echo $?
0
[root@centos68 httpd-2.2.29]# make install

6 設置二進制程序 庫文件 頭文件 幫助文件的路徑。

使用絕對路徑或相對路徑也可以使用命令,但是不是很方面,添加進系統環境變量 方便我們使用。

[root@centos68 httpd-2.2.29]# cd /usr/local/http2/
[root@centos68 http2]# ls
bin  build  cgi-bin  error  htdocs  icons  include  lib  logs  man  manual  modules
#bin 是安裝http服務的二進制程序,我們需要把 /usr/local/http2/bin文件加入到PATH環境變量。
#lib 是http服務需要的庫文件,我們需要把 /usr/local/http2/bin加載到系統中去
#include 是http需要使用的頭文件,需要把/usr/local/http2/include 映射到系統頭文件路徑
#man  是http的man幫助文檔
[root@centos68 http2]#

設置二進制程序加入PATH環境變量中(/etc/profile.d/)

[root@centos68 http2]# cat  /etc/profile.d/httpd.sh 
PATH=$PATH:/usr/local/http2/bin
#在 /etc/profile.d/新建一個文件后綴名為.sh的文件里面寫上需要添加的PATH路徑名,每次開機會自動加載
 
[root@centos68 http2]#  . /etc/profile.d/httpd.sh 
#讓他實時生效
[root@centos68 http2]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/http2/bin:/root/bin:
#查看PATH里面是否有我們設置好的命令路徑

設置lib加載到系統中(/etc/ld.so.conf.d/)

[root@centos68 http2]# cat /etc/ld.so.conf.d/httpd.conf 
/usr/local/http2/lib
#在 /etc/ld.so.conf.d/新建一個文件后綴名為.conf的文件里面寫上需要添加的lib路徑名,每次開機會自動加載
 
[root@centos68 http2]# ldconfig 
#手工加載一下 ldconfig
[root@centos68 http2]# ldconfig -p | grep /usr/local/http2/lib
#查看系統庫文件是否加載我們設置的路徑
libexpat.so.0 (libc6,x86-64) => /usr/local/http2/lib/libexpat.so.0
libexpat.so (libc6,x86-64) => /usr/local/http2/lib/libexpat.so
libaprutil-1.so.0 (libc6,x86-64) => /usr/local/http2/lib/libaprutil-1.so.0
libaprutil-1.so (libc6,x86-64) => /usr/local/http2/lib/libaprutil-1.so
libapr-1.so.0 (libc6,x86-64) => /usr/local/http2/lib/libapr-1.so.0
libapr-1.so (libc6,x86-64) => /usr/local/http2/lib/libapr-1.so

設置include映射到系統頭文件路徑(/usr/include/)

[root@centos68 http2]# cd /usr/include/
#系統頭文件路徑為 /usr/include
[root@centos68 include]# ln -sv /usr/local/http2/include/   http3
`http3' -> `/usr/local/http2/include/'
[root@centos68 include]# ll -ld http3
lrwxrwxrwx. 1 root root 25 Aug 23 09:10 http3 -> /usr/local/http2/include/
#我們建立一個鏈接到http的頭文件路徑即可
[root@centos68 include]#

設置man幫助

[root@centos68 man]# pwd  #找打http幫助文件的路徑
/usr/local/http2/man
[root@centos68 man]# vim  /etc/man.config man    #編輯man配置文件
........................................
#
# This file is also read by man in order to find how to call nroff, less, etc.,
# and to determine the correspondence between extensions and decompressors.
#
# MANBIN  /usr/local/bin/man
#
# Every automatically generated MANPATH includes these fields
#
MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
MANPATH /usr/local/http2/man    #按照格式填寫http  man幫助文件路徑
......................................

 

 

§·Centos 7  yum基礎知識

注意:yum只是rpm的前端管理工具,yum可以幫助我們解決大多數情況下 rpm包安裝的依賴性問題,本質上yum是基于rpm上存在的,yum安裝的所有包通過rpm也是可以正常管理的。

接下來我們簡單的學習下一下相關yum的知識。

學習大綱:

※·什么是rpm

※·什么是yum?

※·為什么使用yum?

※·yum的簡單原理?

※·yum的基礎操作?

 

※·什么是rpm?

windows上常見的程序包有 exe格式 msi格式的程序包,在centos上常見的程序包為 rpm的程序包,rpm全稱為(Redhat Package  Manager),rpm包是紅帽官方編譯好,之間在相對用的平臺上使用rpm命令安裝即可,rpm包常見的命名方式如下:

bash-4.2.46-19el7.x86_64.rpm

包名: bash (軟件包的名稱)

軟件版本:4.2.46(軟件的版本號)

編譯次數:19(重新編譯的次數,rpm包是在對平平臺上編譯好的,所以我們直接安裝就可以使用的)

系統平臺:el7(系統平臺,紅帽企業版7系統)

架構平臺:x86_64(系統架構為64為系統)

rpm有一系列的rpm包管理命令,就不一一舉例,比如:

 

rpm  -ivh  bash-4.2.46-19el7.x86_64.rpm (安裝軟件包顯示詳細的安裝過程)

rpm  -Fvh  bash-4.2.46-19el7.x86_64.rpm (升級或安裝程序包)

rpm  -qa | grep bash (查詢安裝過的包)

rpm  -e  bash (卸載程序包)

※·什么是yum?

CentOS: yum, dnf

YUM: YellowdogUpdate Modifier,rpm的前端程序,用來解決軟件包相關依賴性,可以在多個庫之間定位軟件包, up2date的替代工具

yum repository: yum repo,存儲了眾多rpm包,以及包的相關的元數據文件(放置于特定目錄repodata下)

文件服務器:

ftp://

http://

file:///

※·為什么使用yum?

由于rpm安裝軟件包的時候存在相互依賴的關系,需要安裝A程序包,提示我們必須安裝B程序包,安裝B程序包 ,提示我們必須安裝C程序包,特別是比較大型的軟件,包與包之間的依賴關系特別多,如果手動的去處理包與包之間的關系,特別消耗時間,

然后yum的出現就可以解決包與包之間的依賴關系,自動的去處理包與包之間的關系。

※·yum的基礎操作?

既然yum可以幫助我們處理包與包之間的關系,那我們如何使用yum工具呢?

yum是通過分析rpm的標頭數據后,根據各軟件依賴關系制作出有依賴關系的解決方案,然后可以自動處理軟件的依賴性問題,以解決軟件安裝或移除與升級的問題。

由于發行版的系統必須要先釋放出軟件,然后將軟件放置于yum服務器上面,可供用戶端來安裝于升級之用。

因此我們要是用yum時必須找到合適的yun server才行,每個yum server可能提供不同的軟件功能,yum server會根據功能進行分類,這里分類就所謂的倉庫。

那我們就必須知道 yum server 的地址(倉庫指向的路徑為 repodate目錄所在的父目錄)。

◎·如何配置yum倉庫(以阿里云 yum服務器為例)

·找到yum server的地址。(一定要記得倉庫地址中一定需要有 repodate的文件夾的)

http://mirrors.aliyun.com/centos/7/os/x86_64/

阿里云光盤centos 7 鏡像中的軟件包yum倉庫

 1.png

 http://mirrors.aliyun.com/centos/7/updates/x86_64/

阿里云centos 7 升級軟件包yum倉庫

2.png

 

http://mirrors.aliyun.com/centos/7/extras/x86_64/

阿里云centos 7 擴展軟件包yum倉庫

 3.png

 

 

http://mirrors.aliyun.com/centos/7/paas/x86_64/openshift-origin/

阿里云centos 7 paas軟件包yum倉庫

 4.png

 

·在本地添加阿里云yum倉庫地址

#備注:本地設置倉庫配置文件的路徑為:/etc/yum.repos.d/*.repo

[root@centos68 yum.repos.d]# cat /etc/yum.repos.d/tools.repo 
[aliyun-os] #設置在本地顯示的ID倉庫號
name=aliyun-os-mirrors  #設置在本地顯示的名稱
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/ #設置yum server的遠程地址
gpgcheck=1 #是否設置校驗信息
 
[aliyum-upadtes]
name=aliyun-upadtes-morrors
baseurl=http://mirrors.aliyun.com/centos/7/updates/x86_64/
gpgcheck=1
 
[aliyum-extras]
name=ailiyum-extras-mirrors
baseurl=http://mirrors.aliyun.com/centos/7/extras/x86_64/
gpgcheck=1

·本地倉庫設置好遠程服務器的鏈接后,查看倉庫的列表

[root@centos68 yum.repos.d]# yum repolist  #顯示設置倉庫的列表
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
aliyum-extras                                                                               | 3.4 kB     00:00     
aliyum-extras/primary_db                                                                    | 160 kB     00:00     
aliyum-upadtes                                                                              | 3.4 kB     00:00     
aliyum-upadtes/primary_db                                                                   | 7.1 MB     00:27     
aliyun-os                                                                                   | 3.6 kB     00:00     
aliyun-os/primary_db                                                                        | 5.3 MB     00:18     
repo id           repo name                                                                              status
aliyum-extras     ailiyum-extras-mirrors                                                                   375
aliyum-paas       aliyun-paas-mirrors                                                                        0
aliyum-upadtes    aliyun-upadtes-morrors                                                                 2,297
aliyun-os         aliyun-os-mirrors                                                                      9,007
repolist: 11,679
#顯示倉庫ID   倉庫的名稱     倉庫可以使用的軟件包的數量。
[root@centos68 yum.repos.d]#

 

小結:以上我們就搭建好鏈接外網的yum server,可以使用yum的相關命令安裝 升級 卸載等管理我們的軟軟件包。一定要記得baseurl的指向一定是在有 repodate文件夾的目錄

 

◎·搭建單機的yum倉庫(以光盤鏡像為例)

在實際工作中可能由于網速,或者其他無法上網的環境中,我們如何搭建我們單機的yum服務器呢,下面我們來搭建我們的單機yum服務器。

1.通過某些途徑找到rpm軟件包(光盤就有很多),也可以網上鏡像站點下載需要的軟件包;

2.把所有的軟件包放在一個目錄中,該目錄為baseurl需要指向的路徑地址;

3.使用 createrepo 的工具創建需要的  repodate文件夾。

使用createrepo命令的時候一定是在當前文件中,一定切記。

 

創建單機版的yun倉庫很簡單,其實我們的光盤就是一個被已經創建好的yun倉庫,我們可以直接使用的,我們掛載我們的光盤,設置光盤為本地yum倉庫試一試。

1.掛載光盤:

[root@centos68 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 5418104  42286668  12% /
tmpfs             502068      76    501992   1% /dev/shm
/dev/sda1         194241   34224    149777  19% /boot
/dev/sda3       20027260  123924  18879336   1% /testdir
/dev/sr0         3824484 3824484         0 100% /media/CentOS_6.8_Final
[root@centos68 ~]# cd /media/CentOS_6.8_Final/
[root@centos68 CentOS_6.8_Final]# ls
CentOS_BuildTag  EULA  images    Packages    repodata              RPM-GPG-KEY-CentOS-Debug-6     RPM-GPG-KEY-CentOS-Testing-6
EFI              GPL   isolinux  RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-6  RPM-GPG-KEY-CentOS-Security-6  TRANS.TBL
[root@centos68 CentOS_6.8_Final]# pwd
/media/CentOS_6.8_Final
[root@centos68 CentOS_6.8_Final]# 
#掛載上我們的光盤后,進入光盤目錄下,我們看到repodate的目錄,我們再到我們repo文件中指向該文件路徑即可

2.修改.repo文件

[root@centos68 CentOS_6.8_Final]# cat /etc/yum.repos.d/tools.repo 
[cdrom-tools]
baseurl=file:///media/CentOS_6.8_Final
gpgcheck=0
3.測試單機光盤yum倉庫
[root@centos68 CentOS_6.8_Final]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Repository 'cdrom-tools' is missing name in configuration, using id
Determining fastest mirrors
cdrom-tools                                                              | 4.0 kB     00:00 ... 
cdrom-tools/primary_db                                                    | 4.7 MB     00:00 ... 
repo id                    repo name                                                 status
cdrom-tools                cdrom-tools                                                6,696
repolist: 6,696
[root@centos68 CentOS_6.8_Final]#

yum配置管理(yum命令的使用)

Yum 命令創建repo文件

yum-config-manager

v生成172.16.0.1_cobbler_ks_mirror_CentOS-X-x86_64_.repo

yum-config-manager –add-repo= http://172.16.0.1/cobbler/ks_mirror/CentOS-X-x86_64/

vyum-config-manager –disable “倉庫名" 禁用倉庫

vyum-config-manager –enable “倉庫名” 啟用倉庫

舉例:使用yum-config-manager生成指定文件名稱的repo文件:

#使用該命令確實可以生成指定的repo的文件,但是ID號與name名稱不友好,建議還是自己手動修改下。

[root@centos68 ~]# yum-config-manager --add-repo=http://10.1.0.1/cobbler/ks_mirror/CentOS-X-x86_64/
Loaded plugins: fastestmirror, refresh-packagekit
adding repo from: http://10.1.0.1/cobbler/ks_mirror/CentOS-X-x86_64/
 
[10.1.0.1_cobbler_ks_mirror_CentOS-X-x86_64_]
name=added from: http://10.1.0.1/cobbler/ks_mirror/CentOS-X-x86_64/
baseurl=http://10.1.0.1/cobbler/ks_mirror/CentOS-X-x86_64/
enabled=1
 
[root@centos68 ~]# cat /etc/yum.repos.d/10.1.0.1_cobbler_ks_mirror_CentOS-X-x86_64_.repo 
 
[10.1.0.1_cobbler_ks_mirror_CentOS-X-x86_64_]
name=added from: http://10.1.0.1/cobbler/ks_mirror/CentOS-X-x86_64/
baseurl=http://10.1.0.1/cobbler/ks_mirror/CentOS-X-x86_64/
enabled=1
 
[root@centos68 ~]#

 

 

Yum 命令顯示倉庫列表與安裝軟件

◎顯示倉庫列表:

repolist[all|enabled|disabled]

◎顯示程序包:

list

# yum list [all | glob_exp1] [glob_exp2] […]

# yum list {available|installed|updates} [glob_exp1] […]

◎安裝程序包:

install package1 [package2] […]

reinstall package1 [package2] […] (重新安裝)

舉例顯示倉庫列表與yum軟件的安裝:

[root@centos68 ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
cdrom-tools                                           | 4.0 kB      00:00 ... 
cdrom-tools/primary_db                                 | 4.7 MB     00:00 ... 
ftp-server                                             | 4.0 kB      00:00     
ftp-server/primary_db                                   | 4.7 MB     00:00     
repo id         repo name                                                           status
cdrom-tools     cdrom-tools-centos7                                                   6,696
ftp-server       fte-server                                                            6,696
repolist: 13,392
[root@centos68 ~]#

yum安裝軟件:

[root@centos68 ~]# yum install zsh  #安裝只需要跟上軟件的包名即可
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:4.3.11-4.el6.centos.2 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
====================================================================================================
 Package      Arch        Version                         Repository                        Size
====================================================================================================
Installing:
 zsh       x86_64       4.3.11-4.el6.centos.2               cdrom-tools                      2.2 M
 
Transaction Summary
====================================================================================================Install       1 Package(s)
Total download size: 2.2 M
Installed size: 5.1 M
Is this ok [y/N]:

 

Yum 升級軟件包v降級 卸載軟件包

◎升級程序包:

update [package1] [package2] […]

downgrade package1 [package2] […] (降級)

◎檢查可用升級:

check-update

◎卸載程序包:

remove | erase package1 [package2] […]

舉例:

[root@centos68 ~]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
repo id           repo name                                                             status
cdrom-tools      cdrom-tools-centos7                                                   6,696
ftp-server       fte-server                                                            6,696
repolist: 13,392
 
[root@centos68 ~]# yum  check-update
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 
[root@centos68 ~]# yum remove tree
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.5.3-3.el6 will be erased
--> Finished Dependency Resolution
 
Dependencies Resolved
 
=========================================================================================================================================
 Package    Arch               Version                           Repository                      Size
====================================================================================================
Removing:
 tree        x86_64         1.5.3-3.el6                          @base                           65 k
 
Transaction Summary
====================================================================================================
Remove        1 Package(s)
 
Installed size: 65 k
Is this ok [y/N]:

 

Yum 軟件包查詢v

◎查看程序包information

info […]

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

provides | whatprovidesfeature1 [feature2] […]

◎清理本地緩存:

clean [ packages | metadata | expire-cache | rpmdb| plugins | all ]

◎構建緩存:

Makecache

舉例:

[root@centos68 ~]# yum info tree       #yum查詢軟件包的信息
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Installed Packages
Name        : tree
Arch        : x86_64
Version     : 1.5.3
Release     : 3.el6
Size        : 65 k
Repo        : installed
From repo   : base
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.
 
[root@centos68 ~]# rpm -qi tree     #rpm查詢軟件包的信息
Name        : tree                         Relocations: (not relocatable)
Version     : 1.5.3                             Vendor: CentOS
Release     : 3.el6                         Build Date: Wed 14 Jan 2015 08:21:02 PM CST
Install Date: Tue 26 Jul 2016 10:47:42 AM CST      Build Host: c6b9.bsys.dev.centos.org
Group       : Applications/File             Source RPM: tree-1.5.3-3.el6.src.rpm
Size        : 66687                            License: GPLv2+
Signature   : RSA/SHA1, Wed 14 Jan 2015 10:12:21 PM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://mama.indstate.edu/users/ice/tree/
Summary     : File system tree viewer
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.
[root@centos68 ~]# yum clean all     #yum清空本機緩存
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: cdrom-tools ftp-server
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@centos68 ~]# yum makecache    #建立本機緩存   使用repolist的時候也會生成緩存的
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
cdrom-tools                                        | 4.0 kB     00:00 ... 
cdrom-tools/group_gz                                | 226 kB     00:00 ... 
cdrom-tools/filelists_db                               | 6.3 MB     00:00 ... 
cdrom-tools/primary_db                              | 4.7 MB     00:00 ... 
cdrom-tools/other_db                                | 2.8 MB     00:00 ... 
ftp-server                                          | 4.0 kB     00:00     
ftp-server/group_gz                                  | 226 kB     00:00     
ftp-server/filelists_db                                 | 6.3 MB     00:00     
ftp-server/primary_db                                 | 4.7 MB     00:00     
ftp-server/other_db                                   | 2.8 MB     00:00     
Metadata Cache Created
[root@centos68 ~]#

Yum 搜索  依賴  事務日志

◎搜索:search   string1 [string2] […]

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

[root@Centos7 ~]# yum  search  zsh  #模糊搜索我們需要的軟件包的名稱
Loaded plugins: fastestmirror, langpacks
Repository 'cdrom-Centos7' is missing name in configuration, using id
Repository 'magedeu-centos7' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
==========================N/S matched: zsh ======================
zsh-html.x86_64 : Zsh shell manual in html format
zsh.x86_64 : Powerful interactive shell
 
  Name and summary matches only, use "search all" for everything.
[root@Centos7 ~]#

 

◎查看指定包所依賴的capabilities

deplist   package1 [package2] […]

[root@Centos7 ~]# yum deplist bash   #看看bash依賴哪些文件
Loaded plugins: fastestmirror, langpacks
Repository 'cdrom-Centos7' is missing name in configuration, using id
Repository 'magedeu-centos7' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
package: bash.x86_64 4.2.46-19.el7
  dependency: libc.so.6(GLIBC_2.15)(64bit)  #依賴的庫文件
   provider: glibc.x86_64 2.17-105.el7  #由那個程序提供的
  dependency: libdl.so.2()(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libdl.so.2(GLIBC_2.2.5)(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libtinfo.so.5()(64bit)
   provider: ncurses-libs.x86_64 5.9-13.20130511.el7
  dependency: rtld(GNU_HASH)
   provider: glibc.x86_64 2.17-105.el7
   provider: glibc.i686 2.17-105.el7
package: bash.x86_64 4.2.46-19.el7
  dependency: libc.so.6(GLIBC_2.15)(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libdl.so.2()(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libdl.so.2(GLIBC_2.2.5)(64bit)
   provider: glibc.x86_64 2.17-105.el7
  dependency: libtinfo.so.5()(64bit)
   provider: ncurses-libs.x86_64 5.9-13.20130511.el7
  dependency: rtld(GNU_HASH)
   provider: glibc.x86_64 2.17-105.el7
   provider: glibc.i686 2.17-105.el7
#由上面我們可以看出,如果我們手動的處理依賴關系,我們需要安裝非常多的軟件和包,如果yum倉庫中有依賴的軟件我們的就可以使用yum解決依賴問題。

 

◎查看yum事務歷史:

history [info|list|packages-list|packages-info|

summary|addon-info|redo|undo|

rollback|new|sync|stats]

yum history[查看安裝日志]

yum history info 6[查看安裝日志的詳細信息]

yum history undo 6[取消第六步的操作(如果是安裝軟件包,就卸載軟件;如果是卸載軟件包,就安裝軟件包)]

◎日志:/var/log/yum.log

舉例:

[root@Centos7 ~]# yum history   #查看yum操作的事務日志
Loaded plugins: fastestmirror, langpacks
Repository 'cdrom-Centos7' is missing name in configuration, using id
Repository 'magedeu-centos7' is missing name in configuration, using id
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     5 | root,,magedu <root>      | 2016-08-23 13:30 | Erase          |    1   #卸載了一個軟件包,
     4 | root,,magedu <root>      | 2016-08-22 19:55 | Install        |    1   
     3 | root,,magedu <root>      | 2016-08-22 19:55 | Install        |    3   
     2 | root,,magedu <root>      | 2016-08-22 19:54 | Install        |   53  <
     1 | System <unset>           | 2016-07-21 11:23 | Install        | 1243 > 
history list
[root@Centos7 ~]# yum history info 5    #查看第五條事務日志的詳細信息
Loaded plugins: fastestmirror, langpacks
Repository 'cdrom-Centos7' is missing name in configuration, using id
Repository 'magedeu-centos7' is missing name in configuration, using id
Transaction ID : 5
Begin time     : Tue Aug 23 13:30:24 2016
Begin rpmdb    : 1303:29dbb60eee14d40a7fdee2d6f908438cc800ec8c
End time       :            13:30:25 2016 (1 seconds)
End rpmdb      : 1302:e8af4622ce2f76282daa602b5f495b254cd11b77
User           : root,,magedu <root>
Return-Code    : Success
Command Line   : remove tree
Transaction performed with:
    Installed     rpm-4.11.3-17.el7.x86_64                      @anaconda
    Installed     yum-3.4.3-132.el7.centos.0.1.noarch           @anaconda
    Installed     yum-plugin-fastestmirror-1.1.31-34.el7.noarch @anaconda
Packages Altered:
Loading mirror speeds from cached hostfile
    Erase tree-1.6.0-10.el7.x86_64 @?cdrom-Centos7  #卸載了 tree這個軟件包
history info
[root@Centos7 ~]# yum history undo 5  #取消第5步的操作。
Loaded plugins: fastestmirror, langpacks
Repository 'cdrom-Centos7' is missing name in configuration, using id
Repository 'magedeu-centos7' is missing name in configuration, using id
Undoing transaction 5, from Tue Aug 23 13:30:24 2016
Loading mirror speeds from cached hostfile
    Erase tree-1.6.0-10.el7.x86_64 @?cdrom-Centos7
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
====================================================================================================
 Package       Arch              Version      Repository                           Size
====================================================================================================
Installing:
 tree        x86_64         1.6.0-10.el7           cdrom-Centos7                        46 k
 
Transaction Summary
====================================================================================================
Install  1 Package   #取消第五步卸載tree操作后,yum自動安裝tree軟件包。
 
Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]:

Yum 命令使用6

◎安裝及升級本地程序包:

* local   install   rpm   file1 [rpmfile2] […]

(install替代)

* local  update   rpm   file1 [rpmfile2] […]

(update替代)

◎包組管理的相關命令:

Groupinstall   group1 [group2] […]

Groupupdate  group1 [group2] […]

Grouplist     [hidden] [groupwildcard] […][Hidden 顯示隱藏包組(過期的,不常用的包)]

Groupremove  group1 [group2] […]

Groupinfo     group1 […]

 

 

 

§·數組課后練習

輸入若干個數值存入數組中,采用冒泡算法進行升序或降序排序?

解題思路:比如我們有4個數字,比如  $a=5 , $b=9 , $c=7 , $d=8.

我們把 $a的值與后面每個數字比較,有$b >$a數值大的時候,我們把$a的值等于$b的值,$b的值為$a的值,比較到最后 $a的值為 9。

再進行第二輪對比較,由于$a保存的是數組中的最大值,排除$a的比較,讓$b取得最大值,一直循序下去即可。

最后打印$a  $b  $c  $d 即可 :

 

#!/bin/bash
 declare -i min    #申明整數變量保存最小值傳遞下去。
 declare -a nums  #申明數組保存用戶輸入的數值。
 echo -en "please input int numbers:   "  #提示用戶輸入整數型的數字。
 read -a nums  #交互式輸入
 
#判斷用戶輸入的是不是整數,不是整數就提醒用戶輸入,退出腳本。
   for  i  in  $(seq 0  $[${#nums[*]}-1])  ;  do
      ! expr ${nums[$i]} + 10 &>/dev/null && echo "please input right numbers :" && exit 1   
   done 
 
#第一個循序取得數組中第一個值與后面所有的數組的其它值進行比較;
     for  j  in  $(seq 0 $[${#nums[*]}-1])  ;  do
 
#第二個循環從上一個數字變量后一個元素開始向后面比較
           for  k  in $(seq $[$j+1] $[${#nums[*]}-1])   ; do
                if  [ ${nums[$j]} -lt ${nums[$k]}  ];then
#比較數組中前面的一個數字如果小于后面的數值,則把最大值給前面的數組元素,后一個保留前一個較小數值
                  min=${nums[$j]}
                  nums[$j]=${nums[$k]}
                  nums[$k]=$min
               fi
              done
    done
 
           echo "${nums[*]}"   #最后打印所有的元素即可
[root@Centos7 shells]# bash array1.sh   #測試結果
please input int numbers:   12 34 56 78 90 54 67 32 54 31 2 6 9 
90 78 67 56 54 54 34 32 31 12 9 6 2
[root@Centos7 shells]#

原創文章,作者:linux_root,如若轉載,請注明出處:http://www.www58058.com/39327

(0)
linux_rootlinux_root
上一篇 2016-08-24
下一篇 2016-08-24

相關推薦

  • Linux網絡配置

    Linux網絡基礎配置 將Linux主機接入到網絡,需要配置網絡相關設置。 一般包括如下內容:     主機名     IP/netmask     路由:默認網關     DNS服務器  …

    Linux干貨 2016-09-09
  • 軟鏈接,硬鏈接區別

    軟硬鏈接涉及文件系統inode, 區分于inode號,硬鏈接inode號與鏈接文件相同,且創建鏈接不占空間.而軟鏈接占名稱字節個空間,且inode號與鏈接文件不同; 兩者查找inode號命令都可查找inode號,命令為ls -i,如需查找本目錄要加d; 在創建鏈接環境上,硬鏈接只能在同分區創建一個,不能跨分區創建;而軟鏈接可以跨分區創建多個鏈接文件且可以多個…

    Linux干貨 2016-10-20
  • 第15天:腳本關鍵字,函數

    http://note.youdao.com/noteshare?id=2ea9bcdf745a47bf65f0cef6e706ccaf

    Linux干貨 2016-09-06
  • 第八周作業腳本練習

    1、寫一個腳本,使用ping命令探測172.16.250.1-172.16.250.254之間的所有主機的在線狀態;      在線的主機使用綠色顯示;      不在線的主使用紅色顯示;          &…

    Linux干貨 2017-02-01
  • 從LongAdder看更高效的無鎖實現

    接觸到AtomicLong的原因是在看guava的LoadingCache相關代碼時,關于LoadingCache,其實思路也非常簡單清晰:用模板模式解決了緩存不命中時獲取數據的邏輯,這個思路我早前也正好在項目中使用到。 言歸正傳,為什么說LongAdder引起了我的注意,原因有二: 作者是Doug lea ,地位實在舉足輕重。 他說這個比AtomicLon…

    Linux干貨 2016-06-01
  • 文件查找命令之find

    文件查找命令之find   特點:實時查找,精確查找,由于find是全磁盤文件查找所有查找速度要比locate略慢一些。   find查找功能強大,下面主要介紹find查找條件的一個重要特性–德·摩根定律     德·摩根定律      非(A &&B)=(非A…

    Linux干貨 2016-08-16

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-08-25 15:24

    文章結構清晰,層次明了,內容上總結的較為詳細,同時通過示例操作介紹清楚了源碼安裝的操作及安裝后的配置??傮w來說是一篇不錯的文章。

欧美性久久久久