7.6、yum更换国内源
- centos7自带的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. [root@localhost ~]# cd /etc/yum.repos.d/
2. [root@localhost yum.repos.d]# cat CentOS-Base.repo
3. # CentOS-Base.repo
4. #
5. # The mirror system uses the connecting IP address of the client and the
6. # update status of each mirror to pick mirrors that are updated to and
7. # geographically close to the client. You should use this for CentOS updates
8. # unless you are manually picking other mirrors.
9. #
10. # If the mirrorlist= does not work for you, as a fall back you can try the
11. # remarked out baseurl= line instead.
12. #
13. #
14.
15. [base]
16. name=CentOS-$releasever - Base
17. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
18. #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
19. gpgcheck=1
20. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
21.
22. #released updates
23. [updates]
24. name=CentOS-$releasever - Updates
25. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
26. #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
27. gpgcheck=1
28. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
29.
30. #additional packages that may be useful
31. [extras]
32. name=CentOS-$releasever - Extras
33. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
34. #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
35. gpgcheck=1
36. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
37.
38. #additional packages that extend functionality of existing packages
39. [centosplus]
40. name=CentOS-$releasever - Plus
41. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
42. #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
43. gpgcheck=1
44. enabled=0
45. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
46.
47. [root@localhost yum.repos.d]#
- 删除CentOS-Base.repo删除改文件后就无法使用yum安装任何命令
1. [root[@localhost](https://my.oschina.net/u/570656) yum.repos.d]# rm -f CentOS-Base.repo
2. [root[@localhost](https://my.oschina.net/u/570656) yum.repos.d]# ls
3. CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
4. CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
5. [root[@localhost](https://my.oschina.net/u/570656) yum.repos.d]#
6. [root[@localhost](https://my.oschina.net/u/570656) yum.repos.d]# yum install -y wget
7. 已加载插件:fastestmirror
8. There are no enabled repos.
9. Run "yum repolist all" to see the repos you have.
10. To enable Red Hat Subscription Management repositories:
11. subscription-manager repos --enable <repo>
12. To enable custom repositories:
13. yum-config-manager --enable <repo>
14. [root[@localhost](https://my.oschina.net/u/570656) yum.repos.d]#
- 在无法使用yum install -y wget安装并使用wget命令时,使用curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo 更换为国内的源
1. [root@localhost yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo % Total % Received % Xferd Average Speed Time Time Time Current
2. Dload Upload Total Spent Left Speed
3. 100 1572 100 1572 0 0 10056 0 --:--:-- --:--:-- --:--:-- 10141
4. [root@localhost yum.repos.d]# ls
5. CentOS7-Base-163.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
6. CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
- 查看源
* [root@localhost yum.repos.d]# cat 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]
* name=CentOS-$releasever - Extras - 163.com
* #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
* baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
* gpgcheck=1
* gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
*
* #additional packages that extend functionality of existing packages
* [centosplus]
* name=CentOS-$releasever - Plus - 163.com
* baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
* gpgcheck=1
* enabled=0
* gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
* [root@localhost yum.repos.d]#
*
7.7、yum下载rpm包
- 安装扩展源epel
- yum install -y epel-release
- yum list |grep epel
1. [root@localhost yum.repos.d]# ls
2. CentOS7-Base-163.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
3. CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
4. [root@localhost yum.repos.d]# yum install -y epel-release
5. 已加载插件:fastestmirror
6. Loading mirror speeds from cached hostfile
7. 正在解决依赖关系
8. --> 正在检查事务
9. ---> 软件包 epel-release.noarch.0.7-9 将被 安装
10. --> 解决依赖关系完成
11.
12. 依赖关系解决
13.
14. ==========================================================================================================================
15. Package 架构 版本 源 大小
16. ==========================================================================================================================
17. 正在安装:
18. epel-release noarch 7-9 extras 14 k
19.
20. 事务概要
21. ==========================================================================================================================
22. 安装 1 软件包
23.
24. 总下载量:14 k
25. 安装大小:24 k
26. Downloading packages:
27. epel-release-7-9.noarch.rpm | 14 kB 00:00:00
28. Running transaction check
29. Running transaction test
30. Transaction test succeeded
31. Running transaction
32. 正在安装 : epel-release-7-9.noarch 1/1
33. 验证中 : epel-release-7-9.noarch 1/1
34.
35. 已安装:
36. epel-release.noarch 0:7-9
37.
38. 完毕!
39. [root@localhost yum.repos.d]# ls
40. CentOS7-Base-163.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel-testing.repo
41. CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo epel.repo
42. [root@localhost yum.repos.d]#
- 使用yum下载rpm包
- yum install -y包名 --downloadonly
- ls /var/cache/yum/x86_64/7/
- yum install -y 包名 --downloadonly --downloaddir=路径
- yum reinstall -y 包名 --downloadonly --downloaddir=路径
1. [root@localhost yum.repos.d]# yum install zsh --downloadonly
2. 已加载插件:fastestmirror
3. Loading mirror speeds from cached hostfile
4. * epel: mirrors.ustc.edu.cn
5. 正在解决依赖关系
6. --> 正在检查事务
7. ---> 软件包 zsh.x86_64.0.5.0.2-28.el7 将被 安装
8. --> 解决依赖关系完成
9.
10. 依赖关系解决
11.
12. ==========================================================================================================================
13. Package 架构 版本 源 大小
14. ==========================================================================================================================
15. 正在安装:
16. zsh x86_64 5.0.2-28.el7 base 2.4 M
17.
18. 事务概要
19. ==========================================================================================================================
20. 安装 1 软件包
21.
22. 总下载量:2.4 M
23. 安装大小:5.6 M
24. Background downloading packages, then exiting:
25. zsh-5.0.2-28.el7.x86_64.rpm | 2.4 MB 00:00:00
26. exiting because "Download Only" specified
27. [root@localhost yum.repos.d]# rpm -q zsh //查询是否安装
28. 未安装软件包 zsh
29. [root@localhost yum.repos.d]#
- 下载的rpm包存放在这个路径下
1. [root@localhost yum.repos.d]# ls /var/cache/yum/x86_64/7/base/packages/
2. zsh-5.0.2-28.el7.x86_64.rpm
3. [root@localhost yum.repos.d]#
- 指定下载路径
1. [root@localhost yum.repos.d]# yum install zabbix22-server.noarch --downloadonly --downloaddir=/tmp/
2. [root@localhost yum.repos.d]# ls /tmp/
3. fping-3.10-4.el7.x86_64.rpm unixODBC-2.3.1-11.el7.x86_64.rpm
4. iksemel-1.4-6.el7.x86_64.rpm yum.log
5. ks-script-JkctqZ yum_save_tx.2017-11-15.17-24.XxJ8jY.yumtx
6. libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm yum_save_tx.2017-11-15.17-33.1i8eN0.yumtx
7. net-snmp-libs-5.7.2-28.el7.x86_64.rpm zabbix22-2.2.20-1.el7.x86_64.rpm
8. OpenIPMI-libs-2.0.19-15.el7.x86_64.rpm zabbix22-dbfiles-mysql-2.2.20-1.el7.noarch.rpm
9. OpenIPMI-modalias-2.0.19-15.el7.x86_64.rpm zabbix22-server-2.2.20-1.el7.noarch.rpm
10. systemd-private-3f6913cce3aa4159a0eb9d10baa09308-vmtoolsd.service-F5ODMg zabbix22-server-mysql-2.2.20-1.el7.x86_64.rpm
11. traceroute-2.0.22-2.el7.x86_64.rpm
12. [root@localhost yum.repos.d]#
- 如果已经安装的包,只下载则提示无须任何处理,无法下载
1. [root@localhost yum.repos.d]# yum install vim-enhanced --downloadonly --downloaddir=/tmp/
2. 已加载插件:fastestmirror
3. Loading mirror speeds from cached hostfile
4. * epel: mirrors.ustc.edu.cn
5. 软件包 2:vim-enhanced-7.4.160-2.el7.x86_64 已安装并且是最新版本
6. 无须任何处理
7. [root@localhost yum.repos.d]# ls /tmp/
8. fping-3.10-4.el7.x86_64.rpm unixODBC-2.3.1-11.el7.x86_64.rpm
9. iksemel-1.4-6.el7.x86_64.rpm yum.log
10. ks-script-JkctqZ yum_save_tx.2017-11-15.17-24.XxJ8jY.yumtx
11. libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm yum_save_tx.2017-11-15.17-33.1i8eN0.yumtx
12. net-snmp-libs-5.7.2-28.el7.x86_64.rpm zabbix22-2.2.20-1.el7.x86_64.rpm
13. OpenIPMI-libs-2.0.19-15.el7.x86_64.rpm zabbix22-dbfiles-mysql-2.2.20-1.el7.noarch.rpm
14. OpenIPMI-modalias-2.0.19-15.el7.x86_64.rpm zabbix22-server-2.2.20-1.el7.noarch.rpm
15. systemd-private-3f6913cce3aa4159a0eb9d10baa09308-vmtoolsd.service-F5ODMg zabbix22-server-mysql-2.2.20-1.el7.x86_64.rpm
16. traceroute-2.0.22-2.el7.x86_64.rpm
17. [root@localhost yum.repos.d]#
- 使用yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/
1. [root@localhost ~]# yum reinstall vim-enhanced --downloadonly --downloaddir=/tmp/
2. 已加载插件:fastestmirror
3. Loading mirror speeds from cached hostfile
4. * epel: mirrors.ustc.edu.cn
5. 正在解决依赖关系
6. --> 正在检查事务
7. ---> 软件包 vim-enhanced.x86_64.2.7.4.160-2.el7 将被 已重新安装
8. --> 解决依赖关系完成
9.
10. 依赖关系解决
11.
12. ==========================================================================================================================
13. Package 架构 版本 源 大小
14. ==========================================================================================================================
15. 重新安装:
16. vim-enhanced x86_64 2:7.4.160-2.el7 base 1.0 M
17.
18. 事务概要
19. ==========================================================================================================================
20. 重新安装 1 软件包
21.
22. 总下载量:1.0 M
23. 安装大小:2.2 M
24. Background downloading packages, then exiting:
25. vim-enhanced-7.4.160-2.el7.x86_64.rpm | 1.0 MB 00:00:00
26. exiting because "Download Only" specified
27. [root@localhost ~]# ls /tmp/
28. fping-3.10-4.el7.x86_64.rpm vim-enhanced-7.4.160-2.el7.x86_64.rpm
29. iksemel-1.4-6.el7.x86_64.rpm yum.log
30. ks-script-JkctqZ yum_save_tx.2017-11-15.17-24.XxJ8jY.yumtx
31. libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm yum_save_tx.2017-11-15.17-33.1i8eN0.yumtx
32. net-snmp-libs-5.7.2-28.el7.x86_64.rpm yum_save_tx.2017-11-15.17-41.kw2dtr.yumtx
33. OpenIPMI-libs-2.0.19-15.el7.x86_64.rpm zabbix22-2.2.20-1.el7.x86_64.rpm
34. OpenIPMI-modalias-2.0.19-15.el7.x86_64.rpm zabbix22-dbfiles-mysql-2.2.20-1.el7.noarch.rpm
35. systemd-private-3f6913cce3aa4159a0eb9d10baa09308-vmtoolsd.service-F5ODMg zabbix22-server-2.2.20-1.el7.noarch.rpm
36. traceroute-2.0.22-2.el7.x86_64.rpm zabbix22-server-mysql-2.2.20-1.el7.x86_64.rpm
37. unixODBC-2.3.1-11.el7.x86_64.rpm
38. [root@localhost ~]#
7.8、源码包安装(上)
- 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
- 卸载就是删除安装的文件
- 约定:源码包都放在/usr/local/src/目录下
1. [root@localhost ~]# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
2. --2017-11-15 17:50:25-- http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.34.tar.gz
3. 正在解析主机 mirrors.cnnic.cn (mirrors.cnnic.cn)... 101.6.6.177, 2402:f000:1:416:101:6:6:177
4. 正在连接 mirrors.cnnic.cn (mirrors.cnnic.cn)|101.6.6.177|:80... 已连接。
5. 已发出 HTTP 请求,正在等待回应... 200 OK
6. 长度:7684419 (7.3M) [application/octet-stream]
7. 正在保存至: “httpd-2.2.34.tar.gz”
8.
9. 100%[================================================================================>] 7,684,419 2.10MB/s 用时 3.6s
10.
11. 2017-11-15 17:50:29 (2.06 MB/s) - 已保存 “httpd-2.2.34.tar.gz” [7684419/7684419])
12.
13. [root@localhost ~]# ls
14. anaconda-ks.cfg httpd-2.2.34.tar.gz
15. [root@localhost ~]# mv httpd-2.2.34.tar.gz /usr/local/src/
16. [root@localhost ~]# cd /usr/local/src/
17. [root@localhost src]# ls
18. httpd-2.2.34.tar.gz
19. tar -zxvf http-2.2.34.tar.gz //解压
20. [root@localhost src]# cd httpd-2.2.34
21. [root@localhost httpd-2.2.34]# ls
22. ABOUT_APACHE BuildBin.dsp configure.in httpd.mak LAYOUT Makefile.in os server
23. acinclude.m4 buildconf docs httpd.spec libhttpd.dep Makefile.win README srclib
24. Apache.dsw CHANGES emacs-style include libhttpd.dsp modules README.platforms support
25. build config.layout httpd.dep INSTALL libhttpd.mak NOTICE README-win32.txt test
26. BuildAll.dsp configure httpd.dsp InstallBin.dsp LICENSE NWGNUmakefile ROADMAP VERSIONING
-
查看README和INSTALL文档
-
编译安装
1. [root@localhost httpd-2.2.34]# ./configure --prefix=/usr/local/apache2
2. checking for chosen layout... Apache
3. checking for working mkdir -p... yes
4. checking build system type... x86_64-unknown-linux-gnu
5. checking host system type... x86_64-unknown-linux-gnu
6. checking target system type... x86_64-unknown-linux-gnu
7.
8. Configuring Apache Portable Runtime library ...
9.
10. checking for APR... reconfig
11. configuring package in srclib/apr now
12. checking build system type... x86_64-unknown-linux-gnu
13. checking host system type... x86_64-unknown-linux-gnu
14. checking target system type... x86_64-unknown-linux-gnu
15. Configuring APR library
16. Platform: x86_64-unknown-linux-gnu
17. checking for working mkdir -p... yes
18. APR Version: 1.5.2
19. checking for chosen layout... apr
20. checking for gcc... no //提示没有gcc,解决方法:yum install -y gcc
21. checking for cc... no
22. checking for cl.exe... no
23. configure: error: in `/usr/local/src/httpd-2.2.34/srclib/apr': //报错
24. configure: error: no acceptable C compiler found in $PATH //报错
25. See `config.log' for more details
26. configure failed for srclib/apr
27. [root@localhost httpd-2.2.34]#
- 使用echo $?返回值非0是指上一条命令报错,此命令用于检测上一条命令是否正确;
1. [root@localhost httpd-2.2.34]# echo $?
2. 1
3. [root@localhost httpd-2.2.34]#
- 安装完gcc后,再运行./configure --prefix=/usr/local/apache2,完成后echo $?检测。
- 完成后make,等待完成
7.9、源码安装(下)
- make install 命令会把编译后的文档放置在--prefix下指定的目录里
1. [root@localhost httpd-2.2.34]# cd /usr/local/apache2/
2. [root@localhost apache2]# ls
3. bin build cgi-bin conf error htdocs icons include lib logs man manual modules
4. [root@localhost apache2]#
- 源码包安装可以指定目录,把所有文件都放在一个目录下,如果需要卸载,直接删除该目录即可。
- 源码包下载一定要具备可靠性、安全性。
扩展学习
-
yum更新源码包优先级设置
- 安装 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)
- 数字越大,优先级越低
-
简单制作RPM二进制包实例