目录

一、安装软件包的三种方法

二、rpm包介绍

三、rpm工具用法

四、yum工具用法

五、yum搭建本地仓库

六、yum更换国内源

七、yum下载rpm包

八、源码包安装

九、扩展

一、安装软件包的三种方法

1.二进制包(Centos是RPM格式,Debian是Deb格式)

2.Yum在线安装

3.源代码包安装

其实还有脚本安装方式。一般一个源代码包的安装最好是查看一下README和INSTALL文件。

二、rpm包介绍

rpm是Redhat Package Manager的缩写,是由Redhat提出,用于管理linux系统的软件包。

RPM包的名称一般为:名称-版本-发布序列号-软件平台-硬件平台.扩展名

挂载光盘镜像

虚拟机加载光盘镜像ISO文件

挂载光盘

  1. [root@localhost ~]# mkdir /mnt/cdrom
  2. [root@localhost ~]# mount /dev/sr0 /mnt/cdrom/
  3. mount: /dev/sr0 is write-protected, mounting read-only

RPM包所在位置

  1. [root@localhost ~]# ls /mnt/cdrom/Packages/ | head -n 5
  2. 389-ds-base-1.3.1.6-25.el7.x86_64.rpm
  3. 389-ds-base-libs-1.3.1.6-25.el7.x86_64.rpm
  4. abattis-cantarell-fonts-0.0.12-3.el7.noarch.rpm
  5. abrt-2.1.11-12.el7.centos.x86_64.rpm
  6. abrt-addon-ccpp-2.1.11-12.el7.centos.x86_64.rpm

三、RPM工具用法

rpm工具常用选项

-i 安装

-U 升级软件包

-V 显示详细安装信息

-h 以安装信息列显示安装进度

-e 卸载rpm包

-q 查询软件包

-qi 查询已安装的指定包信息

-ql 列出一个包安装的文件

-qf 查看命令由哪个安装包而来

-qd 查看文档安装位置

-qpi 查看未安装rpm包的信息

-qpl 查看未安装rpm包将要安装哪些文件

-qpR 查看软件包的依赖关系

--nodeps 在升级或安装rpm包时不检查其依赖关系

--test 并不真正安装rpm包,检测并报告可能的冲突

rpm包安装

  1. [root@localhost Packages]# rpm -ivh dos2unix-6.0.3-4.el7.x86_64.rpm
  2. warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  3. Preparing... ################################# [100%]
  4. Updating / installing...
  5. 1:dos2unix-6.0.3-4.el7 ################################# [100%]

升级安装rpm包

  1. [root@localhost Packages]# rpm -Uvh dos2unix-6.0.3-4.el7.x86_64.rpm
  2. warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  3. Preparing... ################################# [100%]
  4. package dos2unix-6.0.3-4.el7.x86_64 is already installed

卸载软件包

  1. [root@localhost Packages]# rpm -e dos2unix
  2. [root@localhost Packages]# rpm -q dos2unix
  3. package dos2unix is not installed

查询软件包

  1. [root@localhost Packages]# rpm -q vim-enhanced
  2. vim-enhanced-7.4.160-1.el7.x86_64

查询已安装包信息

  1. [root@localhost Packages]# rpm -qi dos2unix
  2. Name : dos2unix
  3. Version : 6.0.3
  4. Release : 4.el7
  5. Architecture: x86_64
  6. Install Date: Tue 29 May 2018 09:25:04 PM EDT
  7. Group : Applications/Text
  8. Size : 178697
  9. License : BSD
  10. Signature : RSA/SHA256, Thu 03 Jul 2014 09:09:30 PM EDT, Key ID 24c6a8a7f4a80eb5
  11. Source RPM : dos2unix-6.0.3-4.el7.src.rpm
  12. Build Date : Mon 09 Jun 2014 06:00:48 PM EDT
  13. Build Host : worker1.bsys.centos.org
  14. Relocations : (not relocatable)
  15. Packager : CentOS BuildSystem <http://bugs.centos.org>
  16. Vendor : CentOS
  17. URL : http://waterlan.home.xs4all.nl/dos2unix.html
  18. Summary : Text file format converters
  19. Description :
  20. Convert text files with DOS or Mac line endings to Unix line endings and
  21. vice versa.

