目录
一、安装软件包的三种方法
二、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文件
挂载光盘
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/sr0 /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
RPM包所在位置
[root@localhost ~]# ls /mnt/cdrom/Packages/ | head -n 5
389-ds-base-1.3.1.6-25.el7.x86_64.rpm
389-ds-base-libs-1.3.1.6-25.el7.x86_64.rpm
abattis-cantarell-fonts-0.0.12-3.el7.noarch.rpm
abrt-2.1.11-12.el7.centos.x86_64.rpm
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包安装
[root@localhost Packages]# rpm -ivh dos2unix-6.0.3-4.el7.x86_64.rpm
warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:dos2unix-6.0.3-4.el7 ################################# [100%]
升级安装rpm包
[root@localhost Packages]# rpm -Uvh dos2unix-6.0.3-4.el7.x86_64.rpm
warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
package dos2unix-6.0.3-4.el7.x86_64 is already installed
卸载软件包
[root@localhost Packages]# rpm -e dos2unix
[root@localhost Packages]# rpm -q dos2unix
package dos2unix is not installed
查询软件包
[root@localhost Packages]# rpm -q vim-enhanced
vim-enhanced-7.4.160-1.el7.x86_64
查询已安装包信息
[root@localhost Packages]# rpm -qi dos2unix
Name : dos2unix
Version : 6.0.3
Release : 4.el7
Architecture: x86_64
Install Date: Tue 29 May 2018 09:25:04 PM EDT
Group : Applications/Text
Size : 178697
License : BSD
Signature : RSA/SHA256, Thu 03 Jul 2014 09:09:30 PM EDT, Key ID 24c6a8a7f4a80eb5
Source RPM : dos2unix-6.0.3-4.el7.src.rpm
Build Date : Mon 09 Jun 2014 06:00:48 PM EDT
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://waterlan.home.xs4all.nl/dos2unix.html
Summary : Text file format converters
Description :
Convert text files with DOS or Mac line endings to Unix line endings and
vice versa.
列出一个rpm包安装的文件
[root@localhost Packages]# rpm -ql dos2unix
/usr/bin/dos2unix
/usr/bin/mac2unix
/usr/bin/unix2dos
/usr/bin/unix2mac
/usr/share/doc/dos2unix-6.0.3
/usr/share/doc/dos2unix-6.0.3/COPYING.txt
/usr/share/doc/dos2unix-6.0.3/ChangeLog.txt
/usr/share/doc/dos2unix-6.0.3/NEWS.txt
/usr/share/doc/dos2unix-6.0.3/README.txt
/usr/share/doc/dos2unix-6.0.3/TODO.txt
/usr/share/doc/dos2unix-6.0.3/dos2unix.htm
/usr/share/locale/de/LC_MESSAGES/dos2unix.mo
/usr/share/locale/eo/LC_MESSAGES/dos2unix.mo
/usr/share/locale/es/LC_MESSAGES/dos2unix.mo
/usr/share/locale/nl/LC_MESSAGES/dos2unix.mo
/usr/share/man/es/man1/dos2unix.1.gz
/usr/share/man/es/man1/mac2unix.1.gz
/usr/share/man/es/man1/unix2dos.1.gz
/usr/share/man/es/man1/unix2mac.1.gz
/usr/share/man/man1/dos2unix.1.gz
/usr/share/man/man1/mac2unix.1.gz
/usr/share/man/man1/unix2dos.1.gz
/usr/share/man/man1/unix2mac.1.gz
/usr/share/man/nl/man1/dos2unix.1.gz
/usr/share/man/nl/man1/mac2unix.1.gz
/usr/share/man/nl/man1/unix2dos.1.gz
/usr/share/man/nl/man1/unix2mac.1.gz
查看命令由哪个包安装而来
[root@localhost Packages]# rpm -qf /usr/sbin/ifconfig
net-tools-2.0-0.17.20131004git.el7.x86_64
//常见用法,用反引号取命令的绝对路径
[root@localhost Packages]# rpm -qf `which ifconfig`
net-tools-2.0-0.17.20131004git.el7.x86_64
//推荐做法
[root@localhost Packages]# rpm -qf $(which ifconfig)
net-tools-2.0-0.17.20131004git.el7.x86_64
查看文档安装位置
[root@localhost Packages]# rpm -qd dos2unix
/usr/share/doc/dos2unix-6.0.3/COPYING.txt
/usr/share/doc/dos2unix-6.0.3/ChangeLog.txt
/usr/share/doc/dos2unix-6.0.3/NEWS.txt
/usr/share/doc/dos2unix-6.0.3/README.txt
/usr/share/doc/dos2unix-6.0.3/TODO.txt
/usr/share/doc/dos2unix-6.0.3/dos2unix.htm
/usr/share/man/es/man1/dos2unix.1.gz
/usr/share/man/es/man1/mac2unix.1.gz
/usr/share/man/es/man1/unix2dos.1.gz
/usr/share/man/es/man1/unix2mac.1.gz
/usr/share/man/man1/dos2unix.1.gz
/usr/share/man/man1/mac2unix.1.gz
/usr/share/man/man1/unix2dos.1.gz
/usr/share/man/man1/unix2mac.1.gz
/usr/share/man/nl/man1/dos2unix.1.gz
/usr/share/man/nl/man1/mac2unix.1.gz
/usr/share/man/nl/man1/unix2dos.1.gz
/usr/share/man/nl/man1/unix2mac.1.gz
查看未安装rpm包的信息
[root@localhost Packages]# rpm -q dos2unix-6.0.3-4.el7.x86_64.rpm
package dos2unix-6.0.3-4.el7.x86_64.rpm is not installed
//查看未安装rpm包的信息
[root@localhost Packages]# rpm -qpi dos2unix-6.0.3-4.el7.x86_64.rpm
warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Name : dos2unix
Version : 6.0.3
Release : 4.el7
Architecture: x86_64
Install Date: (not installed)
Group : Applications/Text
Size : 178697
License : BSD
Signature : RSA/SHA256, Thu 03 Jul 2014 09:09:30 PM EDT, Key ID 24c6a8a7f4a80eb5
Source RPM : dos2unix-6.0.3-4.el7.src.rpm
Build Date : Mon 09 Jun 2014 06:00:48 PM EDT
Build Host : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem <http://bugs.centos.org>
Vendor : CentOS
URL : http://waterlan.home.xs4all.nl/dos2unix.html
Summary : Text file format converters
Description :
Convert text files with DOS or Mac line endings to Unix line endings and
vice versa.
查看未安装rpm包将要安装哪些文件
[root@localhost Packages]# rpm -qpl dos2unix-6.0.3-4.el7.x86_64.rpm
warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
/usr/bin/dos2unix
/usr/bin/mac2unix
/usr/bin/unix2dos
/usr/bin/unix2mac
/usr/share/doc/dos2unix-6.0.3
/usr/share/doc/dos2unix-6.0.3/COPYING.txt
/usr/share/doc/dos2unix-6.0.3/ChangeLog.txt
/usr/share/doc/dos2unix-6.0.3/NEWS.txt
/usr/share/doc/dos2unix-6.0.3/README.txt
/usr/share/doc/dos2unix-6.0.3/TODO.txt
/usr/share/doc/dos2unix-6.0.3/dos2unix.htm
/usr/share/locale/de/LC_MESSAGES/dos2unix.mo
/usr/share/locale/eo/LC_MESSAGES/dos2unix.mo
/usr/share/locale/es/LC_MESSAGES/dos2unix.mo
/usr/share/locale/nl/LC_MESSAGES/dos2unix.mo
/usr/share/man/es/man1/dos2unix.1.gz
/usr/share/man/es/man1/mac2unix.1.gz
/usr/share/man/es/man1/unix2dos.1.gz
/usr/share/man/es/man1/unix2mac.1.gz
/usr/share/man/man1/dos2unix.1.gz
/usr/share/man/man1/mac2unix.1.gz
/usr/share/man/man1/unix2dos.1.gz
/usr/share/man/man1/unix2mac.1.gz
/usr/share/man/nl/man1/dos2unix.1.gz
/usr/share/man/nl/man1/mac2unix.1.gz
/usr/share/man/nl/man1/unix2dos.1.gz
/usr/share/man/nl/man1/unix2mac.1.gz
查看软件包的依赖关系
[root@localhost Packages]# rpm -qpR dos2unix-6.0.3-4.el7.x86_64.rpm
warning: dos2unix-6.0.3-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
libc.so.6()(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
libc.so.6(GLIBC_2.4)(64bit)
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)
rpmlib(PayloadIsXz) <= 5.2-1
升级或安装rpm包时不检查依赖关系
[root@localhost Packages]# rpm -ivh wireshark-1.10.3-10.el7.x86_64.rpm
warning: wireshark-1.10.3-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
libcares.so.2()(64bit) is needed by wireshark-1.10.3-10.el7.x86_64
libsmi.so.2()(64bit) is needed by wireshark-1.10.3-10.el7.x86_64
[root@localhost Packages]# rpm -ivh --nodeps wireshark-1.10.3-10.el7.x86_64.rpm
warning: wireshark-1.10.3-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:wireshark-1.10.3-10.el7 ################################# [100%]
[root@localhost Packages]# rpm -q wireshark
wireshark-1.10.3-10.el7.x86_64
不真正安装rpm包,检测并报告可能的冲突
[root@localhost Packages]# rpm -ivh --test wireshark-1.10.3-10.el7.x86_64.rpm
warning: wireshark-1.10.3-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
libcares.so.2()(64bit) is needed by wireshark-1.10.3-10.el7.x86_64
libsmi.so.2()(64bit) is needed by wireshark-1.10.3-10.el7.x86_64
四、YUM工具用法
软件包安装
//-y 自动应答
[root@localhost yum.repos.d]# yum -y install dos2unix
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package dos2unix.x86_64 0:6.0.3-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================
Installing:
dos2unix x86_64 6.0.3-4.el7 base 58 k
Transaction Summary
=====================================================================================================================================
Install 1 Package
Total download size: 58 k
Installed size: 175 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : dos2unix-6.0.3-4.el7.x86_64 1/1
Verifying : dos2unix-6.0.3-4.el7.x86_64 1/1
Installed:
dos2unix.x86_64 0:6.0.3-4.el7
Complete!
列出可用安装包
//推荐用grep过滤,否则会导致出现的结果过多,不方便查看
[root@localhost yum.repos.d]# yum list | grep dos2unix
dos2unix.x86_64 6.0.3-4.el7 @base
卸载软件包
//不建议加上-y选项自动应答,因为yum工具卸载会自动卸载依赖关系。
[root@localhost yum.repos.d]# yum remove dos2unix
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package dos2unix.x86_64 0:6.0.3-4.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================
Removing:
dos2unix x86_64 6.0.3-4.el7 @base 175 k
Transaction Summary
=====================================================================================================================================
Remove 1 Package
Installed size: 175 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : dos2unix-6.0.3-4.el7.x86_64 1/1
Verifying : dos2unix-6.0.3-4.el7.x86_64 1/1
Removed:
dos2unix.x86_64 0:6.0.3-4.el7
Complete!
查看软件包信息
[root@localhost yum.repos.d]# yum info dos2unix
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name : dos2unix
Arch : x86_64
Version : 6.0.3
Release : 4.el7
Size : 58 k
Repo : base
Summary : Text file format converters
URL : http://waterlan.home.xs4all.nl/dos2unix.html
License : BSD
Description : Convert text files with DOS or Mac line endings to Unix line endings and
: vice versa.
查询某件文件的提供包
[root@localhost yum.repos.d]# yum provides /usr/bin/dos2unix
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
dos2unix-6.0.3-4.el7.x86_64 : Text file format converters
Repo : base
Matched from:
Filename : /usr/bin/dos2unix
dos2unix-6.0.3-4.el7.x86_64 : Text file format converters
Repo : @base
Matched from:
Filename : /usr/bin/dos2unix
清除缓存信息
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base
Cleaning up everything
Cleaning up list of fastest mirrors
生成缓存信息
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
(1/4): base/group_gz | 157 kB 00:00:00
(2/4): base/filelists_db | 2.8 MB 00:00:00
(3/4): base/primary_db | 2.7 MB 00:00:00
(4/4): base/other_db | 1.1 MB 00:00:00
Determining fastest mirrors
Metadata Cache Created
五、YUM搭建本地仓库
虚拟机加载Centos7操作系统ISO镜像文件
挂载光盘
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/sr0 /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only
备份原Repo文件
[root@localhost Packages]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# find . -type f -exec mv {} {}.bak \;
[root@localhost yum.repos.d]# cp CentOS-Base.repo.bak CentOS-Media.repo
[root@localhost yum.repos.d]# vim CentOS-Media.repo
//修改为以下内容
1 # CentOS-Media.repo
2 [base]
3 name=CentOS-$releasever - Base
4 baseurl=file:///mnt/cdrom
5 gpgcheck=0
6 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
7
清理缓存
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base
Cleaning up everything
Cleaning up list of fastest mirrors
生成新缓存
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
(1/4): base/group_gz | 157 kB 00:00:00
(2/4): base/filelists_db | 2.8 MB 00:00:00
(3/4): base/primary_db | 2.7 MB 00:00:00
(4/4): base/other_db | 1.1 MB 00:00:00
Determining fastest mirrors
Metadata Cache Created
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
base CentOS-7 - Base 3,538
repolist: 3,538
六、yum更换国内源
备份原始源CentOS-Base.repo
[root@localhost Packages]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# find . -type f -exec mv {} {}.bak \;
添加国内源
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2018-05-30 02:52:39-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 59.111.0.251
Connecting to mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘CentOS7-Base-163.repo’
100%[===========================================================================================>] 1,572 --.-K/s in 0.03s
2018-05-30 02:52:39 (56.9 KB/s) - ‘CentOS7-Base-163.repo’ saved [1572/1572]
[root@localhost yum.repos.d]# ls
CentOS7-Base-163.repo CentOS-Base.repo.bak CentOS-Debuginfo.repo.bak CentOS-Sources.repo.bak CentOS-Vault.repo.bak
安装扩展源epel
[root@localhost yum.repos.d]# yum -y install epel-release
Loaded plugins: fastestmirror
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 147 kB 00:00:03
(2/2): updates/7/x86_64/primary_db | 2.0 MB 00:00:26
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================
Installing:
epel-release noarch 7-11 extras 15 k
Transaction Summary
=====================================================================================================================================
Install 1 Package
Total download size: 15 k
Installed size: 24 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for epel-release-7-11.noarch.rpm is not installed
epel-release-7-11.noarch.rpm | 15 kB 00:00:00
Retrieving key from http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
From : http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-11.noarch 1/1
Verifying : epel-release-7-11.noarch 1/1
Installed:
epel-release.noarch 0:7-11
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
epel/x86_64/metalink | 5.6 kB 00:00:00
epel | 4.7 kB 00:00:00
(1/3): epel/x86_64/group_gz | 88 kB 00:00:03
(2/3): epel/x86_64/updateinfo | 930 kB 00:00:08
(3/3): epel/x86_64/primary_db | 6.4 MB 00:00:30
Loading mirror speeds from cached hostfile
* epel: mirrors.tuna.tsinghua.edu.cn
repo id repo name status
base/7/x86_64 CentOS-7 - Base - 163.com 3,538
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,577
extras/7/x86_64 CentOS-7 - Extras - 163.com 305
updates/7/x86_64 CentOS-7 - Updates - 163.com 632
repolist: 17,052
七、yum下载rpm包
仅下载不安装rpm包
下载位置在:/var/cache/yum/x86_64/7/仓库名/packages/
//跟--downloadonly选项
[root@localhost yum.repos.d]# yum install zsh --downloadonly
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-7.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
zsh x86_64 5.0.2-7.el7 base 2.4 M
Transaction Summary
===========================================================================================================
Install 1 Package
Total download size: 2.4 M
Installed size: 5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified
//不跟downloadonly选项,在自动应答时选d
[root@localhost yum.repos.d]# yum install dos2unix
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package dos2unix.x86_64 0:6.0.3-4.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================
Package Arch Version Repository Size
===========================================================================================================
Installing:
dos2unix x86_64 6.0.3-4.el7 base 58 k
Transaction Summary
===========================================================================================================
Install 1 Package
Total download size: 58 k
Installed size: 175 k
Is this ok [y/d/N]: d
Background downloading packages, then exiting:
exiting because "Download Only" specified
指定下载目录:-- downloadonly --downloaddir=/tmp/
[root@localhost packages]# yum install zsh --downloadonly --downloaddir=/tmp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-7.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================
Installing:
zsh x86_64 5.0.2-7.el7 base 2.4 M
Transaction Summary
=====================================================================================================================================
Install 1 Package
Total download size: 2.4 M
Installed size: 5.6 M
Background downloading packages, then exiting:
exiting because "Download Only" specified
如果下载已经安装过的rpm包会提示已经安装,不会重新安装。除了卸载已经安装的包重新下载外还有一个方法:yum reinstall
[root@localhost packages]# yum install -y dos2unix
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package dos2unix-6.0.3-4.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost packages]# yum reinstall -y dos2unix
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package dos2unix.x86_64 0:6.0.3-4.el7 will be reinstalled
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================
Package Arch Version Repository Size
=====================================================================================================================================
Reinstalling:
dos2unix x86_64 6.0.3-4.el7 base 58 k
Transaction Summary
=====================================================================================================================================
Reinstall 1 Package
Total download size: 58 k
Installed size: 175 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : dos2unix-6.0.3-4.el7.x86_64 1/1
Verifying : dos2unix-6.0.3-4.el7.x86_64 1/1
Installed:
dos2unix.x86_64 0:6.0.3-4.el7
Complete!
八、源码代包安装
约定:源码包下载好后放到/usr/local/src/下
下载nginx包
[root@localhost src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
--2018-05-30 02:58:08-- http://nginx.org/download/nginx-1.14.0.tar.gz
Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2606:7100:1:69::3f, ...
Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1016272 (992K) [application/octet-stream]
Saving to: ‘nginx-1.14.0.tar.gz’
100%[===========================================================================================>] 1,016,272 56.2KB/s in 29s
2018-05-30 02:58:38 (34.6 KB/s) - ‘nginx-1.14.0.tar.gz’ saved [1016272/1016272]
解压源码包
[root@localhost src]# tar -xvf nginx-1.14.0.tar.gz
安装所需的依赖
[root@localhost src]# yum -y install pcre.x86_64 pcre-devel.x86_64
[root@localhost yum.repos.d]# yum -y install openssl openssl-devel
新建nginx安装目录以及nginx用户
[root@localhost src]# cd nginx-1.14.0
[root@localhost nginx-1.14.0]# mkdir -p /application/nginx-1.14
[root@localhost nginx-1.14.0]# useradd nginx -M -s /sbin/nologin
配置选项
[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
编译、安装
[root@localhost nginx-1.14.0]# make && make install
[root@localhost nginx-1.14.0]# ln -s /application/nginx-1.14/ /application/nginx
[root@localhost nginx-1.14.0]# ll /application/
total 0
lrwxrwxrwx 1 root root 24 May 30 03:34 nginx -> /application/nginx-1.14/
drwxr-xr-x 6 root root 50 May 30 03:33 nginx-1.14
启动nginx
[root@localhost ~]# /application/nginx/sbin/nginx
[root@localhost ~]# netstat -nltup | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10928/nginx: master
[root@localhost ~]# curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
九、扩展
搭建一个局域网http的yum源
创建rpm包存放目录
[root@localhost ~]# mkdir -p /data/yumdata
拷贝ISO镜像文件中的rpm包到/data/yumdata/
root@localhost ~]# cp /mnt/cdrom/Packages/*.rpm /data/yumdata/
创建repository
[root@localhost ~]# createrepo /data/yumdata/
Spawning worker 0 with 1769 pkgs
Spawning worker 1 with 1769 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
如果rpm包有增加,可执行
createrepo --update /data/yumdata/
利用第八节编译安装的nginx提供http服务
修改nginx的配置文件
[root@localhost ~]# vim /application/nginx-1.14/conf/nginx.conf
35 server {
36 listen 80;
37 server_name localhost;
38 root /data/yumdata;
39 #charset koi8-r;
40
41 #access_log logs/host.access.log main;
42
43 location / {
44 autoindex on;
45 }
46
47
48 #error_page 404 /404.html;
49
50 # redirect server error pages to the static page /50x.html
51 #
52 error_page 500 502 503 504 /50x.html;
53 location = /50x.html {
54 root html;
55 }
[root@localhost ~]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.14//conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.14//conf/nginx.conf test is successful
重载nginx配置文件
[root@localhost ~]# /application/nginx/sbin/nginx -s reload
客户端上配置repo文件
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir bak
[root@localhost yum.repos.d]# mv CentOS* bak/
[root@localhost yum.repos.d]# mv epel* bak/
[root@localhost yum.repos.d]# vim my.repo
1 [hjm]
2 name=myserver
3 baseurl=http://192.168.1.6
4 gpgcheck=0
5 enabled=1
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: epel hjm
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
hjm | 2.9 kB 00:00:00
(1/3): hjm/filelists_db | 2.8 MB 00:00:00
(2/3): hjm/primary_db | 2.7 MB 00:00:00
(3/3): hjm/other_db | 1.1 MB 00:00:00
Determining fastest mirrors
Metadata Cache Created
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
hjm myserver 3,538
repolist: 3,538
做一个镜像yum源
[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/”外,客户端上也需要执行
yum clean all
yum makecache
源代码包编译为二制包参考链接:https://jin-yang.github.io/post/linux-create-rpm-package.html