7.6 yum更换国内源
7.7 yum下载rpm包
7.8/7.9 源码包安装
扩展
1. 配置yum源优先级 http://ask.apelearn.com/question/7168
2. 把源码包打包成rpm包 http://www.linuxidc.com/Linux/2012-09/70096.htm
# 7.6 yum更换国内源

- 有时候自带的yum 仓库 yum源 不太好使,本身自带的yum里的网址资源,是国外的,从国内下国外的rpm包肯定会很慢,所以搞一个国内的yum源
```
[root@aminglinux-01 yum.repos.d]# ls
dvd.repo
[root@aminglinux-01 yum.repos.d]# rm -f dvd.repo 首先把之前备份的文件给恢复,dvd.repo 就不要了,删了
[root@aminglinux-01 yum.repos.d]# cp ../yum.repos.d.bak/* .
cp: 略过目录"../yum.repos.d.bak/yum.repos.d"
[root@aminglinux-01 yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@aminglinux-01 yum.repos.d]#
```
1. 再把 CentOS-Base.repo 最核心最基本的那个源 删掉不要这个,改一个,改成国内的163的源
```
[root@aminglinux-01 yum.repos.d]# rm -f CentOS-Base.repo
使用命令wget 去下载
[root@aminglinux-01 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
-bash: wget: 未找到命令
```
2.wget命令没有本来可以用yum 安装,但是刚刚我们把 CentOS-Base.repo 删掉了,所以用下面这个命令
curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
```
[root@aminglinux-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 9623 0 --:--:-- --:--:-- --:--:-- 9703
[root@aminglinux-01 yum.repos.d]# ls
CentOS7-Base-163.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@aminglinux-01 yum.repos.d]# vim CentOS7-Base-163.repo
```
3. 打开这个看下
```
[root@aminglinux-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]
name=CentOS-$releasever - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
"CentOS7-Base-163.repo" 41L, 1572C 1,1 顶端
```
4.使用yum list 看下
```
[root@aminglinux-01 yum.repos.d]# yum list
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
zsh-html.x86_64 5.0.2-25.el7_3.1 updates
zziplib.i686 0.13.62-5.el7 base
zziplib.x86_64 0.13.62-5.el7 base
zziplib-devel.i686 0.13.62-5.el7 base
zziplib-devel.x86_64 0.13.62-5.el7 base
zziplib-utils.x86_64 0.13.62-5.el7 base
[root@aminglinux-01 yum.repos.d]#
[root@aminglinux-01 yum.repos.d]# yum install zlib
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
Loading mirror speeds from cached hostfile
软件包 zlib-1.2.7-17.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@aminglinux-01 yum.repos.d]#
```
5.已经安装过了,试下别的包
```
[root@aminglinux-01 yum.repos.d]# yum install zsh
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-25.el7_3.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================================
Package 架构 版本 源 大小
===========================================================================================
正在安装:
zsh x86_64 5.0.2-25.el7_3.1 updates 2.4 M
事务概要
===========================================================================================
安装 1 软件包
总下载量:2.4 M
安装大小:5.6 M
Is this ok [y/d/N]: n
Exiting on user command
您的事务已保存,请执行:
yum load-transaction /tmp/yum_save_tx.2017-08-12.16-23.AT17pc.yumtx 重新执行该事务
[root@aminglinux-01 yum.repos.d]#
```
6.那这个到底是不是163的源,可以先改名看下,再yum clean all 清除所有缓存
```
[root@aminglinux-01 yum.repos.d]# mv CentOS7-Base-163.repo CentOS7-Base-163.repo.123
[root@aminglinux-01 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>
[root@aminglinux-01 yum.repos.d]#
[root@aminglinux-01 yum.repos.d]# yum repolist all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base 禁用
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus 禁用
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras 禁用
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus 禁用
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates 禁用
C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base 禁用
C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus 禁用
C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras 禁用
C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus 禁用
C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates 禁用
C7.2.1511-base/x86_64 CentOS-7.2.1511 - Base 禁用
C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus 禁用
C7.2.1511-extras/x86_64 CentOS-7.2.1511 - Extras 禁用
C7.2.1511-fasttrack/x86_64 CentOS-7.2.1511 - CentOSPlus 禁用
C7.2.1511-updates/x86_64 CentOS-7.2.1511 - Updates 禁用
base-debuginfo/x86_64 CentOS-7 - Debuginfo 禁用
base-source/7 CentOS-7 - Base Sources 禁用
c7-media CentOS-7 - Media 禁用
centosplus-source/7 CentOS-7 - Plus Sources 禁用
cr/7/x86_64 CentOS-7 - cr 禁用
extras-source/7 CentOS-7 - Extras Sources 禁用
fasttrack/7/x86_64 CentOS-7 - fasttrack 禁用
updates-source/7 CentOS-7 - Updates Sources 禁用
repolist: 0
[root@aminglinux-01 yum.repos.d]#
```
7.都是禁用的,再把名字改回来
```
[root@aminglinux-01 yum.repos.d]# ls
CentOS7-Base-163.repo.123 CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@aminglinux-01 yum.repos.d]# mv CentOS7-Base-163.repo.123 CentOS7-Base-163.repo
[root@aminglinux-01 yum.repos.d]# yum repolist all
[root@aminglinux-01 yum.repos.d]# yum repolist all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base 禁用
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus 禁用
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras 禁用
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus 禁用
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates 禁用
C7.1.1503-base/x86_64 CentOS-7.1.1503 - Base 禁用
C7.1.1503-centosplus/x86_64 CentOS-7.1.1503 - CentOSPlus 禁用
C7.1.1503-extras/x86_64 CentOS-7.1.1503 - Extras 禁用
C7.1.1503-fasttrack/x86_64 CentOS-7.1.1503 - CentOSPlus 禁用
C7.1.1503-updates/x86_64 CentOS-7.1.1503 - Updates 禁用
C7.2.1511-base/x86_64 CentOS-7.2.1511 - Base 禁用
C7.2.1511-centosplus/x86_64 CentOS-7.2.1511 - CentOSPlus 禁用
C7.2.1511-extras/x86_64 CentOS-7.2.1511 - Extras 禁用
C7.2.1511-fasttrack/x86_64 CentOS-7.2.1511 - CentOSPlus 禁用
C7.2.1511-updates/x86_64 CentOS-7.2.1511 - Updates 禁用
base/7/x86_64 CentOS-7 - Base - 163.com 启用: 9,363
base-debuginfo/x86_64 CentOS-7 - Debuginfo 禁用
base-source/7 CentOS-7 - Base Sources 禁用
c7-media CentOS-7 - Media 禁用
centosplus/7/x86_64 CentOS-7 - Plus - 163.com 禁用
centosplus-source/7 CentOS-7 - Plus Sources 禁用
cr/7/x86_64 CentOS-7 - cr 禁用
extras/7/x86_64 CentOS-7 - Extras - 163.com 启用: 449
extras-source/7 CentOS-7 - Extras Sources 禁用
fasttrack/7/x86_64 CentOS-7 - fasttrack 禁用
updates/7/x86_64 CentOS-7 - Updates - 163.com 启用: 2,146
updates-source/7 CentOS-7 - Updates Sources 禁用
repolist: 11,958
[root@aminglinux-01 yum.repos.d]#
```
8。再清除缓存,重新安装一些zsh包
```
[root@aminglinux-01 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@aminglinux-01 yum.repos.d]# yum install zsh
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 155 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 191 kB 00:00:00
(3/4): base/7/x86_64/primary_db | 5.6 MB 00:00:03
(4/4): updates/7/x86_64/primary_db | 7.8 MB 00:00:03
Determining fastest mirrors
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-25.el7_3.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================================
Package 架构 版本 源 大小
===========================================================================================
正在安装:
zsh x86_64 5.0.2-25.el7_3.1 updates 2.4 M
事务概要
===========================================================================================
安装 1 软件包
总下载量:2.4 M
安装大小:5.6 M
Is this ok [y/d/N]:
您的事务已保存,请执行:
yum load-transaction /tmp/yum_save_tx.2017-08-12.16-30.hWaWgQ.yumtx 重新执行该事务
[root@aminglinux-01 yum.repos.d]#
```
9.这时候就可以安装wget wget 就是下载这个文件 CentOS7-Base-163.repo
```
[root@aminglinux-01 yum.repos.d]# yum install -y wget
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 wget.x86_64.0.1.14-13.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================================
Package 架构 版本 源 大小
===========================================================================================
正在安装:
wget x86_64 1.14-13.el7 base 546 k
事务概要
===========================================================================================
安装 1 软件包
总下载量:546 k
安装大小:2.0 M
Downloading packages:
wget-1.14-13.el7.x86_64.rpm | 546 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : wget-1.14-13.el7.x86_64 1/1
验证中 : wget-1.14-13.el7.x86_64 1/1
已安装:
wget.x86_64 0:1.14-13.el7
完毕!
[root@aminglinux-01 yum.repos.d]#
```
## 7.7 安装一个扩展源epel