列出一个rpm包安装的文件

  1. [root@localhost Packages]# rpm -ql dos2unix
  2. /usr/bin/dos2unix
  3. /usr/bin/mac2unix
  4. /usr/bin/unix2dos
  5. /usr/bin/unix2mac
  6. /usr/share/doc/dos2unix-6.0.3
  7. /usr/share/doc/dos2unix-6.0.3/COPYING.txt
  8. /usr/share/doc/dos2unix-6.0.3/ChangeLog.txt
  9. /usr/share/doc/dos2unix-6.0.3/NEWS.txt
  10. /usr/share/doc/dos2unix-6.0.3/README.txt
  11. /usr/share/doc/dos2unix-6.0.3/TODO.txt
  12. /usr/share/doc/dos2unix-6.0.3/dos2unix.htm
  13. /usr/share/locale/de/LC_MESSAGES/dos2unix.mo
  14. /usr/share/locale/eo/LC_MESSAGES/dos2unix.mo
  15. /usr/share/locale/es/LC_MESSAGES/dos2unix.mo
  16. /usr/share/locale/nl/LC_MESSAGES/dos2unix.mo
  17. /usr/share/man/es/man1/dos2unix.1.gz
  18. /usr/share/man/es/man1/mac2unix.1.gz
  19. /usr/share/man/es/man1/unix2dos.1.gz
  20. /usr/share/man/es/man1/unix2mac.1.gz
  21. /usr/share/man/man1/dos2unix.1.gz
  22. /usr/share/man/man1/mac2unix.1.gz
  23. /usr/share/man/man1/unix2dos.1.gz
  24. /usr/share/man/man1/unix2mac.1.gz
  25. /usr/share/man/nl/man1/dos2unix.1.gz
  26. /usr/share/man/nl/man1/mac2unix.1.gz
  27. /usr/share/man/nl/man1/unix2dos.1.gz
  28. /usr/share/man/nl/man1/unix2mac.1.gz

查看命令由哪个包安装而来

  1. [root@localhost Packages]# rpm -qf /usr/sbin/ifconfig
  2. net-tools-2.0-0.17.20131004git.el7.x86_64
  3. //常见用法,用反引号取命令的绝对路径
  4. [root@localhost Packages]# rpm -qf `which ifconfig`
  5. net-tools-2.0-0.17.20131004git.el7.x86_64
  6. //推荐做法
  7. [root@localhost Packages]# rpm -qf $(which ifconfig)
  8. net-tools-2.0-0.17.20131004git.el7.x86_64

查看文档安装位置

  1. [root@localhost Packages]# rpm -qd dos2unix
  2. /usr/share/doc/dos2unix-6.0.3/COPYING.txt
  3. /usr/share/doc/dos2unix-6.0.3/ChangeLog.txt
  4. /usr/share/doc/dos2unix-6.0.3/NEWS.txt
  5. /usr/share/doc/dos2unix-6.0.3/README.txt
  6. /usr/share/doc/dos2unix-6.0.3/TODO.txt
  7. /usr/share/doc/dos2unix-6.0.3/dos2unix.htm
  8. /usr/share/man/es/man1/dos2unix.1.gz
  9. /usr/share/man/es/man1/mac2unix.1.gz
  10. /usr/share/man/es/man1/unix2dos.1.gz
  11. /usr/share/man/es/man1/unix2mac.1.gz
  12. /usr/share/man/man1/dos2unix.1.gz
  13. /usr/share/man/man1/mac2unix.1.gz
  14. /usr/share/man/man1/unix2dos.1.gz
  15. /usr/share/man/man1/unix2mac.1.gz
  16. /usr/share/man/nl/man1/dos2unix.1.gz
  17. /usr/share/man/nl/man1/mac2unix.1.gz
  18. /usr/share/man/nl/man1/unix2dos.1.gz
  19. /usr/share/man/nl/man1/unix2mac.1.gz

查看未安装rpm包的信息

  1. [root@localhost Packages]# rpm -q dos2unix-6.0.3-4.el7.x86_64.rpm
  2. package dos2unix-6.0.3-4.el7.x86_64.rpm is not installed
  3. //查看未安装rpm包的信息
  4. [root@localhost Packages]# rpm -qpi dos2unix-6.0.3-4.el7.x86_64.rpm
  5. warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  6. Name : dos2unix
  7. Version : 6.0.3
  8. Release : 4.el7
  9. Architecture: x86_64
  10. Install Date: (not installed)
  11. Group : Applications/Text
  12. Size : 178697
  13. License : BSD
  14. Signature : RSA/SHA256, Thu 03 Jul 2014 09:09:30 PM EDT, Key ID 24c6a8a7f4a80eb5
  15. Source RPM : dos2unix-6.0.3-4.el7.src.rpm
  16. Build Date : Mon 09 Jun 2014 06:00:48 PM EDT
  17. Build Host : worker1.bsys.centos.org
  18. Relocations : (not relocatable)
  19. Packager : CentOS BuildSystem <http://bugs.centos.org>
  20. Vendor : CentOS
  21. URL : http://waterlan.home.xs4all.nl/dos2unix.html
  22. Summary : Text file format converters
  23. Description :
  24. Convert text files with DOS or Mac line endings to Unix line endings and
  25. vice versa.

