6.26-6.27任务

7.1 安装软件包的三种方法

在linux下,安装软件包和Windows下差不多,有三种方法。

1)rpm工具 ->redhat package manager

2)yum工具 ->python开发的管理rpm的工具,可以自动安装依赖

3)源码安装 ->按照开发者的readme文档查看安装说明

7.2 rpm包介绍

为了演示rpm的用法,我们要挂载光盘,使用光盘里的rpm包。

[root@localhost ~]# mount -o ro /dev/cdrom /mnt/
[root@localhost ~]# ls /mnt/
CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL

我们列出10个包

[root@localhost Packages]# cd /mnt/Packages/
[root@localhost Packages]# ls | head
389-ds-base-1.3.6.1-16.el7.x86_64.rpm
389-ds-base-libs-1.3.6.1-16.el7.x86_64.rpm
abattis-cantarell-fonts-0.0.25-1.el7.noarch.rpm
abrt-2.1.11-48.el7.centos.x86_64.rpm
abrt-addon-ccpp-2.1.11-48.el7.centos.x86_64.rpm
abrt-addon-kerneloops-2.1.11-48.el7.centos.x86_64.rpm
abrt-addon-pstoreoops-2.1.11-48.el7.centos.x86_64.rpm
abrt-addon-python-2.1.11-48.el7.centos.x86_64.rpm
abrt-addon-vmcore-2.1.11-48.el7.centos.x86_64.rpm
abrt-addon-xorg-2.1.11-48.el7.centos.x86_64.rpm

以上的命名方式为包名+版本号+发布版本号+平台。

对于abrt-addon-kerneloops-2.1.11-48.el7.centos.x86_64.rpm
包名         abrt-addon-kerneloops
版本号       2.1.11
发布版本号    48.el7.centos
平台         x86_64

7.3 rpm工具用法

rpm命令可以安装rpm包。

使用-i选项(install)安装,-v(verbose)是显示信息,-h(hash)配合-v更人性化的打印信息。