- 使用命令yum install -y epel-release
```
[root@aminglinux-01 yum.repos.d]# ls
CentOS7-Base-163.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@aminglinux-01 yum.repos.d]# yum install -y epel-release
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 epel-release.noarch.0.7-9 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================================
Package 架构 版本 源 大小
===========================================================================================
正在安装:
epel-release noarch 7-9 extras 14 k
事务概要
===========================================================================================
安装 1 软件包
总下载量:14 k
安装大小:24 k
Downloading packages:
epel-release-7-9.noarch.rpm | 14 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : epel-release-7-9.noarch 1/1
验证中 : epel-release-7-9.noarch 1/1
已安装:
epel-release.noarch 0:7-9
完毕!
[root@aminglinux-01 yum.repos.d]#
[root@aminglinux-01 yum.repos.d]# ls 这里多了俩个包 epel.repo epel-testing.repo
CentOS7-Base-163.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo epel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo epel-testing.repo
[root@aminglinux-01 yum.repos.d]#
```
- 再cat一下这个文件看下
```
[root@aminglinux-01 yum.repos.d]# cat epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[root@aminglinux-01 yum.repos.d]#
```
- 使用yum list 查看一下,这样看不太清楚,现在用一个命令yum list |grep epel
```
[root@aminglinux-01 yum.repos.d]# yum list |grep epel
zlib-ada-devel.x86_64 1.4-0.5.20120830CVS.el7 epel
zmap.x86_64 2.1.1-1.el7 epel
znc.x86_64 1.6.5-1.el7 epel
znc-devel.x86_64 1.6.5-1.el7 epel
znc-modperl.x86_64 1.6.5-1.el7 epel
znc-modpython.x86_64 1.6.5-1.el7 epel
znc-modtcl.x86_64 1.6.5-1.el7 epel
zopfli.x86_64 1.0.1-1.el7 epel
zsh-lovers.noarch 0.9.0-1.el7 epel
zstd.x86_64 1.3.0-1.el7 epel
zulucrypt.x86_64 5.0.1-1.el7 epel
zulucrypt-console.x86_64 5.0.1-1.el7 epel
zulucrypt-devel.x86_64 5.0.1-1.el7 epel
zulucrypt-doc.noarch 5.0.1-1.el7 epel
zulucrypt-libs.x86_64 5.0.1-1.el7 epel
zvbi.x86_64 0.2.35-1.el7 epel
zvbi-devel.x86_64 0.2.35-1.el7 epel
zvbi-fonts.noarch 0.2.35-1.el7 epel
[root@aminglinux-01 yum.repos.d]#
```
- 这个epel 非常有用,后续使用会多次用到这个
# yum 下载rpm 包