查看未安装rpm包将要安装哪些文件

  1. [root@localhost Packages]# rpm -qpl dos2unix-6.0.3-4.el7.x86_64.rpm
  2. warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  3. /usr/bin/dos2unix
  4. /usr/bin/mac2unix
  5. /usr/bin/unix2dos
  6. /usr/bin/unix2mac
  7. /usr/share/doc/dos2unix-6.0.3
  8. /usr/share/doc/dos2unix-6.0.3/COPYING.txt
  9. /usr/share/doc/dos2unix-6.0.3/ChangeLog.txt
  10. /usr/share/doc/dos2unix-6.0.3/NEWS.txt
  11. /usr/share/doc/dos2unix-6.0.3/README.txt
  12. /usr/share/doc/dos2unix-6.0.3/TODO.txt
  13. /usr/share/doc/dos2unix-6.0.3/dos2unix.htm
  14. /usr/share/locale/de/LC_MESSAGES/dos2unix.mo
  15. /usr/share/locale/eo/LC_MESSAGES/dos2unix.mo
  16. /usr/share/locale/es/LC_MESSAGES/dos2unix.mo
  17. /usr/share/locale/nl/LC_MESSAGES/dos2unix.mo
  18. /usr/share/man/es/man1/dos2unix.1.gz
  19. /usr/share/man/es/man1/mac2unix.1.gz
  20. /usr/share/man/es/man1/unix2dos.1.gz
  21. /usr/share/man/es/man1/unix2mac.1.gz
  22. /usr/share/man/man1/dos2unix.1.gz
  23. /usr/share/man/man1/mac2unix.1.gz
  24. /usr/share/man/man1/unix2dos.1.gz
  25. /usr/share/man/man1/unix2mac.1.gz
  26. /usr/share/man/nl/man1/dos2unix.1.gz
  27. /usr/share/man/nl/man1/mac2unix.1.gz
  28. /usr/share/man/nl/man1/unix2dos.1.gz
  29. /usr/share/man/nl/man1/unix2mac.1.gz

查看软件包的依赖关系

  1. [root@localhost Packages]# rpm -qpR dos2unix-6.0.3-4.el7.x86_64.rpm
  2. warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  3. libc.so.6()(64bit)
  4. libc.so.6(GLIBC_2.2.5)(64bit)
  5. libc.so.6(GLIBC_2.3.4)(64bit)
  6. libc.so.6(GLIBC_2.4)(64bit)
  7. rpmlib(CompressedFileNames) <= 3.0.4-1
  8. rpmlib(FileDigests) <= 4.6.0-1
  9. rpmlib(PayloadFilesHavePrefix) <= 4.0-1
  10. rtld(GNU_HASH)
  11. rpmlib(PayloadIsXz) <= 5.2-1

升级或安装rpm包时不检查依赖关系

  1. [root@localhost Packages]# rpm -ivh wireshark-1.10.3-10.el7.x86_64.rpm
  2. warning: wireshark-1.10.3-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  3. error: Failed dependencies:
  4. libcares.so.2()(64bit) is needed by wireshark-1.10.3-10.el7.x86_64
  5. libsmi.so.2()(64bit) is needed by wireshark-1.10.3-10.el7.x86_64
  6. [root@localhost Packages]# rpm -ivh --nodeps wireshark-1.10.3-10.el7.x86_64.rpm
  7. warning: wireshark-1.10.3-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  8. Preparing... ################################# [100%]
  9. Updating / installing...
  10. 1:wireshark-1.10.3-10.el7 ################################# [100%]
  11. [root@localhost Packages]# rpm -q wireshark
  12. wireshark-1.10.3-10.el7.x86_64

不真正安装rpm包,检测并报告可能的冲突

  1. [root@localhost Packages]# rpm -ivh --test wireshark-1.10.3-10.el7.x86_64.rpm
  2. warning: wireshark-1.10.3-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  3. error: Failed dependencies:
  4. libcares.so.2()(64bit) is needed by wireshark-1.10.3-10.el7.x86_64
  5. libsmi.so.2()(64bit) is needed by wireshark-1.10.3-10.el7.x86_64

四、YUM工具用法

软件包安装

  1. //-y 自动应答
  2. [root@localhost yum.repos.d]# yum -y install dos2unix
  3. Loaded plugins: fastestmirror
  4. Loading mirror speeds from cached hostfile
  5. Resolving Dependencies
  6. --> Running transaction check
  7. ---> Package dos2unix.x86_64 0:6.0.3-4.el7 will be installed
  8. --> Finished Dependency Resolution
  9. Dependencies Resolved
  10. =====================================================================================================================================
  11. Package Arch Version Repository Size
  12. =====================================================================================================================================
  13. Installing:
  14. dos2unix x86_64 6.0.3-4.el7 base 58 k
  15. Transaction Summary
  16. =====================================================================================================================================
  17. Install 1 Package
  18. Total download size: 58 k
  19. Installed size: 175 k
  20. Downloading packages:
  21. Running transaction check
  22. Running transaction test
  23. Transaction test succeeded
  24. Running transaction
  25. Installing : dos2unix-6.0.3-4.el7.x86_64 1/1
  26. Verifying : dos2unix-6.0.3-4.el7.x86_64 1/1
  27. Installed:
  28. dos2unix.x86_64 0:6.0.3-4.el7
  29. Complete!

