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 Modifierrpm的前端程序,用来解决软件包相关依赖性,可以在多个库之间定位软件包, 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.178linux.com/39327

(0)
上一篇 2016-08-24 10:12
下一篇 2016-08-24 10:12

相关推荐

  • 路由配置

      RA和RB为linux系统,此处虚拟成为路由器,在每一台路由器的接口上设置好ip之后开始配置路由表 ip地址配置如下: RA:eth1:192.168.100.1/24    eth0:10.1.0.1/8       主机A:10.1.0.25/8 RB: eth1:192.168.100.2…

    Linux干货 2016-09-07
  • 正则表达式基础

    正则表达式正则表达式    元字符:        .       点表示任意单个字符 最少一次        \w      匹配字母、数字、下划线、或汉字。        \s      匹配任意空白字符        \d      匹配数字        \b      匹配字符的开始或结束        ^       匹配首字符        $…

    Linux干货 2017-11-14
  • linux基础学习第十二天(shell函数、数组以及yum使用及编译安装)

    2016-08-18 授课内容: shell编程基础(select 循环与菜单、函数) yum管理、定制yum仓库 select 循环与菜单         select variable in list       &…

    Linux干货 2016-08-21
  • Linux基础之加密通讯过程详解

    加密通讯过程详解 第一阶段 客户端->服务器端 向服务器声明自己的加密通讯协议版本,ssl或者tls 支持的加密算法 支持的压缩算法 第二阶段 服务器端->客户端 向客户端确认使用的加密通讯协议版本 确认的加密方法 确认压缩方法 服务器端证书 第三阶段 客户端->服务器端 客户端验证服务器端证书 发证机构 证书完整性 证书持有者 证书有效期…

    2017-09-16
  • Shell编程(1)

    Shell编程:     编程语言:机器语言、汇编语言、高级语言         高级语言:             静…

    Linux干货 2016-08-18
  • iptables详解

    iptables的工作机制 iptables有五个钩子函数(hook functions),也叫五个规则链。 1.PREROUTING (路由前) 2.INPUT (数据包流入口) 3.FORWARD (转发关卡) 4.OUTPUT(数据包出口) 5.POSTROUTING(路由后)   这是NetFilter规定的五个规则链,任何一个数据包,只要…

    Linux干货 2017-03-15

评论列表(1条)

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

    文章结构清晰,层次明了,内容上总结的较为详细,同时通过示例操作介绍清楚了源码安装的操作及安装后的配置。总体来说是一篇不错的文章。