- 网上的rpm 包有很多,虽然可以 在 光驱光盘里找到一些rpm ,像一些 epel光驱没有,但是想要,可以下到本地来,可以把这些包保存下来,可以让其他机器去用,省的再yum安装下半天,它实际上是yum的一个插件
- 这种做法,你需要先确认下,你现在的rpm包是否已经安装过了
```
[root@aminglinux-01 yum.repos.d]# yum install zsh --downloadonly downloadonly 仅仅下载不安装
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirror.premi.st
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-25.el7_3.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================================
Package 架构 版本 源 大小
=======================================================================================================
正在安装:
zsh x86_64 5.0.2-25.el7_3.1 updates 2.4 M
事务概要
=======================================================================================================
安装 1 软件包
总下载量:2.4 M
安装大小:5.6 M
Background downloading packages, then exiting:
zsh-5.0.2-25.el7_3.1.x86_64.rpm | 2.4 MB 00:00:01
exiting because "Download Only" specified
[root@aminglinux-01 yum.repos.d]#
[root@aminglinux-01 yum.repos.d]# rpm -q zsh
未安装软件包 zsh
[root@aminglinux-01 yum.repos.d]#
```
- 并没有安装,仅仅是下载,因为加了--downloadonly ,那下载到哪里去了?
```
[root@aminglinux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/base
bd50ff3d861cc21d254a390a963e9f0fd7b7b96ed9d31ece2f2b1997aa3a056f-primary.sqlite.bz2 gen
c55e5b7bbe933fa8dac2cffca4596c265812b74ed12ef3968d487dd6eb22ad93-c7-x86_64-comps.xml.gz packages
cachecookie repomd.xml
[root@aminglinux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/base/packages/
[root@aminglinux-01 yum.repos.d]# ls /var/cache/yum/x86_64/7/updates/packages/
zsh-5.0.2-25.el7_3.1.x86_64.rpm
[root@aminglinux-01 yum.repos.d]#
```
- 指定它下载的路径 指定到/tmp/下
```
[root@aminglinux-01 yum.repos.d]# yum install zsh --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirror.premi.st
正在解决依赖关系
--> 正在检查事务
---> 软件包 zsh.x86_64.0.5.0.2-25.el7_3.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
==========================================================================
Package 架构 版本 源 大小
==========================================================================
正在安装:
zsh x86_64 5.0.2-25.el7_3.1 updates 2.4 M
事务概要
==========================================================================
安装 1 软件包
总下载量:2.4 M
安装大小:5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified
[root@aminglinux-01 yum.repos.d]#
[root@aminglinux-01 yum.repos.d]# ls /tmp/
1.txt
1.txt.bz2
1.txt.gz
2.txt.xz
aminglinux
d6z
fstab
ls2
passwd.sh
systemd-private-e031fa9e20494934b9848b750907442a-vmtoolsd.service-RI8yhR
xxx.conf
yum_save_tx.2017-08-11.23-52.oRt6jf.yumtx
yum_save_tx.2017-08-12.00-28.o4N6Ss.yumtx
yum_save_tx.2017-08-12.00-31.QLxOxc.yumtx
yum_save_tx.2017-08-12.16-23.AT17pc.yumtx
yum_save_tx.2017-08-12.16-30.hWaWgQ.yumtx
yum_save_tx.2017-08-12.17-40.W2Mqi8.yumtx
yum_save_tx.2017-08-12.17-54.DgNopW.yumtx
zsh-5.0.2-25.el7_3.1.x86_64.rpm
[root@aminglinux-01 yum.repos.d]#
```
- 再来弄一个vim 的
```
[root@aminglinux-01 yum.repos.d]# yum install vim-enhanced --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.neusoft.edu.cn
软件包 2:vim-enhanced-7.4.160-1.el7_3.1.x86_64 已安装并且是最新版本
无须任何处理
[root@aminglinux-01 yum.repos.d]#
```
- 发现已经存在了,那可以使用命令reinstall 重新安装
```
[root@aminglinux-01 yum.repos.d]# yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 vim-enhanced.x86_64.2.7.4.160-1.el7_3.1 将被 已重新安装
--> 解决依赖关系完成
依赖关系解决
==========================================================================
Package 架构 版本 源 大小
==========================================================================
重新安装:
vim-enhanced x86_64 2:7.4.160-1.el7_3.1 updates 1.0 M
事务概要
==========================================================================
重新安装 1 软件包
总下载量:1.0 M
安装大小:2.2 M
Background downloading packages, then exiting:
vim-enhanced-7.4.160-1.el7_3.1.x86_64.rpm | 1.0 MB 00:00
exiting because "Download Only" specified
[root@aminglinux-01 yum.repos.d]# ls /tmp/
1.txt
1.txt.bz2
1.txt.gz
2.txt.xz
aminglinux
d6z
fstab
ls2
passwd.sh
systemd-private-e031fa9e20494934b9848b750907442a-vmtoolsd.service-RI8yhR
vim-enhanced-7.4.160-1.el7_3.1.x86_64.rpm
xxx.conf
yum_save_tx.2017-08-11.23-52.oRt6jf.yumtx
yum_save_tx.2017-08-12.00-28.o4N6Ss.yumtx
yum_save_tx.2017-08-12.00-31.QLxOxc.yumtx
yum_save_tx.2017-08-12.16-23.AT17pc.yumtx
yum_save_tx.2017-08-12.16-30.hWaWgQ.yumtx
yum_save_tx.2017-08-12.17-40.W2Mqi8.yumtx
yum_save_tx.2017-08-12.17-54.DgNopW.yumtx
yum_save_tx.2017-08-12.17-58.d_63wU.yumtx
zsh-5.0.2-25.el7_3.1.x86_64.rpm
[root@aminglinux-01 yum.repos.d]#
```
# 7.8 源码包安装 上

