安装包类型
rpm包
可执行文件,解包后直接安装。
对应的系统:Redhat Linux、suse、centos redhat
缺点:不能指定安装路径、不能解决软件安装时的依赖性(需手动安装依赖软件)。
rpm包名称分析
例如:rpm -ivh dhcp-4.2.5-68.el7_5.1.x86_64.rpm
[1]. dhcp: 软件名称
[2]. 4.2.5-68: 软件版本
[3]. el7_5.1:软件授权,el7表示此软件在Linux7中被授权
[4]. x86_64:软件位数
[5]. rpm:软件类型
安装
安装命令:rpm -ivh rpm软件包的路径
安装过程
- 在虚拟机中添加当前系统匹配的镜像文件
- 挂载镜像到/rhel7(先新建/rhel7目录)
命令:
mount /dev/cdrom /rhel7
----操作的系统是虚拟机时执行
mount /xxxxx.iso(镜像的路径)/rhel7
—操作的系统是真实主机时执行
[root@rhel7 Packages]# mkdir /rhel7 ##新建目录rhel7作为镜像的挂载点
[root@rhel7 Packages]# df ##查看镜像位置
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/nvme0n1p2 8377344 3834600 4542744 46% /
devtmpfs 418644 0 418644 0% /dev
tmpfs 434444 76 434368 1% /dev/shm
tmpfs 434444 7964 426480 2% /run
tmpfs 434444 0 434444 0% /sys/fs/cgroup
/dev/nvme0n1p1 201380 153884 47496 77% /boot
tmpfs 86892 4 86888 1% /run/user/42
tmpfs 86892 44 86848 1% /run/user/0
/dev/sr0 4391278 4391278 0 100% /run/media/root/RHEL-7.6 Server.x86_64
[root@rhel7 Packages]# mount /dev/cdrom /rhel7
mount: /dev/sr0 is write-protected, mounting read-only
[root@rhel7 Packages]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/nvme0n1p2 8377344 3834564 4542780 46% /
devtmpfs 418644 0 418644 0% /dev
tmpfs 434444 76 434368 1% /dev/shm
tmpfs 434444 7960 426484 2% /run
tmpfs 434444 0 434444 0% /sys/fs/cgroup
/dev/nvme0n1p1 201380 153884 47496 77% /boot
tmpfs 86892 4 86888 1% /run/user/42
tmpfs 86892 44 86848 1% /run/user/0
/dev/sr0 4391278 4391278 0 100% /rhel7 ##成功挂载
- 查看rhel7目录
[root@rhel7 Packages]# ls /rhel7
addons extra_files.json isolinux Packages RPM-GPG-KEY-redhat-release
EFI GPL LiveOS repodata TRANS.TBL
EULA images media.repo RPM-GPG-KEY-redhat-beta
- 找到dhcp软件的路径,执行安装命令
[root@rhel7 Packages]# ls dhcp*
dhcp-4.2.5-68.el7_5.1.x86_64.rpm dhcp-libs-4.2.5-68.el7_5.1.i686.rpm
dhcp-common-4.2.5-68.el7_5.1.x86_64.rpm dhcp-libs-4.2.5-68.el7_5.1.x86_64.rpm
[root@rhel7 Packages]# rpm -ivh dhcp-4.2.5-68.el7_5.1.x86_64.rpm ##安装此软件
warning: dhcp-4.2.5-68.el7_5.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:dhcp-12:4.2.5-68.el7_5.1 ################################# [100%]
rpm命令的参数
rpm命令之后还可以跟一些别的参数:
命令 | 含义 |
---|---|
rpm -i | 安装软件 |
rpm -v | 显示安装过程 |
rpm -h | 检测软件中的hash值是否有改变 |
rpm -e 软件名称 | 卸载软件(不加.rpm) |
rpm -q | 查看 |
rpm -a | 所有 |
rpm -qa | 查看所有安装过的软件 |
rpm -l | 列出安装后在系统中生成的文件 |
rpm -p | 操作对象为软件包 |
rpm --scripts | 查看软件在安装或卸载时在系统中执行的脚本 |
rpm --force | 强制安装 |
rpm --nodeps | 忽略软件依赖性安装 |
rpm -K | 通过对比MD5检测软件是否为原版软件 |
举例说明--scripts
查看脚本的作用:
有两个安装软件:
FluffyMcAwesome-A-6.4.0-11.r19335.x86_64.rpm
FluffyMcAwesome-B-6.4.0-11.r19335.x86_64.rpm
通过查看安装时的脚本可以确定,我们只能使用第二个rpm文件,因为A软件的权限太大,用户权限为root,还可以执行rm -rf /*
删除根目录下的所有文件,极不安全!!
举例说明忽略依赖--nodeps
的作用:
假设系统准备安装软件kolourpaint-4.10.5-4.el7.x86_64.rpm
:
直接安装时会报依赖性错误:
若要忽略依赖关系,直接安装软件,可以加--nodeps
参数。
举例说明检测版本-K
的作用:
签名不通过,说明软件被篡改过,可以检查软件包的安全性。
卸载
rpm -e 软件名
拆解
命令:rpm2cpio 软件包名称 | cpio -id
deb包
可执行文件,解包后直接安装
对应的系统:DebianLinux
安装
dpkg -ideb 软件包名
如:dpkg ?isoftware-1.2.3-1.deb
卸载
dpkg -e 软件名
tar包
绿色软件:解压后即可使用的压缩软件。
编译软件:解压缩后需编译成可执行文件才可安装。
特点:可以指定安装路径。
下面演示tar包的用法:
首先联网下载好ntfs-3g_ntfsprogs-2017.3.23.tgz
包,然后解压这个包。
[root@rhel7 ~]# cd Downloads/
[root@rhel7 Downloads]# ls
ntfs-3g_ntfsprogs-2017.3.23.tgz
[root@rhel7 Downloads]# cp ntfs-3g_ntfsprogs-2017.3.23.tgz /mnt
[root@rhel7 Downloads]# cd /mnt/
[root@rhel7 mnt]# ls
ntfs-3g_ntfsprogs-2017.3.23.tgz
[root@rhel7 mnt]# tar zxf ntfs-3g_ntfsprogs-2017.3.23.tgz
[root@rhel7 mnt]# ls
ntfs-3g_ntfsprogs-2017.3.23 ntfs-3g_ntfsprogs-2017.3.23.tgz
[root@rhel7 mnt]# cd ntfs-3g_ntfsprogs-2017.3.23
[root@rhel7 ntfs-3g_ntfsprogs-2017.3.23]# ls
aclocal.m4 config.h.in CREDITS libntfs-3g NEWS
AUTHORS config.sub depcomp ltmain.sh ntfsprogs
autogen.sh configure include m4 README
ChangeLog configure.ac INSTALL Makefile.am src
compile COPYING install-sh Makefile.in TODO.ntfsprogs
config.guess COPYING.LIB libfuse-lite missing
[root@rhel7 ntfs-3g_ntfsprogs-2017.3.23]# less README ##查看这个tar包的用法
在README文件中的几个常用命令:
./configure
: 检测安装平台
make
:编译源码
makeinstall
: 安装软件
makeuninstall
: 卸载软件
yum软件仓库
软件仓库搭建目的:
rpm不能自动解决软件安装时的依赖关系,而yum仓库可以解决。
搭建软件仓库的步骤
1. 得到与当前系统匹配的系统安装镜像文件
2. 挂载镜像
与安装rpm包时的挂载方法相同。(查看上面的过程即可,不再重复)
3. 配置系统访问软件路径(yum指向文件)
[root@rhel7 Downloads]# cd /etc/yum.repos.d/
[root@rhel7 yum.repos.d]# ls
redhat.repo
[root@rhel7 yum.repos.d]# rm -fr *
[root@rhel7 yum.repos.d]# vim zj.repo
Linux7中
- [zjrhel7]
仓库名称 - name=zj rhel7 source
仓库描述 - baseurl=file:///rhel7
资源路径 - gpgcheck=1
软件包授权检测开关:gbgcheck=0|1 - enabled=1
仓库启动开关 - gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
软件包授权码,当gbgcheck=1时需指定。
Linux8中
假设Linux8中的镜像挂载在/rhel8目录上。
4. 清空原始yum缓存,加载新yum缓存
Linux7中
命令:yum clean all
[root@rhel7 yum.repos.d]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: zjrhel7
Linux8中
命令:dnf clean all
5. 查看仓库
Linux7中
Linux8中
6. 使用yum命令下载镜像内的软件
[root@rhel7 yum.repos.d]# yum install httpd ##安装httpd
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
zjrhel7 | 4.3 kB 00:00:00
(1/2): zjrhel7/group_gz | 146 kB 00:00:00
(2/2): zjrhel7/primary_db | 4.2 MB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-88.el7 for package: httpd-2.4.6-88.el7.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-88.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-88.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-88.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-88.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Installing:
httpd x86_64 2.4.6-88.el7 zjrhel7 1.2 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7_4.1 zjrhel7 103 k
apr-util x86_64 1.5.2-6.el7 zjrhel7 92 k
httpd-tools x86_64 2.4.6-88.el7 zjrhel7 90 k
mailcap noarch 2.1.41-2.el7 zjrhel7 31 k
Transaction Summary
========================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 1.5 M
Installed size: 4.3 M
Is this ok [y/d/N]: y ##y
Downloading packages:
warning: /rhel7/Packages/apr-1.4.8-3.el7_4.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
Public key for apr-1.4.8-3.el7_4.1.x86_64.rpm is not installed
--------------------------------------------------------------------------------------------------------
Total 5.7 MB/s | 1.5 MB 00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Importing GPG key 0xFD431D51:
Userid : "Red Hat, Inc. (release key 2) <security@redhat.com>"
Fingerprint: 567e 347a d004 4ade 55ba 8a5f 199e 2f91 fd43 1d51
Package : redhat-release-server-7.6-4.el7.x86_64 (@anaconda/7.6)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Is this ok [y/N]: y ##y
Importing GPG key 0x2FA658E0:
Userid : "Red Hat, Inc. (auxiliary key) <security@redhat.com>"
Fingerprint: 43a6 e49c 4a38 f4be 9abf 2a53 4568 9c88 2fa6 58e0
Package : redhat-release-server-7.6-4.el7.x86_64 (@anaconda/7.6)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
Is this ok [y/N]: y ##y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : apr-1.4.8-3.el7_4.1.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-88.el7.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-88.el7.x86_64 5/5
zjrhel7/productid | 1.6 kB 00:00:00
Verifying : mailcap-2.1.41-2.el7.noarch 1/5
Verifying : httpd-2.4.6-88.el7.x86_64 2/5
Verifying : apr-1.4.8-3.el7_4.1.x86_64 3/5
Verifying : apr-util-1.5.2-6.el7.x86_64 4/5
Verifying : httpd-tools-2.4.6-88.el7.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-88.el7
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-88.el7
mailcap.noarch 0:2.1.41-2.el7
Complete!
yum命令
仅管理rpm类型的软件。
命令 | 含义 |
---|---|
yum install | 安装软件 |
yum remove | 卸载软件 |
yum reinstall | 重新安装 |
yum list all/installed/available/软件名称 | 列出 |
yum update | 更新 |
yum repolist | 列出仓库信息 |
yum history | 查看yum历史 |
yum info 软件 | 查看软件包信息 |
yum clean all | 清除yum缓存 |
yum search | 根据软件信息搜索 |
yum whatprovides | 根据软件包文件搜索 |
yum groups install | 组安装 |
yum groups remove | 组卸载 |
yum groups info | 组信息 |
第三方软件仓库
第三方软件:不在镜像中,须在网上下载的软件。
加入要安装画图软件:kolourpaint
- 把待安装的、rpm结尾的软件包存放到一个目录
/software
中
[root@rhel7 yum.repos.d]# mkdir /software ##创建目录
[root@rhel7 yum.repos.d]# mv /root/Downloads/kolourpaint-* /software
[root@rhel7 yum.repos.d]# cd /software/
[root@rhel7 software]# ls
kolourpaint-4.10.5-4.el7.x86_64.rpm kolourpaint-libs-4.10.5-4.el7.x86_64.rpm
- 生成软件数据库存放软件属性
命令:createrepo -v /software
注意:第三方软件目录必须生成软件数据库,否则找不到该目录对应的repomd.xml
无法正常执行yum命令。
[root@rhel7 software]# createrepo -v /software
Spawning worker 0 with 2 pkgs
Worker 0: reading kolourpaint-4.10.5-4.el7.x86_64.rpm
Worker 0: reading kolourpaint-libs-4.10.5-4.el7.x86_64.rpm
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Starting other db creation: Tue Feb 18 22:18:13 2020
Ending other db creation: Tue Feb 18 22:18:13 2020
Starting filelists db creation: Tue Feb 18 22:18:13 2020
Ending filelists db creation: Tue Feb 18 22:18:13 2020
Starting primary db creation: Tue Feb 18 22:18:13 2020
Ending primary db creation: Tue Feb 18 22:18:13 2020
Sqlite DBs complete
- 配置文件
[root@rhel7 software]# vim /etc/yum.repos.d/software.repo
- 清空原始yum缓存,加载新yum缓存
[root@rhel7 software]# yum clean all
- 用yum查看第三方软件
[root@rhel7 repodata]# yum search kolourpaint
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
software | 2.9 kB 00:00:00
zjrhel7 | 4.3 kB 00:00:00
(1/3): software/primary_db | 3.9 kB 00:00:00
(2/3): zjrhel7/group_gz | 146 kB 00:00:00
(3/3): zjrhel7/primary_db | 4.2 MB 00:00:00
======================================= N/S matched: kolourpaint =======================================
kolourpaint-libs.x86_64 : Runtime libraries for kolourpaint
kolourpaint.x86_64 : An easy-to-use paint program
Name and summary matches only, use "search all" for everything.
- 安装第三方软件
[root@rhel7 repodata]# yum install kolourpaint.x86_64
共享软件仓库
软件仓库支持的访问方式
file://
:本地文件
ftp://
:文本传输协议
http://
:超文本传输协议
nfs://
:网络文件系统
搭建共享软件仓库
1. 在含有软件资源的主机中安装共享软件ftp
命令:
yum install vsftpd -y
systemctl start vsftpd
systemctl enable vsftpd
由于ftp软件在镜像中,所以要安装此软件,需要先搭建好镜像的软件仓库,否则执行yum install vsftpd -y
命令会报错:
[root@rhel7 ~]# yum install vsftpd -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
file:///rhel7/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /rhel7/repodata/repomd.xml"
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-25.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
vsftpd x86_64 3.0.2-25.el7 zjrhel7 171 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 171 k
Installed size: 353 k
Downloading packages:
Error downloading packages:
vsftpd-3.0.2-25.el7.x86_64: [Errno 256] No more mirrors to try. ##无镜像
搭建软件仓库的步骤可以参考本篇博客yum软件仓库中的内容。挂载好镜像后,安装ftp:
[root@rhel7 yum.repos.d]# yum install vsftpd -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
zjrhel7 | 4.3 kB 00:00
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-25.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
vsftpd x86_64 3.0.2-25.el7 zjrhel7 171 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 171 k
Installed size: 353 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-25.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-25.el7.x86_64 1/1
Installed:
vsftpd.x86_64 0:3.0.2-25.el7
Complete!
[root@rhel7 yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repo id repo name status
software software 2
zjrhel7 zj rhel7 source 5,152
repolist: 5,154
[root@rhel7 yum.repos.d]# systemctl start vsftpd
[root@rhel7 yum.repos.d]# systemctl enable vsftpd
2. 关闭selinux和firewalld
关闭selinux
- 查询selinux状态
命令:getenforce
- 编辑配置文件
配置文件位置:/etc/sysconfig/selinux
- 重启系统
命令:reboot
关闭firewalld
命令:
systemctl stop firewalld
systemctl disable firewalld
此时,其他主机可以访问这个虚拟机的ftp文件
3. 建立共享目录
[root@rhel7 ftp]# mkdir /var/ftp/rhel7 /var/ftp/software
4. 在共享目录中存放软件资源
把所有第三方软件放入/var/ftp/software
[root@rhel7 ftp]# ls /software
kolourpaint-4.10.5-4.el7.x86_64.rpm repodata
kolourpaint-libs-4.10.5-4.el7.x86_64.rpm
[root@rhel7 software]# cp /software/* /var/ftp/software/
cp: omitting directory ‘/software/repodata’
[root@rhel7 software]# ls
kolourpaint-4.10.5-4.el7.x86_64.rpm repodata
kolourpaint-libs-4.10.5-4.el7.x86_64.rpm
生成软件数据库存放软件属性(不能忘记!!!)
执行createrepo -v /var/ftp/software
[root@rhel7 software]# createrepo -v /var/ftp/software
Spawning worker 0 with 2 pkgs
Worker 0: reading kolourpaint-4.10.5-4.el7.x86_64.rpm
Worker 0: reading kolourpaint-libs-4.10.5-4.el7.x86_64.rpm
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Starting other db creation: Wed Feb 19 15:15:45 2020
Ending other db creation: Wed Feb 19 15:15:45 2020
Starting filelists db creation: Wed Feb 19 15:15:45 2020
Ending filelists db creation: Wed Feb 19 15:15:45 2020
Starting primary db creation: Wed Feb 19 15:15:45 2020
Ending primary db creation: Wed Feb 19 15:15:45 2020
Sqlite DBs complete
挂载镜像
临时挂载(重启消失)
命令:mount /dev/cdrom /var/ftp/rhel7
永久挂载
- 编辑配置文件:
/etc/rc.d/rc.local
- 由于配置文件中的语句需执行,因此增加配置文件的执行权限
[root@rhel7 software]# ls -l /etc/rc.d/rc.local
-rw-r--r-- 1 root root 505 Feb 19 15:14 /etc/rc.d/rc.local
[root@rhel7 software]# chmod 755 /etc/rc.d/rc.local ##增加权限
[root@rhel7 software]# ls -l /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 505 Feb 19 15:14 /etc/rc.d/rc.local
[root@rhel7 software]# /etc/rc.d/rc.local ##执行配置文件,挂载镜像
mount: /dev/sr0 is write-protected, mounting read-only
[root@rhel7 software]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/nvme0n1p2 8377344 4397792 3979552 53% /
devtmpfs 418644 0 418644 0% /dev
tmpfs 434444 0 434444 0% /dev/shm
tmpfs 434444 7936 426508 2% /run
tmpfs 434444 0 434444 0% /sys/fs/cgroup
/dev/nvme0n1p1 201380 153884 47496 77% /boot
tmpfs 86892 4 86888 1% /run/user/42
tmpfs 86892 28 86864 1% /run/user/0
/dev/sr0 4391278 4391278 0 100% /var/ftp/rhel7 ##成功挂载
5. 共享文件
- 在另一台虚拟机(linux7_clone3)中查看资源
- 搭建待下载虚拟机的仓库
- 编辑配置文件:
/etc/yum.repos.d/zj.repo
其中:
ftp://192.168.1.188/rhel7
中为镜像中软件包的下载路径;
ftp://192.168.1.188/software
中为第三方软件包的下载路径。
- 清空原始yum缓存,加载新yum缓存
[root@rhel7_clone3 ~]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: rhel7 software
- 下载软件
- 下载镜像中的软件
[root@rhel7_clone3 ~]# yum install dhcp -y
- 下载rhel7虚拟机中已有的第三方软件
[root@rhel7_clone3 ~]# yum install kolourpaint.x86_64 -y
均可成功下载,但不需要在thel7_clone3中挂载镜像,即可以使rhel7和rhel7_clone3之间共享所有的软件。