列出可用安装包

  1. //推荐用grep过滤,否则会导致出现的结果过多,不方便查看
  2. [root@localhost yum.repos.d]# yum list | grep dos2unix
  3. dos2unix.x86_64 6.0.3-4.el7 @base

卸载软件包

  1. //不建议加上-y选项自动应答,因为yum工具卸载会自动卸载依赖关系。
  2. [root@localhost yum.repos.d]# yum remove dos2unix
  3. Loaded plugins: fastestmirror
  4. Resolving Dependencies
  5. --> Running transaction check
  6. ---> Package dos2unix.x86_64 0:6.0.3-4.el7 will be erased
  7. --> Finished Dependency Resolution
  8. Dependencies Resolved
  9. =====================================================================================================================================
  10. Package Arch Version Repository Size
  11. =====================================================================================================================================
  12. Removing:
  13. dos2unix x86_64 6.0.3-4.el7 @base 175 k
  14. Transaction Summary
  15. =====================================================================================================================================
  16. Remove 1 Package
  17. Installed size: 175 k
  18. Is this ok [y/N]: y
  19. Downloading packages:
  20. Running transaction check
  21. Running transaction test
  22. Transaction test succeeded
  23. Running transaction
  24. Erasing : dos2unix-6.0.3-4.el7.x86_64 1/1
  25. Verifying : dos2unix-6.0.3-4.el7.x86_64 1/1
  26. Removed:
  27. dos2unix.x86_64 0:6.0.3-4.el7
  28. Complete!

查看软件包信息

  1. [root@localhost yum.repos.d]# yum info dos2unix
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. Available Packages
  5. Name : dos2unix
  6. Arch : x86_64
  7. Version : 6.0.3
  8. Release : 4.el7
  9. Size : 58 k
  10. Repo : base
  11. Summary : Text file format converters
  12. URL : http://waterlan.home.xs4all.nl/dos2unix.html
  13. License : BSD
  14. Description : Convert text files with DOS or Mac line endings to Unix line endings and
  15. : vice versa.

查询某件文件的提供包

  1. [root@localhost yum.repos.d]# yum provides /usr/bin/dos2unix
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. dos2unix-6.0.3-4.el7.x86_64 : Text file format converters
  5. Repo : base
  6. Matched from:
  7. Filename : /usr/bin/dos2unix
  8. dos2unix-6.0.3-4.el7.x86_64 : Text file format converters
  9. Repo : @base
  10. Matched from:
  11. Filename : /usr/bin/dos2unix

清除缓存信息

  1. [root@localhost yum.repos.d]# yum clean all
  2. Loaded plugins: fastestmirror
  3. Cleaning repos: base
  4. Cleaning up everything
  5. Cleaning up list of fastest mirrors

生成缓存信息

  1. [root@localhost yum.repos.d]# yum makecache
  2. Loaded plugins: fastestmirror
  3. base | 3.6 kB 00:00:00
  4. (1/4): base/group_gz | 157 kB 00:00:00
  5. (2/4): base/filelists_db | 2.8 MB 00:00:00
  6. (3/4): base/primary_db | 2.7 MB 00:00:00
  7. (4/4): base/other_db | 1.1 MB 00:00:00
  8. Determining fastest mirrors
  9. Metadata Cache Created

五、YUM搭建本地仓库

虚拟机加载Centos7操作系统ISO镜像文件

挂载光盘

  1. [root@localhost ~]# mkdir /mnt/cdrom
  2. [root@localhost ~]# mount /dev/sr0 /mnt/cdrom/
  3. mount: /dev/sr0 is write-protected, mounting read-only

备份原Repo文件

  1. [root@localhost Packages]# cd /etc/yum.repos.d/
  2. [root@localhost yum.repos.d]# find . -type f -exec mv {} {}.bak \;
  3. [root@localhost yum.repos.d]# cp CentOS-Base.repo.bak CentOS-Media.repo
  4. [root@localhost yum.repos.d]# vim CentOS-Media.repo
  5. //修改为以下内容
  6. 1 # CentOS-Media.repo
  7. 2 [base]
  8. 3 name=CentOS-$releasever - Base
  9. 4 baseurl=file:///mnt/cdrom
  10. 5 gpgcheck=0
  11. 6 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
  12. 7

清理缓存

  1. [root@localhost yum.repos.d]# yum clean all
  2. Loaded plugins: fastestmirror
  3. Cleaning repos: base
  4. Cleaning up everything
  5. Cleaning up list of fastest mirrors

生成新缓存

  1. [root@localhost yum.repos.d]# yum makecache
  2. Loaded plugins: fastestmirror
  3. base | 3.6 kB 00:00:00
  4. (1/4): base/group_gz | 157 kB 00:00:00
  5. (2/4): base/filelists_db | 2.8 MB 00:00:00
  6. (3/4): base/primary_db | 2.7 MB 00:00:00
  7. (4/4): base/other_db | 1.1 MB 00:00:00
  8. Determining fastest mirrors
  9. Metadata Cache Created
  10. [root@localhost yum.repos.d]# yum repolist
  11. Loaded plugins: fastestmirror
  12. Loading mirror speeds from cached hostfile
  13. repo id repo name status
  14. base CentOS-7 - Base 3,538
  15. repolist: 3,538