- 为了形成统一规范,方便找、管理 ,以后所有源码包都放在/usr/local/src/目录下
```
[root@aminglinux-01 etc]# cd
[root@aminglinux-01 ~]# cd /etc/
[root@aminglinux-01 etc]# cd yum.repos.d
[root@aminglinux-01 yum.repos.d]# ls
CentOS7-Base-163.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo epel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo epel-testing.repo
[root@aminglinux-01 yum.repos.d]# cd
[root@aminglinux-01 ~]# cd /usr/local/src/
[root@aminglinux-01 src]# ls
[root@aminglinux-01 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
--2017-08-12 20:23:09-- http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
正在解析主机 mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.6.177, 2402:f000:1:416:101:6:6:177
正在连接 mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.6.177|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:8603417 (8.2M) [application/octet-stream]
正在保存至: “httpd-2.4.27.tar.gz.1”
100%[=================================================>] 8,603,417 1.27MB/s 用时 6.3s
2017-08-12 20:23:15 (1.31 MB/s) - 已保存 “httpd-2.4.27.tar.gz.1” [8603417/8603417])
[root@aminglinux-01 src]# ls
httpd-2.4.27.tar.gz httpd-2.4.27.tar.gz.1
[root@aminglinux-01 src]#
解压.gz的包
[root@aminglinux-01 src]# tar -zxvf httpd-2.4.27.tar.gz
...
httpd-2.4.27/test/Makefile.in
httpd-2.4.27/test/README
httpd-2.4.27/test/tcpdumpscii.txt
httpd-2.4.27/test/test-writev.c
httpd-2.4.27/test/test_find.c
httpd-2.4.27/test/test_limits.c
httpd-2.4.27/test/test_parser.c
httpd-2.4.27/test/test_select.c
httpd-2.4.27/test/time-sem.c
httpd-2.4.27/VERSIONING
[root@aminglinux-01 src]#
解压后,进入这个目录下去
[root@aminglinux-01 src]# cd httpd-2.4.27
[root@aminglinux-01 httpd-2.4.27]# ls
ABOUT_APACHE buildconf httpd.dsp libhttpd.mak README.cmake
acinclude.m4 CHANGES httpd.mak LICENSE README.platforms
Apache-apr2.dsw CMakeLists.txt httpd.spec Makefile.in ROADMAP
Apache.dsw config.layout include Makefile.win server
apache_probes.d configure INSTALL modules srclib
ap.d configure.in InstallBin.dsp NOTICE support
build docs LAYOUT NWGNUmakefile test
BuildAll.dsp emacs-style libhttpd.dep os VERSIONING
BuildBin.dsp httpd.dep libhttpd.dsp README
[root@aminglinux-01 httpd-2.4.27]#
用more 查看安装文档
[root@aminglinux-01 httpd-2.4.27]# 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
NOTES: * Replace PREFIX with the filesystem path under which
Apache should be installed. A typical installation
might use "/usr/local/apache2" for PREFIX (without the
quotes).
* Consider if you want to use a previously installed APR and
APR-Util (such as those provided with many OSes) or if you
need to use the APR and APR-Util from the apr.apache.org
project. If the latter, download the latest versions and
unpack them to ./srclib/apr and ./srclib/apr-util (no
version numbers in the directory names) and use
```
1. ./configure --prefix=PREFIX
```
[root@aminglinux-01 httpd-2.4.27]# ./configure --prefix=/usr/local/apache2
[root@aminglinux-01 httpd-2.4.27]# ./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@aminglinux-01 httpd-2.4.27]# echo $?
1
[root@aminglinux-01 httpd-2.4.27]#
```
- 如果想检查上条命令是否正常,可以运行命令 echo $? 结果如果是非0 就是不正常,如果是0就是正常 上面出现这个报错:checking for APR... no 那几用yum 安装下APR
```
[root@aminglinux-01 httpd-2.4.27]# yum install -y APR
[root@aminglinux-01 httpd-2.4.27]# yum install -y APR
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: ftp.riken.jp
没有可用软件包 APR。
* 也许您想要:apr
错误:无须任何处理
[root@aminglinux-01 httpd-2.4.27]# yum install -y apr
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 apr.x86_64.0.1.4.8-3.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================================
Package 架构 版本 源 大小
===========================================================================================
正在安装:
apr x86_64 1.4.8-3.el7 base 103 k
事务概要
===========================================================================================
安装 1 软件包
总下载量:103 k
安装大小:221 k
Downloading packages:
apr-1.4.8-3.el7.x86_64.rpm | 103 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : apr-1.4.8-3.el7.x86_64 1/1
验证中 : apr-1.4.8-3.el7.x86_64 1/1
已安装:
apr.x86_64 0:1.4.8-3.el7
完毕!
[root@aminglinux-01 httpd-2.4.27]#
```
- 报错说 也许要安装apr 那就yum重新安装一次,
-
```
[root@aminglinux-01 src]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
--2017-08-12 21:32:07-- http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
正在解析主机 mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.6.178, 2402:f000:1:416:101:6:6:178
正在连接 mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.6.178|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:8603417 (8.2M) [application/octet-stream]
正在保存至: “httpd-2.4.27.tar.gz.2”
100%[=================================================>] 8,603,417 532KB/s 用时 16s
2017-08-12 21:32:23 (531 KB/s) - 已保存 “httpd-2.4.27.tar.gz.2” [8603417/8603417])
[root@aminglinux-01 src]#
```
- 再运行一次./configure --prefix=/usr/local/apache2命令
```
[root@aminglinux-01 httpd-2.4.27]# ./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.
```
- 还是报错,说缺少APR
使用 yum list |grep -i apr 把前面yum列表里的内容 过滤 有apr 字符的 包
```
[root@aminglinux-01 httpd-2.4.27]# yum list |grep -i apr
apr.x86_64 1.4.8-3.el7 @base
apr.i686 1.4.8-3.el7 base
apr-devel.i686 1.4.8-3.el7 base
apr-devel.x86_64 1.4.8-3.el7 base
apr-util.i686 1.5.2-6.el7 base
apr-util.x86_64 1.5.2-6.el7 base
apr-util-devel.i686 1.5.2-6.el7 base
apr-util-devel.x86_64 1.5.2-6.el7 base
apr-util-ldap.x86_64 1.5.2-6.el7 base
apr-util-mysql.x86_64 1.5.2-6.el7 base
apr-util-nss.x86_64 1.5.2-6.el7 base
apr-util-odbc.x86_64 1.5.2-6.el7 base
apr-util-openssl.x86_64 1.5.2-6.el7 base
apr-util-pgsql.x86_64 1.5.2-6.el7 base
apr-util-sqlite.x86_64 1.5.2-6.el7 base
haproxy.x86_64 1.5.18-3.el7_3.1 updates
libapreq2.x86_64 2.13-11.el7.1 epel
libapreq2-devel.x86_64 2.13-11.el7.1 epel
libchromaprint.x86_64 1.0-1.el7 epel
libchromaprint-devel.x86_64 1.0-1.el7 epel
perl-libapreq2.x86_64 2.13-11.el7.1 epel
php-whitehat101-apr1-md5.noarch 1.0.0-1.el7 epel
snapraid.x86_64 10.0-1.el7 epel
```
- 安装下文件 apr-devel.x86_64 库文件
- 安装完 apr-devel.x86_64 文件后,再继续运行./configure --prefix=/usr/local/apache2,还是报错
```
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[root@aminglinux-01 httpd-2.4.27]# echo $?
1
```
- echo $? 检查上一步操作是否正常,如果是非0 就是错误,0就是正常,上面显示缺少pcre 库文件,继续使用命令yum list|grep -i pcre
```
[root@aminglinux-01 httpd-2.4.27]# yum list |grep -i pcre
pcre.x86_64 8.32-15.el7_2.1 @anaconda
ghc-pcre-light.x86_64 0.4-13.el7 epel
ghc-pcre-light-devel.x86_64 0.4-13.el7 epel
mingw32-pcre.noarch 8.38-1.el7 epel
mingw32-pcre-static.noarch 8.38-1.el7 epel
mingw64-pcre.noarch 8.38-1.el7 epel
mingw64-pcre-static.noarch 8.38-1.el7 epel
pcre.i686 8.32-15.el7_2.1 base
pcre-devel.i686 8.32-15.el7_2.1 base
pcre-devel.x86_64 8.32-15.el7_2.1 base
pcre-static.i686 8.32-15.el7_2.1 base
pcre-static.x86_64 8.32-15.el7_2.1 base
pcre-tools.x86_64 8.32-15.el7_2.1 base
```
- 再次安装 库文件pcre-devel.x86_64 使用命令yum install -y pcre-devel.x86_64
```
总下载量:479 k
安装大小:1.4 M
Downloading packages:
pcre-devel-8.32-15.el7_2.1.x86_64.rpm | 479 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : pcre-devel-8.32-15.el7_2.1.x86_64 1/1
验证中 : pcre-devel-8.32-15.el7_2.1.x86_64 1/1
已安装:
pcre-devel.x86_64 0:8.32-15.el7_2.1
```
- 再次运行./configure --prefix=/usr/local/apache2 初始化配置
```
完毕!
[root@aminglinux-01 httpd-2.4.27]# ./configure --prefix=/usr/local/apache2
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:
Server Version: 2.4.27
Install prefix: /usr/local/apache2
C compiler: gcc -std=gnu99
CFLAGS: -pthread
LDFLAGS:
LIBS:
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
C preprocessor: gcc -E
[root@aminglinux-01 httpd-2.4.27]# echo $?
0
[root@aminglinux-01 httpd-2.4.27]#
```
- 第二步 make
```
[root@aminglinux-01 httpd-2.4.27]# make
```
# 7.9 源码包安装下

