20180619 Linux 软件包安装和卸载 7.1 - 7.9

20180619 Linux 软件包安装和卸载 7.1 - 7.9
7.1 安装软件包的三种方法 
7.2 rpm 包介绍
7.3 rpm 工具用法
7.4 yum 工具用噶
7.5 yum 搭建本地仓库 
7.6 yum 更换国内源
7.7 yum 下载 rpm 包 
7.8/7.9 源码包安装

7.1 安装软件包的三种方法

Windows 下 exe 软件包(二进制)安装只需要连续的下一步就可以了

rmp 工具
yum 工具
源码包
  1. rpm [redhat package manager]工具和 windows 下的 exe 一样, 不需要做太多的设置, 安装路径和文件名都是固定好的,

  2. yum 工具 自动安装依赖的包, yum是最简单的

  3. 源码包 需要编译器将源码包编译成可执行的文件, 比如拿到 ls 的包可以直接编译成 ls 命令, 源码包是最难的.

  4. 三种方法难易度排名: yum 工具 < rpm 工具 < 源码包

7.2 rpm 包介绍
  1. 挂载光驱

1.1 在 vm 虚拟机右下角的圆形图标, 右击并选择连接 1.2 挂载光驱

[root@arron-01 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G  1.6G   27G    6% /
devtmpfs        481M     0  481M    0% /dev
tmpfs           492M     0  492M    0% /dev/shm
tmpfs           492M  7.5M  485M    2% /run
tmpfs           492M     0  492M    0% /sys/fs/cgroup
/dev/sda1       197M  102M   96M   52% /boot
tmpfs            99M     0   99M    0% /run/user/0
[root@arron-01 ~]# blkid
/dev/sda1: UUID="9e9d939b-7b13-4c26-b956-d2e2ef0d0dc2" TYPE="xfs" 
/dev/sda2: UUID="a9df1da7-288d-46b3-8614-a4327f358c31" TYPE="swap" 
/dev/sda3: UUID="9efe0c94-2bab-4cf7-a5c8-9f94c1fb417b" TYPE="xfs" 
/dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/sdb: PTTYPE="gpt" 
[root@arron-01 ~]# !ls
ls /mnt 

## 挂载
[root@arron-01 ~]# mount /dev/cdrom /mnt;df -h
mount: /dev/sr0 写保护,将以只读方式挂载
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G  1.6G   27G    6% /
devtmpfs        481M     0  481M    0% /dev
tmpfs           492M     0  492M    0% /dev/shm
tmpfs           492M  7.5M  485M    2% /run
tmpfs           492M     0  492M    0% /sys/fs/cgroup
/dev/sda1       197M  102M   96M   52% /boot
tmpfs            99M     0   99M    0% /run/user/0
/dev/sr0        4.2G  4.2G     0  100% /mnt  

## 到挂载点下查看挂载的目录 
[root@arron-01 ~]# cd /mnt ;ls .
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

## 平时用到的包就在 packages/ 下 , 都是 rpm 包 
[root@arron-01 mnt]# cd Packages/;less .
总用量 3782287
drwxrwxr-x. 2 root root   655360 5月   4 04:52 ./
drwxr-xr-x. 8 root root     2048 5月   4 04:54 ../
-rw-rw-r--. 1 root root  1794136 4月  25 18:52 389-ds-base-1.3.7.5-18.el7.x86_64.rpm
-rw-rw-r--. 1 root root   711232 4月  25 18:52 389-ds-base-libs-1.3.7.5-18.el7.x86_64.rpm
-rw-rw-r--. 1 root root   152952 8月  10 2017 abattis-cantarell-fonts-0.0.25-1.el7.noarch.rpm
-rw-rw-r--. 1 root root   548960 5月   1 00:17 abrt-2.1.11-50.el7.centos.x86_64.rpm
.........

  1. rpm 的构成
alsa-plugins-pulseaudio-1.1.1-1.el7.x86_64.rpm

 alsa-plugins-pulseaudio 表示包名
 
 1.1.1-1                 表示版本号, 第一个 1 表示主版本号, 不同的主版本号的包变化很大, 第二个 1 表示 次版本号, 最后一个 1 是小版本号
 
 1.el7 表示发布版本号 

 x86_64 平台位数, 这个表示 64 位, i686 是 32 位, noarch 不区分位数, CentOS 7 不区分 32 位和 64 位了, c6,c5,c4 都区分 32 位 

 rpm  后缀名
7.3 rpm 工具用法
设置光驱并挂载
 rpm包格式,包名、版本号、发布版本号、平台
 rpm -ivh rpm包文件 //安装
 rpm -Uvh rpm包文件  //升级
 rpm -e  包名 //卸载
 rpm -qa //查询安装的包
 rpm -q 包名 //查询指定包是否安装
 rpm -qi 包名 //查询指定包信息
 rpm -ql 包名 //列出包安装的文件
 rpm -qf 文件绝对路径  //查看一个文件是由哪个包安装的

  1. 安装 rpm 包
## 可以写绝对路径也可以写相对路径(不需要加 ./), 
[root@arron-01 Packages]# rpm -ivh ./zsh-5.0.2-28.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...
   1:zsh-5.0.2-28.el7                 ################################# [100%] 

## 升级 rpm 包, 很少用 Uvh
[root@arron-01 Packages]# rpm -ivh zsh-5.0.2-28.el7.x86_64.rpm
  1. 卸载包 rpm -e package name
[root@arron-01 Packages]# rpm -e zsh
  1. rpm -qa 查询安装的包
[root@arron-01 Packages]# rpm -qa 
tuned-2.9.0-1.el7.noarch
grub2-common-2.02-0.65.el7.centos.2.noarch
man-db-2.6.3-9.el7.x86_64
ncurses-base-5.9-14.20130511.el7_4.noarch
.....

## rpm -q 查看某个包是否安装
[root@arron-01 Packages]# rpm -qa|grep zsh
### 它会有显示 
[root@arron-01 Packages]# rpm -q zsh
未安装软件包 zsh

  1. rpm -qi package name 查询包信息
[root@arron-01 Packages]# rpm -qi vim-enhanced
Name        : vim-enhanced
Epoch       : 2
Version     : 7.4.160
Release     : 4.el7
Architecture: x86_64
Install Date: 2018年06月15日 星期五 16时51分26秒
Group       : Applications/Editors
Size        : 2296714
License     : Vim
Signature   : RSA/SHA256, 2018年04月25日 星期三 19时50分34秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : vim-7.4.160-4.el7.src.rpm
Build Date  : 2018年04月11日 星期三 07时55分09秒
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.vim.org/
Summary     : A version of the VIM editor which includes recent enhancements
Description :
VIM (VIsual editor iMproved) is an updated and improved version of the
vi editor.  Vi was the first real screen-based editor for UNIX, and is
still very popular.  VIM improves on vi by adding new features:
multiple windows, multi-level undo, block highlighting and more.  The
vim-enhanced package contains a version of VIM with extra, recently
introduced features like Python and Perl interpreters.

Install the vim-enhanced package if you'd like to use a version of the
VIM editor which includes recently added enhancements like
interpreters for the Python and Perl scripting languages.  You'll also
need to install the vim-common package. 

  1. rpm -ql 列出包安装的文件
[root@arron-01 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
  1. rpm -qf fully path command 查看一个文件是由哪个包安装的
[root@arron-01 Packages]# rpm -qf /usr/bin/cd
bash-4.2.46-30.el7.x86_64

## which command 与 绝对路径文件是一样的效果 
[root@arron-01 Packages]# rpm -qf `which cd`
bash-4.2.46-30.el7.x86_64
7.4 yum 工具用法

yum 工具

yum list  //列出可用rpm包
 ls /etc/yum.repos.d/
 yum search vim  //搜索包
 yum install [-y]
 yum grouplist
 yum groupinstall  [-y]
 yum remove [-y] 
 yum update [-y]
 yum provides “/*/vim”

  1. rpm 工具安装时需要将依赖的包一个个都安装好, 而 yum 可以一次性将依赖的包安装好
[root@arron-01 Packages]# rpm -ivh texlive-2012-38.20130427_r30134.el7.x86_64.rpm
错误:依赖检测失败:
	texlive-scheme-basic 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
	texlive-collection-latexrecommended 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
	tex-kpathsea 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要
	tex-tetex 被 texlive-2:2012-38.20130427_r30134.el7.x86_64 需要 

  1. yum 工具安装 rpm 包
[root@arron-01 Packages]# yum install -y texlive-2012-38.20130427_r30134.el7.x86_64.rpm
cairo.x86_64 0:1.14.8-2.el7                                                                                 
  fontconfig.x86_64 0:2.10.95-11.el7                                                                          
  fontpackages-filesystem.noarch 0:1.44-8.el7                                                                 
  jbigkit-libs.x86_64 0:2.0-11.el7                                                                            
  lcms2.x86_64 0:2.6-3.el7                                                                                    
  libICE.x86_64 0:1.0.9-9.el7                                 
......
  1. yum list 列出可用 rpm 包
[root@arron-01 Packages]# yum list
uwsgi-plugin-ring.x86_64                                    2.0.16-1.el7                             epel     
uwsgi-plugin-rpc.x86_64                                     2.0.16-1.el7                             epel     
uwsgi-plugin-rrdtool.x86_64                                 2.0.16-1.el7                             epel     
uwsgi-plugin-ruby.x86_64                                    2.0.16-1.el7                             epel     
uwsgi-plugin-spooler.x86_64                                 2.0.16-1.el7                             epel                                         

  1. rpm 包的仓库
[root@arron-01 Packages]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel-testing.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo 

## 查看 yum 的内容, 仓库地址如下:  mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra 

[root@arron-01 Packages]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel-testing.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo
[root@arron-01 Packages]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  1. yum search command 搜索包
[root@arron-01 Packages]# yum search vim
......
apvlv.x86_64 : PDF viewer which behaves like Vim
......

## 精准安装 yum list |grep 'vim'
[root@arron-01 Packages]# yum list |grep 'vim'
  1. yum grouplist 列出套件
[root@arron-01 Packages]# yum grouplist 
已加载插件:fastestmirror
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * epel: mirrors.tongji.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: mirrors.nju.edu.cn
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
   Cinnamon 桌面环境
   MATE 桌面环境
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
可用组:
   Fedora Packager
   Haskell
   Milkymist
   TurboGears 应用程序构架
   Xfce
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   教育软件
   智能卡支持
   电子实验室
   科学记数法支持
   系统管理
   系统管理工具
   通用桌面
完成
  1. yum groupinstall 安装套件 , 如果安装的套件名有多个单词, 要加 单引号 ' , 如果只有一个单词, 就不用加单引号了
[root@arron-01 Packages]# yum groupinstall 'Virtualization Host'
  1. yum remove 卸载包
[root@arron-01 Packages]# yum remove network

  1. yum update 升级包或系统, 如果 yum update 后边什么也不加 , 会升级系统所有的包甚至会升级系统至最新 ( 6.1 升级到 6.9 ), 如果系统安装了环境, 就不要随意去升级; 同时内核也有可能会被升级

  2. yum provides "/*/command" 通过命令(前提是系统没有这个文件)搜索包 , 两个 / 中间是路径

7.5 yum 搭建本地仓库
 挂载镜像到/mnt目录
 cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
 rm -f /etc/yum.repos.d/*
 vim /etc/yum.repos.d/dvd.repo //内容如下
[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpgcheck=0
 yum clean all
 yum list 

  1. 搭建本地仓库的必要性: 有时候 yum 不能用是因为没有联网 , 因为默认的 yum 是需要远程连接资源的; 搭建本地仓库实现不能联网一样能用资源(prm)

  2. 搭建仓库的构成: 必须要有镜像文件

  3. 搭建操作如下:

3.1 备份 yum 源

[root@arron-01 Packages]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak;cd /etc/yum.repos.d/;ls . ; 

CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel-testing.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo

## 删除源文件并查看
[root@arron-01 yum.repos.d]# rm -rf ./*;ls .

## 查看备份的文件
[root@arron-01 yum.repos.d]# ls -l ../*
../yum.repos.d.bak:
总用量 40
-rw-r--r--. 1 root root 1664 6月  21 11:17 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 6月  21 11:17 CentOS-CR.repo
-rw-r--r--. 1 root root  649 6月  21 11:17 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 6月  21 11:17 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 6月  21 11:17 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 6月  21 11:17 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 6月  21 11:17 CentOS-Vault.repo
-rw-r--r--. 1 root root  951 6月  21 11:17 epel.repo
-rw-r--r--. 1 root root 1050 6月  21 11:17 epel-testing.repo

3.2 创建 dvd.repo 文件, 模仿的是 /etc/yum.repos.d/CentOS-Base.repo 里边写的

[root@arron-01 yum.repos.d]# vim dvd.repo 

[dvd]
name=install dvd
baseurl=file:///mnt
enable=1
gpgcheck=0 

- - - - - - - - - - - - - - - - - -
[dvd] 表示 包右侧的名字
name 说明信息, 没什么用
baseurl 表示 rpm 包在 /mnt 下
enable 表示是否可用 , 1表示可用
gpgcheck 是否检测, 0 表示不检测 , 因为是本地的
  1. 清除缓存 , yum clean all
[root@arron-01 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: 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@arron-01 yum.repos.d]# yum list
NetworkManager.x86_64                   1:1.10.2-13.el7                @anaconda

可安装的软件包 
389-ds-base.x86_64                      1.3.7.5-18.el7                 dvd
.......

## 试安装一个包, 可以看到同时也安装了很多依赖的包
[root@arron-01 yum.repos.d]# yum install -y gconf-editor 

已安装:
  gconf-editor.x86_64 0:3.0.1-8.el7_1                                                                         

作为依赖被安装:
  GConf2.x86_64 0:3.2.6-8.el7                             adwaita-cursor-theme.noarch 0:3.26.0-1.el7          
  adwaita-icon-theme.noarch 0:3.26.0-1.el7                at-spi2-atk.x86_64 0:2.22.0-2.el7 
 .......

7.6 yum 更换国内源
cd /etc/yum.repos.d/

 rm -f dvd.repo

 wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
 或者
 curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo

 yum list
  1. 自带的 yum 源是国外的网站, 从国内下载国外的资源时会很慢, 所以弄一个国内的 yum 源很有必要

  2. 删除 yum源的配置文件


## 复制 yum 源文件
[root@arron-01 yum.repos.d]# cp ../yum.repos.d.bak/* . ;ls . ;mv CentOS-Base.repo CentOS-Base.repo.bak;rm -f CentOS-Base.repo;ls .
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  dvd.repo           epel-testing.repo

CentOS-Base.repo.bak  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel.repo
CentOS-CR.repo        CentOS-fasttrack.repo  CentOS-Sources.repo  dvd.repo           epel-testing.repo

  1. 下载 163 的 yum 源 curl -O / wget url 都可以
## CentOS7-Base-163.repo 正是我们想要的 yum 源 
[root@arron-01 yum.repos.d]# ls
CentOS7-Base-163.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  epel.repo
CentOS-Base.repo.bak   CentOS-fasttrack.repo  CentOS-Vault.repo    epel-testing.repo
CentOS-CR.repo         CentOS-Media.repo      dvd.repo
[root@arron-01 yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1572  100  1572    0     0   6143      0 --:--:-- --:--:-- --:--:--  6188 

## 查看 yum 源 的配置文件
[root@arron-01 yum.repos.d]# vim CentOS7-Base-163.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
[base]
# CentOS-Base.repo
.......
[root@arron-01 yum.repos.d]# yum list 
.......
znc-devel.x86_64                                            1.7.0-3.el7                              epel 
.......
[root@arron-01 yum.repos.d]# rm -f dvd.repo

## 安装一个包, 发觉安装成功
[root@arron-01 yum.repos.d]# rpm -q znc
未安装软件包 znc 
[root@arron-01 yum.repos.d]# yum install znc
.....
已安装:
  znc.x86_64 0:1.7.0-3.el7                                                                                    

完毕!

## 如果将 yum 源更名再看一下会不会识别 
[root@arron-01 yum.repos.d]# mv CentOS7-Base-163.repo CentOS7-Base-163.repo.123;ls .
CentOS7-Base-163.repo.123  CentOS-Debuginfo.repo  CentOS-Sources.repo  epel.repo
CentOS-Base.repo.bak       CentOS-fasttrack.repo  CentOS-Vault.repo    epel-testing.repo
CentOS-CR.repo             CentOS-Media.repo      dvd.repo

## 清除缓存
[root@arron-01 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: dvd epel
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@arron-01 ~]# yum list
已加载插件:fastestmirror
Determining fastest mirrors


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again

## 如上一直没有实现视频中的效果, 经与视频中 /et/yum.repos.d/ 下的文件比较, 发觉多了 epel.repo 和  epel-testing.repo , 现将 epel.repo 和  epel-testing.repo 更名, 发觉达到的视频中的效果
[root@localhost yum.repos.d]# mv epel.repo epel.repo.bak
[root@localhost yum.repos.d]# mv epel-testing.repo epel-testing.repo.bak 
[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo> 

## 通过 yum repolist all 查看还有哪些仓库可用 
[root@localhost yum.repos.d]# yum repolist all
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
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 
......

## 无论装哪个包, 都不可以
[root@localhost yum.repos.d]# yum install zziplib
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo>

[root@localhost yum.repos.d]# yum install znc
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable <repo>
 To enable custom repositories:
     yum-config-manager --enable <repo> 

## 所以只能将 yum 源的名称改回来
[root@localhost yum.repos.d]# mv CentOS7-Base-163.repo.bak CentOS7-Base-163.repo 

[root@localhost yum.repos.d]# mv CentOS7-Base-163.repo.bak CentOS7-Base-163.repo;ls . ; yum repolist all
CentOS-Base.repo.bak   CentOS-Media.repo    CentOS-fasttrack.repo  epel.repo.bak
CentOS-CR.repo         CentOS-Sources.repo  CentOS7-Base-163.repo
CentOS-Debuginfo.repo  CentOS-Vault.repo    epel-testing.repo.bak
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

163 源反馈结果如下

mark

继续操作

[root@localhost yum.repos.d]# yum clean all
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
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 install zziplib

Installed:
  zziplib.x86_64 0:0.13.62-5.el7                                                                              

Complete! 
7.7 yum 下载 rpm 包

安装扩展源, 有时候文件在一个 yum 源找不到, 需要去扩展源里去找, epel, 实际上就是安装了一个文件 / etc/yum.repos.d/epel.repo

yum install -y epel-release

 yum list |grep epel 

## yum下载rpm包
yum install -y 包名 --downloadonly   ## 实际上就是一个插件

 ls /var/cache/yum/x86_64/7/    

 yum install -y 包名 --downloadonly --downloaddir=路径

 yum reinstall -y 包名 --downloadonly --downloaddir=路径
  1. 安装 epel-release, 会生成两个文件, epel-testing.repo 和 epel.repo , 实际上 epel.repo 才重要
[root@localhost yum.repos.d]# yum install -y epel-release 

## 其实 epel.repo 是从 fedora (Redhat 的 release version) 下载的 http://download.fedoraproject.org
[root@localhost yum.repos.d]# vim epel.repo

## 装后会显示很多包, 但是在一般的源里头没有
[root@localhost yum.repos.d]# yum list |grep epel
tesseract-langpack-rus.noarch             3.04.00-3.el7                epel     
tesseract-langpack-san.noarch             3.04.00-3.el7                epel     
tesseract-langpack-sin.noarch             3.04.00-3.el7                epel     
tesseract-langpack-slk.noarch             3.04.00-3.el7                epel     
tesseract-langpack-slk_frak.noarch        3.04.00-3.el7                epel     
tesseract-langpack-slv.noarch             3.04.00-3.el7                epel     
tesseract-langpack-spa.noarch             3.04.00-3.el7                epel     
tesseract-langpack-spa_old.noarch         3.04.00-3.el7                epel
.......
  1. yum install package --downloadonly , 仅仅下载一个包而不去安装, 实际上是仅仅安装了一个插件
## 他们仅仅安装了一个插件, 所以如下显示未安装
[root@localhost yum.repos.d]# yum install znc --downloadonly
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirror.premi.st
 * extras: mirrors.163.com
 * updates: ftp.sjtu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package znc.x86_64 0:1.7.0-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================
 Package               Arch                     Version                          Repository              Size
==============================================================================================================
Installing:
 znc                   x86_64                   1.7.0-3.el7                      epel                   2.0 M

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

Total download size: 2.0 M
Installed size: 6.8 M
Background downloading packages, then exiting:
znc-1.7.0-3.el7.x86_64.rpm                                                             | 2.0 MB  00:00:02     
exiting because "Download Only" specified
[root@localhost yum.repos.d]# rpm -q znc
package znc is not installed

## 根据如上显示, 在路径 /var/cache/yum/x86_64/7/ 下, 然后结合下载时显示的 Repository (如上所示) 找到安装包 
[root@localhost yum.repos.d]# ls /var/cache/yum/x86_64/7/epel/packages/
znc-1.7.0-3.el7.x86_64.rpm

  1. yum install package --downloadonly --downloaddir 指定路径安装
## 因为这个包已经安装了, 所以在 /tmp/ 下没有显示, 碰到这种情况, 可以先卸载再去安装, 但是服务在用这个包时就不合适了, 可以采用 reinstall 
[root@localhost yum.repos.d]# yum install vim-enhanced --downloadonly --downloaddir=/tmp/
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirror.premi.st
 * extras: mirrors.163.com
 * updates: ftp.sjtu.edu.cn
Package 2:vim-enhanced-7.4.160-4.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost yum.repos.d]# ls /tmp/
ks-script-GS2P4L
systemd-private-0614ec7b993a487f9cf6c14fb444fd7f-chronyd.service-FER4JA
vmware-root
yum.log
yum_save_tx.2018-06-22.10-26.OPwmio.yumtx

## yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/

[root@localhost yum.repos.d]# yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * epel: mirror.premi.st
 * extras: mirrors.163.com
 * updates: ftp.sjtu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.160-4.el7 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================
 Package                     Arch                  Version                          Repository           Size
==============================================================================================================
Reinstalling:
 vim-enhanced                x86_64                2:7.4.160-4.el7                  base                1.0 M

Transaction Summary
==============================================================================================================
Reinstall  1 Package

Total download size: 1.0 M
Installed size: 2.2 M
Background downloading packages, then exiting:
vim-enhanced-7.4.160-4.el7.x86_64.rpm                                                  | 1.0 MB  00:00:01     
exiting because "Download Only" specified

## 可以看到 /tmp/ 下有 vim-enhanced 这个包了 
[root@localhost yum.repos.d]# ls /tmp/
ks-script-GS2P4L
systemd-private-0614ec7b993a487f9cf6c14fb444fd7f-chronyd.service-FER4JA
vim-enhanced-7.4.160-4.el7.x86_64.rpm
vmware-root
yum.log
yum_save_tx.2018-06-22.10-26.OPwmio.yumtx
yum_save_tx.2018-06-22.10-43._n1f0D.yumtx
7.8/7.9 源码包安装
cd /usr/local/src/
 wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.32.tar.gz
 tar zxvf httpd-2.2.32.tar.gz
 cd httpd-2.2.32
 ./configure --prefix=/usr/local/apache2
 make
 make install
 卸载就是删除安装的文件 
  1. 像 LAMP 和 LNMP 采用的编译安装, 就是源码包安装, 以后源码包就放在 /usr/local/src/ 路径下
## 可以看到下载成功了
[root@localhost yum.repos.d]# cd /usr/local/src/; curl -O http://mirrors.sohu.com/apache/httpd-2.4.29.tar.gz; ls . 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8436k  100 8436k    0     0   614k      0  0:00:13  0:00:13 --:--:--  579k
httpd-2.4.29.tar.gz

## 解压后查看说明文档 README 或者 INSTALL 
[root@localhost src]# tar xzf httpd-2.4.29.tar.gz;  ls . ;  cd httpd-2.4.29/ ;   ls . 
httpd-2.4.29  httpd-2.4.29.tar.gz
ABOUT_APACHE     INSTALL         NWGNUmakefile     ap.d             docs         libhttpd.dep  support
Apache-apr2.dsw  InstallBin.dsp  README            apache_probes.d  emacs-style  libhttpd.dsp  test
Apache.dsw       LAYOUT          README.cmake      build            httpd.dep    libhttpd.mak
BuildAll.dsp     LICENSE         README.platforms  buildconf        httpd.dsp    modules
BuildBin.dsp     Makefile.in     ROADMAP           config.layout    httpd.mak    os
CHANGES          Makefile.win    VERSIONING        configure        httpd.spec   server
CMakeLists.txt   NOTICE          acinclude.m4      configure.in     include      srclib 

## more README 
[root@localhost httpd-2.4.29]# more README

                          Apache HTTP Server

  What is it?
  -----------

  The Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant
  web server.  Originally designed as a replacement for the NCSA HTTP
  Server, it has grown to be the most popular web server on the
  Internet.  As a project of the Apache Software Foundation, the
  developers aim to collaboratively develop and maintain a robust,
  commercial-grade, standards-based server with freely available
  source code.

  The Latest Version
  ------------------

  Details of the latest version can be found on the Apache HTTP
  server project page under http://httpd.apache.org/.

  Documentation
  -------------

...skipping one line
  The documentation available as of the date of this release is
  included in HTML format in the docs/manual/ directory.  The most
  up-to-date documentation can be found at
  http://httpd.apache.org/docs/2.4/.

  Installation
  ------------

  Please see the file called INSTALL.  Platform specific notes can be
  found in README.platforms.

  Licensing
  ---------

  Please see the file called LICENSE.


## more INSTALL 
[root@localhost httpd-2.4.29]# more INSTALL

  APACHE INSTALLATION OVERVIEW

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

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

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


## 源码包安装时可以通过 ./configure --help 查看安装时的参数 
[root@localhost httpd-2.4.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]
.......
## 加上一些参数, 减去一些参数
--enable-dav-lock       DAV provider for generic locking
  --enable-vhost-alias    mass virtual hosting module
  --enable-negotiation    content negotiation
  --disable-dir           directory request handling
  --enable-imagemap       server-side imagemaps
  --enable-actions        Action triggering on requests
  --enable-speling        correct common URL misspellings
  --enable-userdir        mapping of requests to user-specific directories
  --disable-alias         mapping of requests to different filesystem parts
  --enable-rewrite        rule based URL manipulation
  --enable-v4-mapped      Allow IPv6 sockets to handle IPv4 connections
  .......

## 初始化, 发觉不行, 可以在执行后的下一步(不要选在下下步) echo $? 来查看初始化以及 make & make install 是否 ok , echo $? 返回的是 0 就表示 OK, 如果 非 0 就表示 失败
[root@localhost httpd-2.4.29]# ./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... no
configure: error: APR not found.  Please read the documentation.

[root@localhost httpd-2.4.29]# echo $?
1
## 如下显示的是上一步操作 OK , 不是上上步
[root@localhost httpd-2.4.29]# echo $?
0

## 安装需要的包, apr 是 Configuring Apache Portable Runtime library 需要的, 而 gcc 是编译安装必须的一个工具 
[root@localhost httpd-2.4.29]# yum install -y apr; yum install -y gcc 

## 再次初始化也不行
[root@localhost httpd-2.4.29]# ./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... no
configure: error: APR not found.  Please read the documentation.

## 但是不行, 需要这样操作, 参考网址: https://blog.csdn.net/superbirds/article/details/52373102 
### 操作如下

1.2 下载两个包 ( apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植)

[root@localhost httpd-2.4.29]# wget http://mirrors.hust.edu.cn/apache//apr/apr-1.6.3.tar.gz;wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.6.1.tar.gz

[root@localhost httpd-2.4.29]# mv apr-1.6.3.tar.gz ../ ; mv apr-util-1.6.1.tar.gz ../ ; ls ../
apr-1.6.3.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.29  httpd-2.4.29.tar.gz 

1.3 解压并安装他们
[root@localhost httpd-2.4.29]# cd ../ ; tar zxf apr-1.6.3.tar.gz ; tar zxf apr-util-1.6.1.tar.gz ; ls 
apr-1.6.3  apr-1.6.3.tar.gz  apr-util-1.6.1  apr-util-1.6.1.tar.gz  httpd-2.4.29  httpd-2.4.29.tar.gz

### 初始化 apr-1.6.3 
[root@localhost apr-1.6.3]# cd apr-1.6.3; ./configure --prefix=/usr/local/apr

### 出现了如下的错误, 网上的解决方案: https://blog.csdn.net/u013281361/article/details/51896740 

config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands 

"解决如上错误的方案"

30375     RM='$RM'

### 查找包, 这个包没有安装成功, 不过这个包不装也没有关系
[root@localhost apr-1.6.3]# yum provides "/*/libtool"
libtool-2.4.2-22.el7_3.x86_64 : The GNU Portable Library Tool
Repo        : base
Matched from:
Filename    : /usr/bin/libtool
Filename    : /usr/share/libtool 

### 重新初始化 apr
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.6.3]# echo $?
0

1.4 编译, 安装 apr
[root@localhost apr-1.6.3]# make && make install
[root@localhost apr-1.6.3]# echo $?
0 

1.5 初始化 apr-util
[root@localhost apr-1.6.3]# cd ../apr-util-1.6.1/ ; ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.6.1]# echo $?
0 
[root@localhost apr-util-1.6.1]# make && make install 

### 出现如下错误, expat.h: No such file or directory 
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
 #include <expat.h>
                   ^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/src/apr-util-1.6.1'
make: *** [all-recursive] Error 1

[root@localhost apr-util-1.6.1]# yum provides "/*/expat.h" 
......
expat-devel-2.1.0-10.el7_3.x86_64 : Libraries and header files to develop applications using expat
Repo        : base
Matched from:
Filename    : /usr/include/expat.h
......

## 安装包 expat-devel 
[root@localhost apr-util-1.6.1]# yum install -y expat-devel

## 继续编译安装 apr-util
[root@localhost apr-util-1.6.1]# make && make install 

[root@localhost apr-util-1.6.1]# echo $?
0 

1.6 安装 httpd 
[root@localhost src]# cd httpd-2.4.29/ ; ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --w
ith-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most 

.......

## 如下的错误要去安装包 
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

[root@localhost httpd-2.4.29]# echo $?
1

## 查找 文件 pcre-config 的包 
pcre-devel-8.32-17.el7.x86_64 : Development files for pcre
Repo        : base
Matched from:
Filename    : /usr/bin/pcre-config

[root@localhost httpd-2.4.29]# yum install -y pcre-devel

## 继续初始化 httpd 
[root@localhost httpd-2.4.29]# cd httpd-2.4.29/ ; ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most 

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

## 编辑安装 httpd 
[root@localhost httpd-2.4.29]# make && make install 
......
make[1]: Leaving directory `/usr/local/src/httpd-2.4.29' 

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

### 在编译时出现问题要解决这些问题, 查看日志文件, 写的参数, 在网上查找等等

### 查看生成的文件 
[root@localhost src]# ls /usr/local/apache2/
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules 

## 卸载就是在没有做其他操作前删除安装的目录就可以了, 

且安装时要从可靠的站点去下载

转载于:https://my.oschina.net/u/3869385/blog/1834016

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值