[root@localhost Packages]# ls zsh-5.0.2-28.el7.x86_64.rpm 
zsh-5.0.2-28.el7.x86_64.rpm
[root@localhost Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
Updating / installing...
   1:zsh-5.0.2-28.el7                 ################################# [100%]

升级一个工具,使用-U(update)选项。

[root@localhost Packages]# rpm -Uvh zsh-5.0.2-28.el7.x86_64.rpm 
Preparing...                          ################################# [100%]
	package zsh-5.0.2-28.el7.x86_64 is already installed

卸载一个安装包,只需要知道包名即可,使用-e选项

[root@localhost Packages]# rpm -e zsh

如果没有报错,即卸载成功;如果有错误,说明包被别的工具依赖。

查询已经安装的包使用-q(query)a(all)选项。

[root@localhost Packages]# rpm -qa
firewalld-0.4.4.4-6.el7.noarch
grub2-common-2.02-0.64.el7.centos.noarch
grub2-2.02-0.64.el7.centos.x86_64
setup-2.8.71-7.el7.noarch
NetworkManager-team-1.8.0-9.el7.x86_64
basesystem-10.0-7.el7.centos.noarch
......

也可以查询某一个包是否被安装

[root@localhost Packages]# rpm -q ppp
package ppp is not installed
[root@localhost Packages]# rpm -q systemd
systemd-219-42.el7.x86_64

也可以查询某一个包的详细信息-qi(info)

[root@localhost Packages]# rpm -qi systemd
Name        : systemd
Version     : 219
Release     : 42.el7
Architecture: x86_64
Install Date: Mon 11 Jun 2018 04:00:10 PM CST
Group       : Unspecified
Size        : 22001263
License     : LGPLv2+ and MIT and GPLv2+
Signature   : RSA/SHA256, Fri 11 Aug 2017 04:00:28 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : systemd-219-42.el7.src.rpm
Build Date  : Sat 05 Aug 2017 02:38:39 PM CST
Build Host  : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.freedesktop.org/wiki/Software/systemd
Summary     : A System and Service Manager
Description :
systemd is a system and service manager for Linux, compatible with
SysV and LSB init scripts. systemd provides aggressive parallelization
capabilities, uses socket and D-Bus activation for starting services,
offers on-demand starting of daemons, keeps track of processes using
Linux cgroups, supports snapshotting and restoring of the system
state, maintains mount and automount points and implements an
elaborate transactional dependency-based service control logic. It can
work as a drop-in replacement for sysvinit.

使用-ql(list)可以查询某个包会安装什么文件在linux上

[root@localhost Packages]# rpm -ql vim-enhanced
/etc/profile.d/vim.csh
/etc/profile.d/vim.sh
/usr/bin/rvim
/usr/bin/vim
/usr/bin/vimdiff
/usr/bin/vimtutor

使用-qf(format)可以根据一个绝对路径查询此文件由哪个包安装。

[root@localhost Packages]# rpm -qf /usr/bin/vim
vim-enhanced-7.4.160-4.el7.x86_64
[root@localhost Packages]# rpm -qf /usr/bin/ls
coreutils-8.22-18.el7.x86_64
[root@localhost Packages]# rpm -qf /usr/bin/``
filesystem-3.2-21.el7.x86_64

反引号的作用就是将反引号内的Linux命令先执行,然后将执行结果赋予变量。尽管可以通过输入字符或者字符串来创建变量值,也可以获取来自于其他Linux命令的值。为把Linux命令的结果赋予变量,实现需要执行这个命令。如果在命令行上把Linux命令放在反引号中,这个命令会首先被执行,其结果会成为命令行的一个参数。在赋值时,通过把命令放在反引号中,以便于首先执行,命令的执行结果会被赋予一个变量。反引号可以被视为由要执行命令组成的表达式,其结果会被赋予变量。组成命令的字符本身不会被赋予。

[root@localhost Packages]# a=`ls /tmp`
[root@localhost Packages]# echo $a
d6z systemd-private-79b5a286062e4f01a853a99c7fe3f69b-vgauthd.service-wYmtaQ systemd-private-79b5a286062e4f01a853a99c7fe3f69b-vmtoolsd.service-ye2DL0 xxx
[root@localhost Packages]# ls /tmp
d6z  systemd-private-79b5a286062e4f01a853a99c7fe3f69b-vgauthd.service-wYmtaQ  systemd-private-79b5a286062e4f01a853a99c7fe3f69b-vmtoolsd.service-ye2DL0  xxx

 

 

7.4 yum工具用法

使用rpm安装一个包的时候 我们需要首先安装依赖包

[root@localhost Packages]# rpm -ivh ./texlive-2012-38.20130427_r30134.el7.x86_64.rpm 
error: Failed dependencies:
	texlive-scheme-basic is needed by texlive-2:2012-38.20130427_r30134.el7.x86_64
	texlive-collection-latexrecommended is needed by texlive-2:2012-38.20130427_r30134.el7.x86_64
	tex-kpathsea is needed by texlive-2:2012-38.20130427_r30134.el7.x86_64
	tex-tetex is needed by texlive-2:2012-38.20130427_r30134.el7.x86_64

而yum的优势就是帮你自动安装这些依赖包。

[root@localhost Packages]# yum install texlive
................
Transaction Summary
=====================================================
Install  1 Package  (+248 Dependent packages)
Upgrade             (   1 Dependent package)

Total download size: 123 M
Is this ok [y/d/N]: n
Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2018-06-27.02-59.QTteas.yumtx

yum list命令可以列出所有可以安装的包。

[root@localhost Packages]# yum list | head -20
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.163.com
 * updates: mirrors.huaweicloud.com
Installed Packages
GeoIP.x86_64                                1.5.0-11.el7               @anaconda
NetworkManager.x86_64                       1:1.8.0-9.el7              @anaconda
NetworkManager-libnm.x86_64                 1:1.8.0-9.el7              @anaconda
NetworkManager-team.x86_64                  1:1.8.0-9.el7              @anaconda
NetworkManager-tui.x86_64                   1:1.8.0-9.el7              @anaconda
NetworkManager-wifi.x86_64                  1:1.8.0-9.el7              @anaconda
acl.x86_64                                  2.2.51-12.el7              @anaconda
aic94xx-firmware.noarch                     30-6.el7                   @anaconda
alsa-firmware.noarch                        1.0.28-2.el7               @anaconda
alsa-lib.x86_64                             1.1.3-3.el7                @anaconda
alsa-tools-firmware.x86_64                  1.1.0-1.el7                @anaconda
audit.x86_64                                2.7.6-3.el7                @anaconda
audit-libs.x86_64                           2.7.6-3.el7                @anaconda
authconfig.x86_64                           6.2.8-30.el7               @anaconda


Exiting on Broken Pipe

左侧是包的名字+一些信息,中间一列是版本号,最后是仓库名。

仓库名是从/etc/yum.repos.d/中来的。

[root@localhost Packages]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo

#cat CentOS-Base.repo会出现[base]等仓库名(被[]包括)。

搜索一个包使用yum search命令,不论大小写都能搜到,search搜索的是后面的字符串而不是包名

[root@localhost Packages]# yum search vim
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.163.com
 * updates: mirrors.huaweicloud.com
=========================================================================== N/S matched: vim ===========================================================================
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor

  Name and summary matches only, use "search all" for everything.

想搜索的更精确我们使用yum list + grep形式

[root@localhost Packages]# yum list | grep 'vim'
vim-common.x86_64                           2:7.4.160-4.el7            @base    
vim-enhanced.x86_64                         2:7.4.160-4.el7            @base    
vim-filesystem.x86_64                       2:7.4.160-4.el7            @base    
vim-minimal.x86_64                          2:7.4.160-2.el7            @anaconda
protobuf-vim.x86_64                         2.5.0-8.el7                base     
vim-X11.x86_64                              2:7.4.160-4.el7            base     
vim-minimal.x86_64                          2:7.4.160-4.el7            base 

安装一个包使用yum install 命令,相信大家已经不陌生了,-y选项不询问直接安装。

yum grouplist可以列出所有可用的组。

[root@localhost Packages]# yum grouplist
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.163.com
 * updates: mirrors.huaweicloud.com
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done

我们之前安装系统的时候,有很多组的组件是没有安装的,安装完系统后,我们依然可以使用yum查询可以被安装的组和已经被安装的组。

安装组使用命令yum groupinstall

[root@localhost Packages]# yum groupinstall 'Basic Web Server'

yum remove命令可以移除一个包,它会列出所有被卸载的包。解决所有的依赖关系。

同样,yum update可以升级一个包。

[root@localhost Packages]# yum update vim
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.163.com
 * updates: mirrors.huaweicloud.com
No packages marked for update

如果后面没有跟包名,默认升级所有的包,包括内核,系统本身。

最后,yum provides可以查看某个命令的安装包。

[root@localhost Packages]# yum provides "/*/vim"
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.163.com
 * updates: mirrors.huaweicloud.com
updates/7/x86_64/filelists_db                                                                                                                    | 1.5 MB  00:00:00     
cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system
Repo        : base
Matched from:
Filename    : /usr/share/cmake/editors/vim



2:docker-unit-test-1.13.1-53.git774336d.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
Repo        : extras
Matched from:
Filename    : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim



2:docker-unit-test-1.13.1-58.git87f2fab.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
Repo        : extras
Matched from:
Filename    : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim



2:docker-unit-test-1.13.1-63.git94f4240.el7.centos.x86_64 : Automates deployment of containerized applications - for running unit tests
Repo        : extras
Matched from:
Filename    : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/runc-e9c345b3f906d5dc5e8100b05ce37073a811c74a/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
Filename    : /var/lib/docker-unit-test/containerd-296f1f80d6c6a83cc625163f863e53d3287328ee/vendor/src/github.com/docker/docker/contrib/syntax/vim



git-1.8.3.1-13.el7.x86_64 : Fast Version Control System
Repo        : base
Matched from:
Filename    : /usr/share/doc/git-1.8.3.1/contrib/vim



git-1.8.3.1-14.el7_5.x86_64 : Fast Version Control System
Repo        : updates
Matched from:
Filename    : /usr/share/doc/git-1.8.3.1/contrib/vim



2:vim-common-7.4.160-4.el7.x86_64 : The common files needed by any version of the VIM editor
Repo        : base
Matched from:
Filename    : /usr/share/vim



2:vim-enhanced-7.4.160-4.el7.x86_64 : A version of the VIM editor which includes recent enhancements
Repo        : base
Matched from:
Filename    : /usr/bin/vim



2:vim-enhanced-7.4.160-4.el7.x86_64 : A version of the VIM editor which includes recent enhancements
Repo        : @base
Matched from:
Filename    : /usr/bin/vim


 

7.5 yum搭建本地仓库

有时候yum因为不能联网而不能使用,这时候我们可以自己搭建一个本地的仓库。

首先我们挂载镜像到/mnt目录下,你也可以把安装包拷贝到本地的一个目录上去。

然后做一个备份

[root@localhost Packages]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak
[root@localhost Packages]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# ls ../yum* -d
../yum  ../yum.conf  ../yum.repos.d  ../yum.repos.d.bak
[root@localhost yum.repos.d]# ls ../yum.repos.d.bak/
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# rm ./* -fr
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# vim dvd.repo
[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpgcheck=0

然后我们清除一下缓存,就可以看到

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: dvd
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum list
..................
xorg-x11-server-utils.x86_64                    7.7-20.el7            dvd      
xorg-x11-utils.x86_64                           7.5-22.el7            dvd      
xorg-x11-xauth.x86_64                           1:1.0.9-1.el7         dvd                                                     

这样我们的本地源就弄好了。

我们就可以把所有的rpm文件使用yum来管理了。

在配置文件/etc/yum.conf中有一个选项是keepcache

[root@localhost yum.repos.d]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

如果已经安装的工具不保留安装包就置0,想保留就置1。安装包会保存在cachedir里。

扩展:

搭建一个局域网http的yum源 

7.6yum更换国内源

有时候系统自带的yum源由于网络速度太慢(国外网站)可以将其更改为国内的yum源。

使用wget或者curl下载yum源的repo文件

[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2018-06-27 03:51:22--  http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 59.111.0.251
Connecting to mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘CentOS7-Base-163.repo’

100%[==============================================================================================================================>] 1,572       --.-K/s   in 0s      

2018-06-27 03:51:22 (349 MB/s) - ‘CentOS7-Base-163.repo’ saved [1572/1572]

[root@localhost yum.repos.d]# ls
CentOS7-Base-163.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo

可以使用yum repolist all 查看我们所有可用的repo

[root@localhost yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
repo id                                   repo name                                  status
C7.0.1406-base/x86_64                     CentOS-7.0.1406 - Base                     disabled
C7.0.1406-centosplus/x86_64               CentOS-7.0.1406 - CentOSPlus               disabled
C7.0.1406-extras/x86_64                   CentOS-7.0.1406 - Extras                   disabled
C7.0.1406-fasttrack/x86_64                CentOS-7.0.1406 - CentOSPlus               disabled
C7.0.1406-updates/x86_64                  CentOS-7.0.1406 - Updates                  disabled
C7.1.1503-base/x86_64                     CentOS-7.1.1503 - Base                     disabled
C7.1.1503-centosplus/x86_64               CentOS-7.1.1503 - CentOSPlus               disabled
C7.1.1503-extras/x86_64                   CentOS-7.1.1503 - Extras                   disabled
C7.1.1503-fasttrack/x86_64                CentOS-7.1.1503 - CentOSPlus               disabled
C7.1.1503-updates/x86_64                  CentOS-7.1.1503 - Updates                  disabled
C7.2.1511-base/x86_64                     CentOS-7.2.1511 - Base                     disabled
C7.2.1511-centosplus/x86_64               CentOS-7.2.1511 - CentOSPlus               disabled
C7.2.1511-extras/x86_64                   CentOS-7.2.1511 - Extras                   disabled
C7.2.1511-fasttrack/x86_64                CentOS-7.2.1511 - CentOSPlus               disabled
C7.2.1511-updates/x86_64                  CentOS-7.2.1511 - Updates                  disabled
C7.3.1611-base/x86_64                     CentOS-7.3.1611 - Base                     disabled
C7.3.1611-centosplus/x86_64               CentOS-7.3.1611 - CentOSPlus               disabled
C7.3.1611-extras/x86_64                   CentOS-7.3.1611 - Extras                   disabled
C7.3.1611-fasttrack/x86_64                CentOS-7.3.1611 - CentOSPlus               disabled
C7.3.1611-updates/x86_64                  CentOS-7.3.1611 - Updates                  disabled
base/7/x86_64                             CentOS-7 - Base - 163.com                  enabled: 9,911
base-debuginfo/x86_64                     CentOS-7 - Debuginfo                       disabled
base-source/7                             CentOS-7 - Base Sources                    disabled
c7-media                                  CentOS-7 - Media                           disabled
centosplus/7/x86_64                       CentOS-7 - Plus - 163.com                  disabled
centosplus-source/7                       CentOS-7 - Plus Sources                    disabled
cr/7/x86_64                               CentOS-7 - cr                              disabled
extras/7/x86_64                           CentOS-7 - Extras - 163.com                enabled:   313
extras-source/7                           CentOS-7 - Extras Sources                  disabled
fasttrack/7/x86_64                        CentOS-7 - fasttrack                       disabled
updates/7/x86_64                          CentOS-7 - Updates - 163.com               enabled:   711
updates-source/7                          CentOS-7 - Updates Sources                 disabled
repolist: 10,935

7.7 yum下载rpm包

有时候163的源不全,这时候我们可以安装一个扩展的源。

[root@localhost yum.repos.d]# yum install epel-release
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                      Arch                                   Version                               Repository                              Size
========================================================================================================================================================================
Installing:
 epel-release                                 noarch                                 7-11                                  extras                                  15 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: t
Is this ok [y/d/N]: y       
Downloading packages:
epel-release-7-11.noarch.rpm                                                                                                                     |  15 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                                                             1/1 
  Verifying  : epel-release-7-11.noarch                                                                                                                             1/1 

Installed:
  epel-release.noarch 0:7-11                                                                                                                                            

Complete!
[root@localhost yum.repos.d]# ls
CentOS7-Base-163.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel-testing.repo
CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo

epel这个源来自Fedora,同样也是redhat公司出品,它提供了海量的rpm包。

那我想把这些包的rpm文件保存下来,使用--downloadonly

[root@localhost yum.repos.d]# yum install zsh --downloadonly
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                              Arch                                    Version                                       Repository                             Size
========================================================================================================================================================================
Installing:
 zsh                                  x86_64                                  5.0.2-28.el7                                  base                                  2.4 M

Transaction Summary
========================================================================================================================================================================
Install  1 Package

Total download size: 2.4 M
Installed size: 5.6 M
Background downloading packages, then exiting:
zsh-5.0.2-28.el7.x86_64.rpm                                                                                                                      | 2.4 MB  00:00:00     
exiting because "Download Only" specified
[root@localhost yum.repos.d]# find /var/cache/ -name "zsh*"
/var/cache/yum/x86_64/7/base/packages/zsh-5.0.2-28.el7.x86_64.rpm

如果想指定下载目录,使用--downloaddir=/dir

[root@localhost yum.repos.d]# yum install zsh --downloadonly --downloaddir=/tmp
.............
[root@localhost yum.repos.d]# find /tmp -name "zsh*"
/tmp/zsh-5.0.2-28.el7.x86_64.rpm

如果这个工具已经被安装了,但是我们还是想下载这个文件,此时使用install已经不能下载了,我们使用yum reinstall命令即可。

[root@localhost yum.repos.d]# yum install zsh --downloadonly --downloaddir=/root
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * epel: mirrors.huaweicloud.com
Package zsh-5.0.2-28.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost yum.repos.d]# ls /root/
anaconda-ks.cfg  xxx
[root@localhost yum.repos.d]# yum reinstall zsh --downloadonly --downloaddir=/root
......................
[root@localhost yum.repos.d]# ls /root/
anaconda-ks.cfg  xxx  zsh-5.0.2-28.el7.x86_64.rpm

除此之外,使用yumdownloader命令可达到相同的效果。

7.8-7.9源码包安装

我们用httpd演示源码包的安装。

约定我们把源码包下载到/usr/local/src/ ,先下载一个apache

[root@localhost src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.32.tar.gz
--2018-06-27 04:15:07--  http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.32.tar.gz
Resolving mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.8.193|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9070595 (8.7M) [application/octet-stream]
Saving to: ‘httpd-2.4.32.tar.gz’

100%[==============================================================================================================================>] 9,070,595   4.91MB/s   in 1.8s   

2018-06-27 04:15:09 (4.91 MB/s) - ‘httpd-2.4.32.tar.gz’ saved [9070595/9070595]

然后找到这个源文件的说明文档

[root@localhost src]# ls
httpd-2.4.32.tar.gz
[root@localhost src]# tar zxf httpd-2.4.32.tar.gz 
[root@localhost src]# ls
httpd-2.4.32  httpd-2.4.32.tar.gz
[root@localhost src]# cd httpd-2.4.32
[root@localhost httpd-2.4.32]# ls
ABOUT_APACHE     apache_probes.d  BuildBin.dsp    config.layout  emacs-style  httpd.spec      LAYOUT        LICENSE       NOTICE         README.cmake      srclib
acinclude.m4     ap.d             buildconf       configure      httpd.dep    include         libhttpd.dep  Makefile.in   NWGNUmakefile  README.platforms  support
Apache-apr2.dsw  build            CHANGES         configure.in   httpd.dsp    INSTALL         libhttpd.dsp  Makefile.win  os             ROADMAP           test
Apache.dsw       BuildAll.dsp     CMakeLists.txt  docs           httpd.mak    InstallBin.dsp  libhttpd.mak  modules       README         server            VERSIONING

在文件INSTALL中会有说明如何安装,README文件中有对此工具的说明

[root@localhost httpd-2.4.32]# cat INSTALL 

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

以上即如何安装。

[root@localhost httpd-2.4.32]# ./configure --prefix=/usr/local/apache2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to "  -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure: 
configure: Configuring Apache Portable Runtime Utility library...
configure: 
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/usr/local/src/httpd-2.4.32':
configure: error: C compiler cannot create executables
See `config.log' for more details
[root@localhost httpd-2.4.32]# echo $?
77

当我们运行configure的时候,可能有一些依赖没有安装,这时候我们要使用yum一个一个安装依赖包。

对于这个例子,我们可以看到gcc是没有被安装的。

    Server Version: 2.4.32
    Install prefix: /usr/local/apache2
    C compiler:     gcc -std=gnu99
    CFLAGS:           -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E

[root@localhost httpd-2.4.32]# echo $?
0

最后,如果echo $?返回0,说明我们这一步成功了。

接下来,按照文档make && make install 如果不报错就安装完成了。

[root@localhost httpd-2.4.32]# ls /usr/local/apache2/
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

卸载的话直接删除目录即可。

 

转载于:https://my.oschina.net/u/3866688/blog/1836073

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值