```
avoid-version mod_rewrite.lo
make[4]: 离开目录“/usr/local/src/httpd-2.4.27/modules/mappers”
make[3]: 离开目录“/usr/local/src/httpd-2.4.27/modules/mappers”
make[2]: 离开目录“/usr/local/src/httpd-2.4.27/modules”
make[2]: 进入目录“/usr/local/src/httpd-2.4.27/support”
make[2]: 离开目录“/usr/local/src/httpd-2.4.27/support”
make[1]: 离开目录“/usr/local/src/httpd-2.4.27”
[root@aminglinux-01 httpd-2.4.27]#
[root@aminglinux-01 httpd-2.4.27]# echo $?
0
[root@aminglinux-01 httpd-2.4.27]#
```
- 第三步 make install
```
[root@aminglinux-01 httpd-2.4.27]# make install
Installing man pages and online manual
mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1
mkdir /usr/local/apache2/man/man8
mkdir /usr/local/apache2/manual
make[1]: 离开目录“/usr/local/src/httpd-2.4.27”
[root@aminglinux-01 httpd-2.4.27]# echo $?
0
```
- 打开就可以看到 生成了这么多目录,这就是源码编译安装的包
```
[root@aminglinux-01 httpd-2.4.27]# ls /usr/local/apache2
bin build cgi-bin conf error htdocs icons include logs man manual modules
[root@aminglinux-01 httpd-2.4.27]#
```
- 源码包一定要去官方下载,或者是可信任的站点 这样比较安全,不要随便自己去去,随便下会容易出现木马,这样事情很可怕。
## 扩展
- [ ] 1. 配置yum源优先级 http://ask.apelearn.com/question/7168
yum更新源优先级设置
1.安装 yum-priorities
yum install yum-priorities
2.priorities的配置文件是/etc/yum/pluginconf.d/priorities.conf,确认其是否存在。
其内容为:
[main]
enabled=1 # 0禁用 1启用
3.编辑 /etc/yum.repos.d/目录下的*.repo 文件来设置优先级。
参数为:
priority=N # N的值为1-99
推荐的设置为:
[base], [addons], [updates], [extras] … priority=1
[centosplus],[contrib] … priority=2
Third Party Repos such as rpmforge … priority=N (where N is > 10 and based on your preference)
数字越大,优先级越低
- [ ] 2. 把源码包打包成rpm包 http://www.linuxidc.com/Linux/2012-09/70096.htm
有好多朋友问到怎么制作rpm包,可不可把其它服务器上编译好的软件目录复杂到其它服务器上直接应用等等。。。这里做个简单的介绍,高级复杂的不会。
此方法是通过编写spec文件,使用rpmbuild来完成一个rpm的打包。
以nginx为例进行介绍
制作平台:CentOS 5.x X86_64
四步走:
第一步:建立目录结构
mkdir /usr/src/RedHat/{SOURCES,SPECS,BUILD,RPMS,SRPMS} -p
相关目录介绍:
/usr/src/redhat/SOURCES #存放源代码、补丁等文件
/usr/src/redhat/SPECS #存放用于管理rpm制作进程的spec文件
/usr/src/redhat/BUILD #解压后的文件存放目录
/usr/src/redhat/RPMS #存放由rpmbuild制作好的二进制包
/usr/src/redhat/SRPMS #存放由rpmbuild制作好的源码包
第二步:把源码包放在SOURCES目录下
cd /usr/src/redhat/SOURCES
wget http://nginx.org/download/nginx-1.2.0.tar.gz
第三步:生成nginx.spec文件
```
cd /usr/src/redhat/SPECS
cat nginx.spec
#
# spec file for nginx
# Build 2012-07-17
# By opsren
#
Summary: High performance web server
Name: Nginx
Version: 1.2
Release: 0.el5.ngx
License: 2-clause BSD-like license
Group: Applications/Server
Source: http://nginx.org/download/nginx-1.2.0.tar.gz
URL: http://nginx.org
Distribution: Centos/Redhat
Packager: qiuzhijun <250621008@qq.com>
%description
Nginx ("engine x") is a high performance HTTP and reverse proxy server, as well as a mail(IMAP/POP3/SMTP) proxy server.
%prep
tar zxf $RPM_SOURCE_DIR/nginx-1.2.0.tar.gz
%build
cd nginx-1.2.0
./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid
make
%install
cd nginx-1.2.0
make install
%preun
if [ -z "`ps aux | grep nginx | grep -v grep`" ];then
pkill nginx >/dev/null
exit 0
fi
%files
/usr/local/webserver/nginx
```
第四步:RPM包制作
首先系统要安装好必备的制作工具:gcc、rpmbuild等
yum -y install gcc rpm-build pcre-devel
cd /usr/src/redhat/SPECS/
rpmbuild -bb nginx.spec
通过上面这条命令,会在/usr/src/redhat/RPMS/x86_64/下面生成nginx-1.2.0-1.el5.ngx.x86_64.rpm这个文件
-bb 这个选项就是制作二进制包(build binary package only from <specfile>)
对spec文件内容进行简单说明:
spec文件是制作rpm包的核心!
以#开头的是注释信息;
Summary:对相关软件进行简单描述说明
Name:定义rpm包的名称
Version:定义软件的版本号
Release:发行版本
License:定义许可证
Group:说明软件属于哪种应用类型
Source:软件源码下载地址
URL:软件相关官方站点
Distribution: 发行版系列
Packager: 制作人的简单信息
%description:软件详细描述信息
%prep:软件编译之前的处理
%build:编译软件
%install:安装软件
%preun:定义卸载之前的动作
%files:指定要打包的软件包,这里是/usr/local/webserver/nginx
对于更详细的说明请参考官方资料:http://www.rpm.org/max-rpm/ch-rpm-inside.html
下面是apache的spec文件实例:
```
#
# spec file for apache
# Build 2012-07-17
# By opsren
#
Summary: High stability web server
Name: Apache
Version: 2.2
Release: 22.el5
License: 2-clause BSD-like license
Group: Applications/Server
Source: http://apache.etoak.com/httpd/httpd-2.2.22.tar.gz
URL: http://apache.org
Distribution: Centos/Redhat
Packager: qiuzhijun <250621008@qq.com>
%description
Apache is a first web server
%prep
tar zxf $RPM_SOURCE_DIR/httpd-2.2.22.tar.gz
%build
cd httpd-2.2.22
./configure --prefix=/usr/local/webserver/apache --enable-so --enable-deflate --enable-headers --enable-mods-shared=all --enable-rewrite
make
%install
cd httpd-2.2.22
make install
%preun
if [ -z "`ps aux | grep httpd | grep -v grep`" ];then
pkill httpd >/dev/null
exit 0
fi
%files
/usr/local/webserver/apache
```
以后对于相同或类似平台可以到其它服务器上进行rpm安装部署。
另外还有一种rpm打包的方法:rpm_create
这是一种新的打rpm的工具,不用spec语言,只需要会简单的shell命令,即可完成打包操作,非常方便,结合了spec语言和checkinstall,相比spec方法要简单很多!
官方站点:http://code.google.com/p/rpmcreate/
下载站点:wget http://rpmcreate.googlecode.com/files/rpm_create-1.7.5-9.x86_64.rpm
大家可以去官方站点参考!7.6 yum更换国内源 7.7 yum下载rpm包 7.8/7.9 源码包安装
原文:http://ch71smas.blog.51cto.com/13090095/1960923