六、yum更换国内源

备份原始源CentOS-Base.repo

  1. [root@localhost Packages]# cd /etc/yum.repos.d/
  2. [root@localhost yum.repos.d]# find . -type f -exec mv {} {}.bak \;

添加国内源

  1. wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
  2. curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
  3. [root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
  4. --2018-05-30 02:52:39-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
  5. Resolving mirrors.163.com (mirrors.163.com)... 59.111.0.251
  6. Connecting to mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... connected.
  7. HTTP request sent, awaiting response... 200 OK
  8. Length: 1572 (1.5K) [application/octet-stream]
  9. Saving to: CentOS7-Base-163.repo
  10. 100%[===========================================================================================>] 1,572 --.-K/s in 0.03s
  11. 2018-05-30 02:52:39 (56.9 KB/s) - CentOS7-Base-163.repo saved [1572/1572]
  12. [root@localhost yum.repos.d]# ls
  13. CentOS7-Base-163.repo CentOS-Base.repo.bak CentOS-Debuginfo.repo.bak CentOS-Sources.repo.bak CentOS-Vault.repo.bak

安装扩展源epel

  1. [root@localhost yum.repos.d]# yum -y install epel-release
  2. Loaded plugins: fastestmirror
  3. extras | 3.4 kB 00:00:00
  4. updates | 3.4 kB 00:00:00
  5. (1/2): extras/7/x86_64/primary_db | 147 kB 00:00:03
  6. (2/2): updates/7/x86_64/primary_db | 2.0 MB 00:00:26
  7. Loading mirror speeds from cached hostfile
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package epel-release.noarch 0:7-11 will be installed
  11. --> Finished Dependency Resolution
  12. Dependencies Resolved
  13. =====================================================================================================================================
  14. Package Arch Version Repository Size
  15. =====================================================================================================================================
  16. Installing:
  17. epel-release noarch 7-11 extras 15 k
  18. Transaction Summary
  19. =====================================================================================================================================
  20. Install 1 Package
  21. Total download size: 15 k
  22. Installed size: 24 k
  23. Downloading packages:
  24. warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
  25. Public key for epel-release-7-11.noarch.rpm is not installed
  26. epel-release-7-11.noarch.rpm | 15 kB 00:00:00
  27. Retrieving key from http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
  28. Importing GPG key 0xF4A80EB5:
  29. Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
  30. Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
  31. From : http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
  32. Running transaction check
  33. Running transaction test
  34. Transaction test succeeded
  35. Running transaction
  36. Installing : epel-release-7-11.noarch 1/1
  37. Verifying : epel-release-7-11.noarch 1/1
  38. Installed:
  39. epel-release.noarch 0:7-11
  40. [root@localhost yum.repos.d]# yum repolist
  41. Loaded plugins: fastestmirror
  42. epel/x86_64/metalink | 5.6 kB 00:00:00
  43. epel | 4.7 kB 00:00:00
  44. (1/3): epel/x86_64/group_gz | 88 kB 00:00:03
  45. (2/3): epel/x86_64/updateinfo | 930 kB 00:00:08
  46. (3/3): epel/x86_64/primary_db | 6.4 MB 00:00:30
  47. Loading mirror speeds from cached hostfile
  48. * epel: mirrors.tuna.tsinghua.edu.cn
  49. repo id repo name status
  50. base/7/x86_64 CentOS-7 - Base - 163.com 3,538
  51. epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,577
  52. extras/7/x86_64 CentOS-7 - Extras - 163.com 305
  53. updates/7/x86_64 CentOS-7 - Updates - 163.com 632
  54. repolist: 17,052

七、yum下载rpm包

仅下载不安装rpm包

下载位置在:/var/cache/yum/x86_64/7/仓库名/packages/

  1. //跟--downloadonly选项
  2. [root@localhost yum.repos.d]# yum install zsh --downloadonly
  3. Loaded plugins: fastestmirror
  4. Loading mirror speeds from cached hostfile
  5. Resolving Dependencies
  6. --> Running transaction check
  7. ---> Package zsh.x86_64 0:5.0.2-7.el7 will be installed
  8. --> Finished Dependency Resolution
  9. Dependencies Resolved
  10. ===========================================================================================================
  11. Package Arch Version Repository Size
  12. ===========================================================================================================
  13. Installing:
  14. zsh x86_64 5.0.2-7.el7 base 2.4 M
  15. Transaction Summary
  16. ===========================================================================================================
  17. Install 1 Package
  18. Total download size: 2.4 M
  19. Installed size: 5.6 M
  20. Background downloading packages, then exiting:
  21. exiting because "Download Only" specified
  22. //不跟downloadonly选项,在自动应答时选d
  23. [root@localhost yum.repos.d]# yum install dos2unix
  24. Loaded plugins: fastestmirror
  25. Loading mirror speeds from cached hostfile
  26. Resolving Dependencies
  27. --> Running transaction check
  28. ---> Package dos2unix.x86_64 0:6.0.3-4.el7 will be installed
  29. --> Finished Dependency Resolution
  30. Dependencies Resolved
  31. ===========================================================================================================
  32. Package Arch Version Repository Size
  33. ===========================================================================================================
  34. Installing:
  35. dos2unix x86_64 6.0.3-4.el7 base 58 k
  36. Transaction Summary
  37. ===========================================================================================================
  38. Install 1 Package
  39. Total download size: 58 k
  40. Installed size: 175 k
  41. Is this ok [y/d/N]: d
  42. Background downloading packages, then exiting:
  43. exiting because "Download Only" specified

指定下载目录:-- downloadonly --downloaddir=/tmp/

  1. [root@localhost packages]# yum install zsh --downloadonly --downloaddir=/tmp
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. Resolving Dependencies
  5. --> Running transaction check
  6. ---> Package zsh.x86_64 0:5.0.2-7.el7 will be installed
  7. --> Finished Dependency Resolution
  8. Dependencies Resolved
  9. =====================================================================================================================================
  10. Package Arch Version Repository Size
  11. =====================================================================================================================================
  12. Installing:
  13. zsh x86_64 5.0.2-7.el7 base 2.4 M
  14. Transaction Summary
  15. =====================================================================================================================================
  16. Install 1 Package
  17. Total download size: 2.4 M
  18. Installed size: 5.6 M
  19. Background downloading packages, then exiting:
  20. exiting because "Download Only" specified

如果下载已经安装过的rpm包会提示已经安装,不会重新安装。除了卸载已经安装的包重新下载外还有一个方法:yum reinstall

  1. [root@localhost packages]# yum install -y dos2unix
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. Package dos2unix-6.0.3-4.el7.x86_64 already installed and latest version
  5. Nothing to do
  6. [root@localhost packages]# yum reinstall -y dos2unix
  7. Loaded plugins: fastestmirror
  8. Loading mirror speeds from cached hostfile
  9. Resolving Dependencies
  10. --> Running transaction check
  11. ---> Package dos2unix.x86_64 0:6.0.3-4.el7 will be reinstalled
  12. --> Finished Dependency Resolution
  13. Dependencies Resolved
  14. =====================================================================================================================================
  15. Package Arch Version Repository Size
  16. =====================================================================================================================================
  17. Reinstalling:
  18. dos2unix x86_64 6.0.3-4.el7 base 58 k
  19. Transaction Summary
  20. =====================================================================================================================================
  21. Reinstall 1 Package
  22. Total download size: 58 k
  23. Installed size: 175 k
  24. Downloading packages:
  25. Running transaction check
  26. Running transaction test
  27. Transaction test succeeded
  28. Running transaction
  29. Installing : dos2unix-6.0.3-4.el7.x86_64 1/1
  30. Verifying : dos2unix-6.0.3-4.el7.x86_64 1/1
  31. Installed:
  32. dos2unix.x86_64 0:6.0.3-4.el7
  33. Complete!

八、源码代包安装

约定:源码包下载好后放到/usr/local/src/下

下载nginx包

  1. [root@localhost src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
  2. --2018-05-30 02:58:08-- http://nginx.org/download/nginx-1.14.0.tar.gz
  3. Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2606:7100:1:69::3f, ...
  4. Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
  5. HTTP request sent, awaiting response... 200 OK
  6. Length: 1016272 (992K) [application/octet-stream]
  7. Saving to: nginx-1.14.0.tar.gz
  8. 100%[===========================================================================================>] 1,016,272 56.2KB/s in 29s
  9. 2018-05-30 02:58:38 (34.6 KB/s) - nginx-1.14.0.tar.gz saved [1016272/1016272]

解压源码包

  1. [root@localhost src]# tar -xvf nginx-1.14.0.tar.gz

安装所需的依赖

  1. [root@localhost src]# yum -y install pcre.x86_64 pcre-devel.x86_64
  2. [root@localhost yum.repos.d]# yum -y install openssl openssl-devel

新建nginx安装目录以及nginx用户

  1. [root@localhost src]# cd nginx-1.14.0
  2. [root@localhost nginx-1.14.0]# mkdir -p /application/nginx-1.14
  3. [root@localhost nginx-1.14.0]# useradd nginx -M -s /sbin/nologin

配置选项

  1. [root@localhost nginx-1.14.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.14/ --with-http_stub_status_module --with-http_ssl_module

编译、安装

  1. [root@localhost nginx-1.14.0]# make && make install
  2. [root@localhost nginx-1.14.0]# ln -s /application/nginx-1.14/ /application/nginx
  3. [root@localhost nginx-1.14.0]# ll /application/
  4. total 0
  5. lrwxrwxrwx 1 root root 24 May 30 03:34 nginx -> /application/nginx-1.14/
  6. drwxr-xr-x 6 root root 50 May 30 03:33 nginx-1.14

启动nginx

  1. [root@localhost ~]# /application/nginx/sbin/nginx
  2. [root@localhost ~]# netstat -nltup | grep :80
  3. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10928/nginx: master
  4. [root@localhost ~]# curl 127.0.0.1
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <title>Welcome to nginx!</title>
  9. <style>
  10. body {
  11. width: 35em;
  12. margin: 0 auto;
  13. font-family: Tahoma, Verdana, Arial, sans-serif;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <h1>Welcome to nginx!</h1>
  19. <p>If you see this page, the nginx web server is successfully installed and
  20. working. Further configuration is required.</p>
  21. <p>For online documentation and support please refer to
  22. <a href="http://nginx.org/">nginx.org</a>.<br/>
  23. Commercial support is available at
  24. <a href="http://nginx.com/">nginx.com</a>.</p>
  25. <p><em>Thank you for using nginx.</em></p>
  26. </body>
  27. </html>

九、扩展

搭建一个局域网http的yum源

创建rpm包存放目录

  1. [root@localhost ~]# mkdir -p /data/yumdata

拷贝ISO镜像文件中的rpm包到/data/yumdata/

  1. root@localhost ~]# cp /mnt/cdrom/Packages/*.rpm /data/yumdata/

创建repository

  1. [root@localhost ~]# createrepo /data/yumdata/
  2. Spawning worker 0 with 1769 pkgs
  3. Spawning worker 1 with 1769 pkgs
  4. Workers Finished
  5. Saving Primary metadata
  6. Saving file lists metadata
  7. Saving other metadata
  8. Generating sqlite DBs
  9. Sqlite DBs complete

如果rpm包有增加,可执行

  1. createrepo --update /data/yumdata/

利用第八节编译安装的nginx提供http服务

修改nginx的配置文件

  1. [root@localhost ~]# vim /application/nginx-1.14/conf/nginx.conf
  2. 35 server {
  3. 36 listen 80;
  4. 37 server_name localhost;
  5. 38 root /data/yumdata;
  6. 39 #charset koi8-r;
  7. 40
  8. 41 #access_log logs/host.access.log main;
  9. 42
  10. 43 location / {
  11. 44 autoindex on;
  12. 45 }
  13. 46
  14. 47
  15. 48 #error_page 404 /404.html;
  16. 49
  17. 50 # redirect server error pages to the static page /50x.html
  18. 51 #
  19. 52 error_page 500 502 503 504 /50x.html;
  20. 53 location = /50x.html {
  21. 54 root html;
  22. 55 }
  23. [root@localhost ~]# /application/nginx/sbin/nginx -t
  24. nginx: the configuration file /application/nginx-1.14//conf/nginx.conf syntax is ok
  25. nginx: configuration file /application/nginx-1.14//conf/nginx.conf test is successful

重载nginx配置文件

  1. [root@localhost ~]# /application/nginx/sbin/nginx -s reload

客户端上配置repo文件

  1. [root@localhost ~]# cd /etc/yum.repos.d/
  2. [root@localhost yum.repos.d]# mkdir bak
  3. [root@localhost yum.repos.d]# mv CentOS* bak/
  4. [root@localhost yum.repos.d]# mv epel* bak/
  5. [root@localhost yum.repos.d]# vim my.repo
  6. 1 [hjm]
  7. 2 name=myserver
  8. 3 baseurl=http://192.168.1.6
  9. 4 gpgcheck=0
  10. 5 enabled=1
  11. [root@localhost yum.repos.d]# yum clean all
  12. Loaded plugins: fastestmirror
  13. Cleaning repos: epel hjm
  14. Cleaning up everything
  15. Cleaning up list of fastest mirrors
  16. [root@localhost yum.repos.d]# yum makecache
  17. Loaded plugins: fastestmirror
  18. hjm | 2.9 kB 00:00:00
  19. (1/3): hjm/filelists_db | 2.8 MB 00:00:00
  20. (2/3): hjm/primary_db | 2.7 MB 00:00:00
  21. (3/3): hjm/other_db | 1.1 MB 00:00:00
  22. Determining fastest mirrors
  23. Metadata Cache Created
  24. [root@localhost yum.repos.d]# yum repolist
  25. Loaded plugins: fastestmirror
  26. Loading mirror speeds from cached hostfile
  27. repo id repo name status
  28. hjm myserver 3,538
  29. repolist: 3,538

做一个镜像yum源

  1. [root@localhost yum.repos.d]# rsync -av rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages/ /data/yumdata/

当局域网的rpm库有更新时,除了服务端执行“createrepo –update /data/yumdata/”外,客户端上也需要执行

  1. yum clean all
  2. yum makecache

源代码包编译为二制包参考链接:https://jin-yang.github.io/post/linux-create-rpm-package.html

Centos下软件包管理的更多相关文章

  1. centos 系统软件包管理 yum 本地yum配置 扩展源epel rpm 清除yum缓存 yum provides "*/vim" 第十节课

    centos  系统软件包管理  yum 本地yum配置  扩展源epel  rpm  清除yum缓存  yum provides "*/vim"   第十节课 你不能保证可逆化操 ...

  2. Centos下磁盘管理的常用命令记录(如查找大文件)

    Centos下磁盘管理的常用命令记录 查看系统磁盘空间占用,使用命令: df -h 结果: 查看磁盘inode使用情况,如果inode用完了,磁盘就没法写入新的内容了: df -i 结果: 如何查找磁 ...

  3. 【Linux基础】Linux下软件包管理(rpm-deb-yast-yum)

    软件包管理是指系统中一种安装和维护软件的方法.通常软件以包的形式存储在仓库(repository)中,能满足许多人所有需要的软件. 在GNU/Linux(以下简称Linux)操作系统中,RPM和DPK ...

  4. liunx 平台下软件包管理

    RPM/DPKG 两大阵营简介 在 GNU/Linux( 以下简称 Linux) 操作系统中,RPM 和 DPKG 为最常见的两类软件包管理工具,他们分别应用于基于 RPM 软件包的 Linux 发行 ...

  5. debian下软件包管理方式总结

    linux最流行的包管理方式除了rpm之外就是debian的deb格式了.目前采用deb管理方式的主流操作系统主要有debian和ubuntu系列.和rpm包管理方式不同的是,虽然debian也有包含 ...

  6. linux下软件包管理

    挂载光盘:mkdir /mnt/cdrommount /dev/cdrom  /mnt/cdrom 1.rpm包管理1.安装一个包  rpm –ivh < rpm package name> ...

  7. CentOS下Python管理

    一.升级Python 查看系统版本 cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 查看Python版本 python -V ...

  8. Mac下软件包管理器-homebrew

    类似于redhat系统的yum,ubuntu的apt-get,mac系统下也有相应的包管理容器:homebrew.用法与apt-get.yum大同小异,都是对安装软件做一些安装删除类的命令行操作,以下 ...

  9. Centos下磁盘管理---分区

        1.磁盘分区格式说明 linux分区不同于windows,linux下硬盘设备名为(IDE硬盘为hdx(x为从a—d)因为IDE硬盘最多四个,SCSI,SATA,USB硬盘为sdx(x为a—z ...

随机推荐

  1. Subverion仓库迁移知识点整理

    目录 dump远程仓库内容到本地 可能碰到的问题 将dumpFile导入到本地仓库 可能碰到的问题 如何获取控制台信息 最近在工作上提出了一个需求,需要将各个团队的Subversion仓库进行集中管理 ...

  2. MySQL数据的导出和导入

    MySQL环境变量设置,将%MySQL_HOME%下的MySQL Server 5.1/bin放到Path下. MySQL的mysqldump工具,基本用法是:   shell> mysqldu ...

  3. 牛客网 完数VS盈数

    题目链接:https://www.nowcoder.com/practice/ccc3d1e78014486fb7eed3c50e05c99d?tpId=40&tqId=21351&t ...

  4. Python 新式类与经典类

    新式类,经典类 查询匹配 广度查询 横着对每个类进行查询 深度查询 无视平级类,直接寻找下级类 #python 3.0 #新式类 广度查询 #经典类 广度查询 #python 2.0 #新式类 广度查 ...

  5. Python Mysql 交互

    Mysql 安装Python模块   Linux: yum install MySQL-python Windos: http://files.cnblogs.com/files/wupeiqi/py ...

  6. Link-Cut-Tree详解

    图片参考YangZhe的论文,FlashHu大佬的博客 Link-Cut-Tree实际靠的是实链剖分,重链剖分和长链剖分珂以参考树链剖分详解 Link-Cut-Tree将某一个儿子的连边划分为实边,而 ...

  7. Python爬虫——你们要的王者荣耀高清图

    曾经144区的王者 学了计算机后 头发逐渐从李白变成了达摩 秀发有何用,变秃亦变强 (emmm徒弟说李白比达摩强,变秃不一定变强) 前言 前几天开了农药的安装包,发现农药是.Net实现的游戏 虽然游戏 ...

  8. IOS面试题2018/11/17

    1.设计模式是什么?你知道哪些设计模式? 设计模式是一种编码经验,就是一种成熟的逻辑去处理某一种类型的事情. 1.MVC模式:model view controller,把模型,视图,控制器 层进行解 ...

  9. 08.vue中样式-class

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Hbasewindows系统下启动报错及解决办法

    今天在本地windows电脑上,装pinpoint时,需要先安装一个Hbase数据库,按照教程下载启动Hbase数据库时,却启动报错:java.io.IOException: Could not lo ...