7.6yum更换国内源
7.7yum下载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.6yum更换国内源
![mark](http://oqxf7c508.bkt.clouddn.com/blog/20170812/154757717.png?imageslim)
-有时候自带的yum仓库yum源不太好使,本身自带的yum里的网址资源,是国外的,从国内下国外的rpm包肯定会很慢,所以搞一个国内的yum源
```
[root@aminglinux-01yum.repos.d]#ls
dvd.repo
[root@aminglinux-01yum.repos.d]#rm-fdvd.repo首先把之前备份的文件给恢复,dvd.repo就不要了,删了
[root@aminglinux-01yum.repos.d]#cp../yum.repos.d.bak/*.
cp:略过目录"../yum.repos.d.bak/yum.repos.d"
[root@aminglinux-01yum.repos.d]#ls
CentOS-Base.repoCentOS-Debuginfo.repoCentOS-Media.repoCentOS-Vault.repo
CentOS-CR.repoCentOS-fasttrack.repoCentOS-Sources.repo
[root@aminglinux-01yum.repos.d]#
```
1.再把CentOS-Base.repo最核心最基本的那个源删掉不要这个,改一个,改成国内的163的源
```
[root@aminglinux-01yum.repos.d]#rm-fCentOS-Base.repo
使用命令wget去下载
[root@aminglinux-01yum.repos.d]#wgethttp://mirrors.163.com/.help/CentOS7-Base-163.repo
-bash:wget:未找到命令
```
2.wget命令没有本来可以用yum安装,但是刚刚我们把CentOS-Base.repo删掉了,所以用下面这个命令
curl-Ohttp://mirrors.163.com/.help/CentOS7-Base-163.repo
```
[root@aminglinux-01yum.repos.d]#curl-Ohttp://mirrors.163.com/.help/CentOS7-Base-163.repo
%Total%Received%XferdAverageSpeedTimeTimeTimeCurrent
DloadUploadTotalSpentLeftSpeed
100157210015720096230--:--:----:--:----:--:--9703
[root@aminglinux-01yum.repos.d]#ls
CentOS7-Base-163.repoCentOS-Debuginfo.repoCentOS-Media.repoCentOS-Vault.repo
CentOS-CR.repoCentOS-fasttrack.repoCentOS-Sources.repo
[root@aminglinux-01yum.repos.d]#vimCentOS7-Base-163.repo
```
3.打开这个看下
```
[root@aminglinux-01yum.repos.d]#vimCentOS7-Base-163.repo
#CentOS-Base.repo
#
#ThemirrorsystemusestheconnectingIPaddressoftheclientandthe
#updatestatusofeachmirrortopickmirrorsthatareupdatedtoand
#geographicallyclosetotheclient.YoushouldusethisforCentOSupdates
#unlessyouaremanuallypickingothermirrors.
#
#Ifthemirrorlist=doesnotworkforyou,asafallbackyoucantrythe
#remarkedoutbaseurl=lineinstead.
#
#
[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
#releasedupdates
[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
#additionalpackagesthatmaybeuseful
[extras]
"CentOS7-Base-163.repo"41L,1572C1,1顶端
```
4.使用yumlist看下
```
[root@aminglinux-01yum.repos.d]#yumlist
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
zsh-html.x86_645.0.2-25.el7_3.1updates
zziplib.i6860.13.62-5.el7base
zziplib.x86_640.13.62-5.el7base
zziplib-devel.i6860.13.62-5.el7base
zziplib-devel.x86_640.13.62-5.el7base
zziplib-utils.x86_640.13.62-5.el7base
[root@aminglinux-01yum.repos.d]#
[root@aminglinux-01yum.repos.d]#yuminstallzlib
已加载插件:fastestmirror
base|3.6kB00:00:00
extras|3.4kB00:00:00
updates|3.4kB00:00:00
Loadingmirrorspeedsfromcachedhostfile
软件包zlib-1.2.7-17.el7.x86_64已安装并且是最新版本
无须任何处理
[root@aminglinux-01yum.repos.d]#
```
5.已经安装过了,试下别的包
```
[root@aminglinux-01yum.repos.d]#yuminstallzsh
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
正在解决依赖关系
-->正在检查事务
--->软件包zsh.x86_64.0.5.0.2-25.el7_3.1将被安装
-->解决依赖关系完成
依赖关系解决
===========================================================================================
Package架构版本源大小
===========================================================================================
正在安装:
zshx86_645.0.2-25.el7_3.1updates2.4M
事务概要
===========================================================================================
安装1软件包
总下载量:2.4M
安装大小:5.6M
Isthisok[y/d/N]:n
Exitingonusercommand
您的事务已保存,请执行:
yumload-transaction/tmp/yum_save_tx.2017-08-12.16-23.AT17pc.yumtx重新执行该事务
[root@aminglinux-01yum.repos.d]#
```
6.那这个到底是不是163的源,可以先改名看下,再yumcleanall清除所有缓存
```
[root@aminglinux-01yum.repos.d]#mvCentOS7-Base-163.repoCentOS7-Base-163.repo.123
[root@aminglinux-01yum.repos.d]#yumcleanall
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
Therearenoenabledrepos.
Run"yumrepolistall"toseethereposyouhave.
ToenableRedHatSubscriptionManagementrepositories:
subscription-managerrepos--enable<repo>
Toenablecustomrepositories:
yum-config-manager--enable<repo>
[root@aminglinux-01yum.repos.d]#
[root@aminglinux-01yum.repos.d]#yumrepolistall
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
源标识源名称状态
C7.0.1406-base/x86_64CentOS-7.0.1406-Base禁用
C7.0.1406-centosplus/x86_64CentOS-7.0.1406-CentOSPlus禁用
C7.0.1406-extras/x86_64CentOS-7.0.1406-Extras禁用
C7.0.1406-fasttrack/x86_64CentOS-7.0.1406-CentOSPlus禁用
C7.0.1406-updates/x86_64CentOS-7.0.1406-Updates禁用
C7.1.1503-base/x86_64CentOS-7.1.1503-Base禁用
C7.1.1503-centosplus/x86_64CentOS-7.1.1503-CentOSPlus禁用
C7.1.1503-extras/x86_64CentOS-7.1.1503-Extras禁用
C7.1.1503-fasttrack/x86_64CentOS-7.1.1503-CentOSPlus禁用
C7.1.1503-updates/x86_64CentOS-7.1.1503-Updates禁用
C7.2.1511-base/x86_64CentOS-7.2.1511-Base禁用
C7.2.1511-centosplus/x86_64CentOS-7.2.1511-CentOSPlus禁用
C7.2.1511-extras/x86_64CentOS-7.2.1511-Extras禁用
C7.2.1511-fasttrack/x86_64CentOS-7.2.1511-CentOSPlus禁用
C7.2.1511-updates/x86_64CentOS-7.2.1511-Updates禁用
base-debuginfo/x86_64CentOS-7-Debuginfo禁用
base-source/7CentOS-7-BaseSources禁用
c7-mediaCentOS-7-Media禁用
centosplus-source/7CentOS-7-PlusSources禁用
cr/7/x86_64CentOS-7-cr禁用
extras-source/7CentOS-7-ExtrasSources禁用
fasttrack/7/x86_64CentOS-7-fasttrack禁用
updates-source/7CentOS-7-UpdatesSources禁用
repolist:0
[root@aminglinux-01yum.repos.d]#
```
7.都是禁用的,再把名字改回来
```
[root@aminglinux-01yum.repos.d]#ls
CentOS7-Base-163.repo.123CentOS-Debuginfo.repoCentOS-Media.repoCentOS-Vault.repo
CentOS-CR.repoCentOS-fasttrack.repoCentOS-Sources.repo
[root@aminglinux-01yum.repos.d]#mvCentOS7-Base-163.repo.123CentOS7-Base-163.repo
[root@aminglinux-01yum.repos.d]#yumrepolistall
[root@aminglinux-01yum.repos.d]#yumrepolistall
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
源标识源名称状态
C7.0.1406-base/x86_64CentOS-7.0.1406-Base禁用
C7.0.1406-centosplus/x86_64CentOS-7.0.1406-CentOSPlus禁用
C7.0.1406-extras/x86_64CentOS-7.0.1406-Extras禁用
C7.0.1406-fasttrack/x86_64CentOS-7.0.1406-CentOSPlus禁用
C7.0.1406-updates/x86_64CentOS-7.0.1406-Updates禁用
C7.1.1503-base/x86_64CentOS-7.1.1503-Base禁用
C7.1.1503-centosplus/x86_64CentOS-7.1.1503-CentOSPlus禁用
C7.1.1503-extras/x86_64CentOS-7.1.1503-Extras禁用
C7.1.1503-fasttrack/x86_64CentOS-7.1.1503-CentOSPlus禁用
C7.1.1503-updates/x86_64CentOS-7.1.1503-Updates禁用
C7.2.1511-base/x86_64CentOS-7.2.1511-Base禁用
C7.2.1511-centosplus/x86_64CentOS-7.2.1511-CentOSPlus禁用
C7.2.1511-extras/x86_64CentOS-7.2.1511-Extras禁用
C7.2.1511-fasttrack/x86_64CentOS-7.2.1511-CentOSPlus禁用
C7.2.1511-updates/x86_64CentOS-7.2.1511-Updates禁用
base/7/x86_64CentOS-7-Base-163.com启用:9,363
base-debuginfo/x86_64CentOS-7-Debuginfo禁用
base-source/7CentOS-7-BaseSources禁用
c7-mediaCentOS-7-Media禁用
centosplus/7/x86_64CentOS-7-Plus-163.com禁用
centosplus-source/7CentOS-7-PlusSources禁用
cr/7/x86_64CentOS-7-cr禁用
extras/7/x86_64CentOS-7-Extras-163.com启用:449
extras-source/7CentOS-7-ExtrasSources禁用
fasttrack/7/x86_64CentOS-7-fasttrack禁用
updates/7/x86_64CentOS-7-Updates-163.com启用:2,146
updates-source/7CentOS-7-UpdatesSources禁用
repolist:11,958
[root@aminglinux-01yum.repos.d]#
```
8。再清除缓存,重新安装一些zsh包
```
[root@aminglinux-01yum.repos.d]#yumcleanall
已加载插件:fastestmirror
正在清理软件源:baseextrasupdates
Cleaningupeverything
Cleaninguplistoffastestmirrors
[root@aminglinux-01yum.repos.d]#yuminstallzsh
已加载插件:fastestmirror
base|3.6kB00:00:00
extras|3.4kB00:00:00
updates|3.4kB00:00:00
(1/4):base/7/x86_64/group_gz|155kB00:00:00
(2/4):extras/7/x86_64/primary_db|191kB00:00:00
(3/4):base/7/x86_64/primary_db|5.6MB00:00:03
(4/4):updates/7/x86_64/primary_db|7.8MB00:00:03
Determiningfastestmirrors
正在解决依赖关系
-->正在检查事务
--->软件包zsh.x86_64.0.5.0.2-25.el7_3.1将被安装
-->解决依赖关系完成
依赖关系解决
===========================================================================================
Package架构版本源大小
===========================================================================================
正在安装:
zshx86_645.0.2-25.el7_3.1updates2.4M
事务概要
===========================================================================================
安装1软件包
总下载量:2.4M
安装大小:5.6M
Isthisok[y/d/N]:
您的事务已保存,请执行:
yumload-transaction/tmp/yum_save_tx.2017-08-12.16-30.hWaWgQ.yumtx重新执行该事务
[root@aminglinux-01yum.repos.d]#
```
9.这时候就可以安装wgetwget就是下载这个文件CentOS7-Base-163.repo
```
[root@aminglinux-01yum.repos.d]#yuminstall-ywget
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
正在解决依赖关系
-->正在检查事务
--->软件包wget.x86_64.0.1.14-13.el7将被安装
-->解决依赖关系完成
依赖关系解决
===========================================================================================
Package架构版本源大小
===========================================================================================
正在安装:
wgetx86_641.14-13.el7base546k
事务概要
===========================================================================================
安装1软件包
总下载量:546k
安装大小:2.0M
Downloadingpackages:
wget-1.14-13.el7.x86_64.rpm|546kB00:00:00
Runningtransactioncheck
Runningtransactiontest
Transactiontestsucceeded
Runningtransaction
正在安装:wget-1.14-13.el7.x86_641/1
验证中:wget-1.14-13.el7.x86_641/1
已安装:
wget.x86_640:1.14-13.el7
完毕!
[root@aminglinux-01yum.repos.d]#
```
##7.7安装一个扩展源epel
![mark](http://oqxf7c508.bkt.clouddn.com/blog/20170812/171153728.png?imageslim)
-使用命令yuminstall-yepel-release
```
[root@aminglinux-01yum.repos.d]#ls
CentOS7-Base-163.repoCentOS-Debuginfo.repoCentOS-Media.repoCentOS-Vault.repo
CentOS-CR.repoCentOS-fasttrack.repoCentOS-Sources.repo
[root@aminglinux-01yum.repos.d]#yuminstall-yepel-release
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
正在解决依赖关系
-->正在检查事务
--->软件包epel-release.noarch.0.7-9将被安装
-->解决依赖关系完成
依赖关系解决
===========================================================================================
Package架构版本源大小
===========================================================================================
正在安装:
epel-releasenoarch7-9extras14k
事务概要
===========================================================================================
安装1软件包
总下载量:14k
安装大小:24k
Downloadingpackages:
epel-release-7-9.noarch.rpm|14kB00:00:00
Runningtransactioncheck
Runningtransactiontest
Transactiontestsucceeded
Runningtransaction
正在安装:epel-release-7-9.noarch1/1
验证中:epel-release-7-9.noarch1/1
已安装:
epel-release.noarch0:7-9
完毕!
[root@aminglinux-01yum.repos.d]#
[root@aminglinux-01yum.repos.d]#ls这里多了俩个包epel.repoepel-testing.repo
CentOS7-Base-163.repoCentOS-fasttrack.repoCentOS-Vault.repo
CentOS-CR.repoCentOS-Media.repoepel.repo
CentOS-Debuginfo.repoCentOS-Sources.repoepel-testing.repo
[root@aminglinux-01yum.repos.d]#
```
-再cat一下这个文件看下
```
[root@aminglinux-01yum.repos.d]#catepel.repo
[epel]
name=ExtraPackagesforEnterpriseLinux7-$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=ExtraPackagesforEnterpriseLinux7-$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=ExtraPackagesforEnterpriseLinux7-$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-01yum.repos.d]#
```
-使用yumlist查看一下,这样看不太清楚,现在用一个命令yumlist|grepepel
```
[root@aminglinux-01yum.repos.d]#yumlist|grepepel
zlib-ada-devel.x86_641.4-0.5.20120830CVS.el7epel
zmap.x86_642.1.1-1.el7epel
znc.x86_641.6.5-1.el7epel
znc-devel.x86_641.6.5-1.el7epel
znc-modperl.x86_641.6.5-1.el7epel
znc-modpython.x86_641.6.5-1.el7epel
znc-modtcl.x86_641.6.5-1.el7epel
zopfli.x86_641.0.1-1.el7epel
zsh-lovers.noarch0.9.0-1.el7epel
zstd.x86_641.3.0-1.el7epel
zulucrypt.x86_645.0.1-1.el7epel
zulucrypt-console.x86_645.0.1-1.el7epel
zulucrypt-devel.x86_645.0.1-1.el7epel
zulucrypt-doc.noarch5.0.1-1.el7epel
zulucrypt-libs.x86_645.0.1-1.el7epel
zvbi.x86_640.2.35-1.el7epel
zvbi-devel.x86_640.2.35-1.el7epel
zvbi-fonts.noarch0.2.35-1.el7epel
[root@aminglinux-01yum.repos.d]#
```
-这个epel非常有用,后续使用会多次用到这个
#yum下载rpm包
![mark](http://oqxf7c508.bkt.clouddn.com/blog/20170812/173724580.png?imageslim)
-网上的rpm包有很多,虽然可以在光驱光盘里找到一些rpm,像一些epel光驱没有,但是想要,可以下到本地来,可以把这些包保存下来,可以让其他机器去用,省的再yum安装下半天,它实际上是yum的一个插件
-这种做法,你需要先确认下,你现在的rpm包是否已经安装过了
```
[root@aminglinux-01yum.repos.d]#yuminstallzsh--downloadonlydownloadonly仅仅下载不安装
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
*epel:mirror.premi.st
正在解决依赖关系
-->正在检查事务
--->软件包zsh.x86_64.0.5.0.2-25.el7_3.1将被安装
-->解决依赖关系完成
依赖关系解决
=======================================================================================================
Package架构版本源大小
=======================================================================================================
正在安装:
zshx86_645.0.2-25.el7_3.1updates2.4M
事务概要
=======================================================================================================
安装1软件包
总下载量:2.4M
安装大小:5.6M
Backgrounddownloadingpackages,thenexiting:
zsh-5.0.2-25.el7_3.1.x86_64.rpm|2.4MB00:00:01
exitingbecause"DownloadOnly"specified
[root@aminglinux-01yum.repos.d]#
[root@aminglinux-01yum.repos.d]#rpm-qzsh
未安装软件包zsh
[root@aminglinux-01yum.repos.d]#
```
-并没有安装,仅仅是下载,因为加了--downloadonly,那下载到哪里去了?
```
[root@aminglinux-01yum.repos.d]#ls/var/cache/yum/x86_64/7/base
bd50ff3d861cc21d254a390a963e9f0fd7b7b96ed9d31ece2f2b1997aa3a056f-primary.sqlite.bz2gen
c55e5b7bbe933fa8dac2cffca4596c265812b74ed12ef3968d487dd6eb22ad93-c7-x86_64-comps.xml.gzpackages
cachecookierepomd.xml
[root@aminglinux-01yum.repos.d]#ls/var/cache/yum/x86_64/7/base/packages/
[root@aminglinux-01yum.repos.d]#ls/var/cache/yum/x86_64/7/updates/packages/
zsh-5.0.2-25.el7_3.1.x86_64.rpm
[root@aminglinux-01yum.repos.d]#
```
-指定它下载的路径指定到/tmp/下
```
[root@aminglinux-01yum.repos.d]#yuminstallzsh--downloadonly--downloaddir=/tmp/
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
*epel:mirror.premi.st
正在解决依赖关系
-->正在检查事务
--->软件包zsh.x86_64.0.5.0.2-25.el7_3.1将被安装
-->解决依赖关系完成
依赖关系解决
==========================================================================
Package架构版本源大小
==========================================================================
正在安装:
zshx86_645.0.2-25.el7_3.1updates2.4M
事务概要
==========================================================================
安装1软件包
总下载量:2.4M
安装大小:5.6M
Backgrounddownloadingpackages,thenexiting:
exitingbecause"DownloadOnly"specified
[root@aminglinux-01yum.repos.d]#
[root@aminglinux-01yum.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-01yum.repos.d]#
```
-再来弄一个vim的
```
[root@aminglinux-01yum.repos.d]#yuminstallvim-enhanced--downloadonly--downloaddir=/tmp/
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
*epel:mirrors.neusoft.edu.cn
软件包2:vim-enhanced-7.4.160-1.el7_3.1.x86_64已安装并且是最新版本
无须任何处理
[root@aminglinux-01yum.repos.d]#
```
-发现已经存在了,那可以使用命令reinstall重新安装
```
[root@aminglinux-01yum.repos.d]#yumreinstallvim-enhanced--downloadonly--downloaddir=/tmp/
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
*epel:mirrors.ustc.edu.cn
正在解决依赖关系
-->正在检查事务
--->软件包vim-enhanced.x86_64.2.7.4.160-1.el7_3.1将被已重新安装
-->解决依赖关系完成
依赖关系解决
==========================================================================
Package架构版本源大小
==========================================================================
重新安装:
vim-enhancedx86_642:7.4.160-1.el7_3.1updates1.0M
事务概要
==========================================================================
重新安装1软件包
总下载量:1.0M
安装大小:2.2M
Backgrounddownloadingpackages,thenexiting:
vim-enhanced-7.4.160-1.el7_3.1.x86_64.rpm|1.0MB00:00
exitingbecause"DownloadOnly"specified
[root@aminglinux-01yum.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-01yum.repos.d]#
```
#7.8源码包安装上
![mark](http://oqxf7c508.bkt.clouddn.com/blog/20170812/193329488.png?imageslim)
-为了形成统一规范,方便找、管理,以后所有源码包都放在/usr/local/src/目录下
```
[root@aminglinux-01etc]#cd
[root@aminglinux-01~]#cd/etc/
[root@aminglinux-01etc]#cdyum.repos.d
[root@aminglinux-01yum.repos.d]#ls
CentOS7-Base-163.repoCentOS-fasttrack.repoCentOS-Vault.repo
CentOS-CR.repoCentOS-Media.repoepel.repo
CentOS-Debuginfo.repoCentOS-Sources.repoepel-testing.repo
[root@aminglinux-01yum.repos.d]#cd
[root@aminglinux-01~]#cd/usr/local/src/
[root@aminglinux-01src]#ls
[root@aminglinux-01src]#wgethttp://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
--2017-08-1220: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请求,正在等待回应...200OK
长度:8603417(8.2M)[application/octet-stream]
正在保存至:“httpd-2.4.27.tar.gz.1”
100%[=================================================>]8,603,4171.27MB/s用时6.3s
2017-08-1220:23:15(1.31MB/s)-已保存“httpd-2.4.27.tar.gz.1”[8603417/8603417])
[root@aminglinux-01src]#ls
httpd-2.4.27.tar.gzhttpd-2.4.27.tar.gz.1
[root@aminglinux-01src]#
解压.gz的包
[root@aminglinux-01src]#tar-zxvfhttpd-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-01src]#
解压后,进入这个目录下去
[root@aminglinux-01src]#cdhttpd-2.4.27
[root@aminglinux-01httpd-2.4.27]#ls
ABOUT_APACHEbuildconfhttpd.dsplibhttpd.makREADME.cmake
acinclude.m4CHANGEShttpd.makLICENSEREADME.platforms
Apache-apr2.dswCMakeLists.txthttpd.specMakefile.inROADMAP
Apache.dswconfig.layoutincludeMakefile.winserver
apache_probes.dconfigureINSTALLmodulessrclib
ap.dconfigure.inInstallBin.dspNOTICEsupport
builddocsLAYOUTNWGNUmakefiletest
BuildAll.dspemacs-stylelibhttpd.deposVERSIONING
BuildBin.dsphttpd.deplibhttpd.dspREADME
[root@aminglinux-01httpd-2.4.27]#
用more查看安装文档
[root@aminglinux-01httpd-2.4.27]#moreINSTALL
APACHEINSTALLATIONOVERVIEW
QuickStart-Unix
------------------
Forcompleteinstallationdocumentation,see[ht]docs/manual/install.htmlor
http://httpd.apache.org/docs/2.4/install.html
$./configure--prefix=PREFIX
$make
$makeinstall
$PREFIX/bin/apachectlstart
NOTES:*ReplacePREFIXwiththefilesystempathunderwhich
Apacheshouldbeinstalled.Atypicalinstallation
mightuse"/usr/local/apache2"forPREFIX(withoutthe
quotes).
*ConsiderifyouwanttouseaprevIoUslyinstalledAPRand
APR-Util(suchasthoseprovidedwithmanyOSes)orifyou
needtousetheAPRandAPR-Utilfromtheapr.apache.org
project.Ifthelatter,downloadthelatestversionsand
unpackthemto./srclib/aprand./srclib/apr-util(no
versionnumbersinthedirectorynames)anduse
```
1../configure--prefix=PREFIX
```
[root@aminglinux-01httpd-2.4.27]#./configure--prefix=/usr/local/apache2
[root@aminglinux-01httpd-2.4.27]#./configure--prefix=/usr/local/apache2
checkingforchosenlayout...Apache
checkingforworkingmkdir-p...yes
checkingforgrepthathandleslonglinesand-e.../usr/bin/grep
checkingforegrep.../usr/bin/grep-E
checkingbuildsystemtype...x86_64-pc-linux-gnu
checkinghostsystemtype...x86_64-pc-linux-gnu
checkingtargetsystemtype...x86_64-pc-linux-gnu
configure:
configure:ConfiguringApachePortableRuntimelibrary...
configure:
checkingforAPR...no
configure:error:APRnotfound.Pleasereadthedocumentation.
[root@aminglinux-01httpd-2.4.27]#echo$?
1
[root@aminglinux-01httpd-2.4.27]#
```
-如果想检查上条命令是否正常,可以运行命令echo$?结果如果是非0就是不正常,如果是0就是正常上面出现这个报错:checkingforAPR...no那几用yum安装下APR
```
[root@aminglinux-01httpd-2.4.27]#yuminstall-yAPR
[root@aminglinux-01httpd-2.4.27]#yuminstall-yAPR
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
*epel:ftp.riken.jp
没有可用软件包APR。
*也许您想要:apr
错误:无须任何处理
[root@aminglinux-01httpd-2.4.27]#yuminstall-yapr
已加载插件:fastestmirror
Loadingmirrorspeedsfromcachedhostfile
*epel:mirrors.ustc.edu.cn
正在解决依赖关系
-->正在检查事务
--->软件包apr.x86_64.0.1.4.8-3.el7将被安装
-->解决依赖关系完成
依赖关系解决
===========================================================================================
Package架构版本源大小
===========================================================================================
正在安装:
aprx86_641.4.8-3.el7base103k
事务概要
===========================================================================================
安装1软件包
总下载量:103k
安装大小:221k
Downloadingpackages:
apr-1.4.8-3.el7.x86_64.rpm|103kB00:00:00
Runningtransactioncheck
Runningtransactiontest
Transactiontestsucceeded
Runningtransaction
正在安装:apr-1.4.8-3.el7.x86_641/1
验证中:apr-1.4.8-3.el7.x86_641/1
已安装:
apr.x86_640:1.4.8-3.el7
完毕!
[root@aminglinux-01httpd-2.4.27]#
```
-报错说也许要安装apr那就yum重新安装一次,
-
```
[root@aminglinux-01src]#wgethttp://mirrors.cnnic.cn/apache/httpd/httpd-2.4.27.tar.gz
--2017-08-1221: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请求,正在等待回应...200OK
长度:8603417(8.2M)[application/octet-stream]
正在保存至:“httpd-2.4.27.tar.gz.2”
100%[=================================================>]8,417532KB/s用时16s
2017-08-1221:32:23(531KB/s)-已保存“httpd-2.4.27.tar.gz.2”[8603417/8603417])
[root@aminglinux-01src]#
```
-再运行一次./configure--prefix=/usr/local/apache2命令
```
[root@aminglinux-01httpd-2.4.27]#./configure--prefix=/usr/local/apache2
checkingforchosenlayout...Apache
checkingforworkingmkdir-p...yes
checkingforgrepthathandleslonglinesand-e.../usr/bin/grep
checkingforegrep.../usr/bin/grep-E
checkingbuildsystemtype...x86_64-pc-linux-gnu
checkinghostsystemtype...x86_64-pc-linux-gnu
checkingtargetsystemtype...x86_64-pc-linux-gnu
configure:
configure:ConfiguringApachePortableRuntimelibrary...
configure:
checkingforAPR...no
configure:error:APRnotfound.Pleasereadthedocumentation.
```
-还是报错,说缺少APR
使用yumlist|grep-iapr把前面yum列表里的内容过滤有apr字符的包
```
[root@aminglinux-01httpd-2.4.27]#yumlist|grep-iapr
apr.x86_641.4.8-3.el7@base
apr.i6861.4.8-3.el7base
apr-devel.i6861.4.8-3.el7base
apr-devel.x86_641.4.8-3.el7base
apr-util.i6861.5.2-6.el7base
apr-util.x86_641.5.2-6.el7base
apr-util-devel.i6861.5.2-6.el7base
apr-util-devel.x86_641.5.2-6.el7base
apr-util-ldap.x86_641.5.2-6.el7base
apr-util-MysqL.x86_641.5.2-6.el7base
apr-util-nss.x86_641.5.2-6.el7base
apr-util-odbc.x86_641.5.2-6.el7base
apr-util-openssl.x86_641.5.2-6.el7base
apr-util-pgsql.x86_641.5.2-6.el7base
apr-util-sqlite.x86_641.5.2-6.el7base
haproxy.x86_641.5.18-3.el7_3.1updates
libapreq2.x86_642.13-11.el7.1epel
libapreq2-devel.x86_642.13-11.el7.1epel
libchromaprint.x86_641.0-1.el7epel
libchromaprint-devel.x86_641.0-1.el7epel
perl-libapreq2.x86_642.13-11.el7.1epel
PHP-whitehat101-apr1-md5.noarch1.0.0-1.el7epel
snapraid.x86_6410.0-1.el7epel
```
-安装下文件apr-devel.x86_64库文件
-安装完apr-devel.x86_64文件后,再继续运行./configure--prefix=/usr/local/apache2,还是报错
```
checkingwhethergccaccepts-g...yes
checkingforgccoptiontoacceptISOC89...noneneeded
checkinghowtoruntheCpreprocessor...gcc-E
checkingforgccoptiontoacceptISOC99...-std=gnu99
checkingforpcre-config...false
configure:error:pcre-configforlibpcrenotfound.PCREisrequiredandavailablefromhttp://pcre.org/
[root@aminglinux-01httpd-2.4.27]#echo$?
1
```
-echo$?检查上一步操作是否正常,如果是非0就是错误,0就是正常,上面显示缺少pcre库文件,继续使用命令yumlist|grep-ipcre
```
[root@aminglinux-01httpd-2.4.27]#yumlist|grep-ipcre
pcre.x86_648.32-15.el7_2.1@anaconda
ghc-pcre-light.x86_640.4-13.el7epel
ghc-pcre-light-devel.x86_640.4-13.el7epel
mingw32-pcre.noarch8.38-1.el7epel
mingw32-pcre-static.noarch8.38-1.el7epel
mingw64-pcre.noarch8.38-1.el7epel
mingw64-pcre-static.noarch8.38-1.el7epel
pcre.i6868.32-15.el7_2.1base
pcre-devel.i6868.32-15.el7_2.1base
pcre-devel.x86_648.32-15.el7_2.1base
pcre-static.i6868.32-15.el7_2.1base
pcre-static.x86_648.32-15.el7_2.1base
pcre-tools.x86_648.32-15.el7_2.1base
```
-再次安装库文件pcre-devel.x86_64使用命令yuminstall-ypcre-devel.x86_64
```
总下载量:479k
安装大小:1.4M
Downloadingpackages:
pcre-devel-8.32-15.el7_2.1.x86_64.rpm|479kB00:00:01
Runningtransactioncheck
Runningtransactiontest
Transactiontestsucceeded
Runningtransaction
正在安装:pcre-devel-8.32-15.el7_2.1.x86_641/1
验证中:pcre-devel-8.32-15.el7_2.1.x86_641/1
已安装:
pcre-devel.x86_640:8.32-15.el7_2.1
```
-再次运行./configure--prefix=/usr/local/apache2初始化配置
```
完毕!
[root@aminglinux-01httpd-2.4.27]#./configure--prefix=/usr/local/apache2
config.status:creatingbuild/pkg/pkginfo
config.status:creatingbuild/config_vars.sh
config.status:creatinginclude/ap_config_auto.h
config.status:executingdefaultcommands
configure:summaryofbuildoptions:
ServerVersion:2.4.27
Installprefix:/usr/local/apache2
Ccompiler:gcc-std=gnu99
CFLAGS:-pthread
LDFLAGS:
LIBS:
CPPFLAGS:-DLINUX-D_REENTRANT-D_GNU_SOURCE
Cpreprocessor:gcc-E
[root@aminglinux-01httpd-2.4.27]#echo$?
0
[root@aminglinux-01httpd-2.4.27]#
```
-第二步make
```
[root@aminglinux-01httpd-2.4.27]#make
```
#7.9源码包安装下
![mark](http://oqxf7c508.bkt.clouddn.com/blog/20170812/225212127.png?imageslim)
```
avoid-versionmod_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-01httpd-2.4.27]#
[root@aminglinux-01httpd-2.4.27]#echo$?
0
[root@aminglinux-01httpd-2.4.27]#
```
-第三步makeinstall
```
[root@aminglinux-01httpd-2.4.27]#makeinstall
Installingmanpagesandonlinemanual
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-01httpd-2.4.27]#echo$?
0
```
-打开就可以看到生成了这么多目录,这就是源码编译安装的包
```
[root@aminglinux-01httpd-2.4.27]#ls/usr/local/apache2
binbuildcgi-binconferrorhtdocsiconsincludelogsmanmanualmodules
[root@aminglinux-01httpd-2.4.27]#
```
-源码包一定要去官方下载,或者是可信任的站点这样比较安全,不要随便自己去去,随便下会容易出现木马,这样事情很可怕。
##扩展
-[]1.配置yum源优先级http://ask.apelearn.com/question/7168
yum更新源优先级设置
1.安装yum-priorities
yuminstallyum-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
ThirdPartyRepossuchasrpmforge…priority=N(whereNis>10andbasedonyourpreference)
数字越大,优先级越低
-[]2.把源码包打包成rpm包http://www.linuxidc.com/Linux/2012-09/70096.htm
有好多朋友问到怎么制作rpm包,可不可把其它服务器上编译好的软件目录复杂到其它服务器上直接应用等等。。。这里做个简单的介绍,高级复杂的不会。
此方法是通过编写spec文件,使用rpmbuild来完成一个rpm的打包。
以Nginx为例进行介绍
制作平台:CentOS5.xX86_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
wgethttp://Nginx.org/download/Nginx-1.2.0.tar.gz
第三步:生成Nginx.spec文件
```
cd/usr/src/redhat/SPECS
catNginx.spec
#
#specfileforNginx
#Build2012-07-17
#Byopsren
#
Summary:Highperformancewebserver
Name:Nginx
Version:1.2
Release:0.el5.ngx
License:2-clauseBSD-likelicense
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("enginex")isahighperformanceHTTPandreverseproxyserver,aswellasamail(IMAP/POP3/SMTP)proxyserver.
%prep
tarzxf$RPM_SOURCE_DIR/Nginx-1.2.0.tar.gz
%build
cdNginx-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
cdNginx-1.2.0
makeinstall
%preun
if[-z"`psaux|grepNginx|grep-vgrep`"];then
pkillNginx>/dev/null
exit0
fi
%files
/usr/local/webserver/Nginx
```
第四步:RPM包制作
首先系统要安装好必备的制作工具:gcc、rpmbuild等
yum-yinstallgccrpm-buildpcre-devel
cd/usr/src/redhat/SPECS/
rpmbuild-bbNginx.spec
通过上面这条命令,会在/usr/src/redhat/RPMS/x86_64/下面生成Nginx-1.2.0-1.el5.ngx.x86_64.rpm这个文件
-bb这个选项就是制作二进制包(buildbinarypackageonlyfrom<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文件实例:
```
#
#specfileforapache
#Build2012-07-17
#Byopsren
#
Summary:Highstabilitywebserver
Name:Apache
Version:2.2
Release:22.el5
License:2-clauseBSD-likelicense
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
Apacheisafirstwebserver
%prep
tarzxf$RPM_SOURCE_DIR/httpd-2.2.22.tar.gz
%build
cdhttpd-2.2.22
./configure--prefix=/usr/local/webserver/apache--enable-so--enable-deflate--enable-headers--enable-mods-shared=all--enable-rewrite
make
%install
cdhttpd-2.2.22
makeinstall
%preun
if[-z"`psaux|grephttpd|grep-vgrep`"];then
pkillhttpd>/dev/null
exit0
fi
%files
/usr/local/webserver/apache
```
以后对于相同或类似平台可以到其它服务器上进行rpm安装部署。
另外还有一种rpm打包的方法:rpm_create
这是一种新的打rpm的工具,不用spec语言,只需要会简单的shell命令,即可完成打包操作,非常方便,结合了spec语言和checkinstall,相比spec方法要简单很多!
官方站点:http://code.google.com/p/rpmcreate/
下载站点:wgethttp://rpmcreate.googlecode.com/files/rpm_create-1.7.5-9.x86_64.rpm
大家可以去官方站点参考!
原文链接:https://www.f2er.com/bash/391111.html