rpm:在 Linux 操作系统下,几乎所有的软件均通过RPM 进行安装、卸载及管理等操作。
-qa:查询已经安装的所有包
-qi:查询已经安装软件的包信息和版本
-ql:已经安装装软件包的配置文件
[root@localhost python]# rpm -qa | grep man
man-1.6f-32.el6.x86_64
man-pages-3.22-20.el6.noarch
pixman-0.32.4-4.el6.x86_64
crash-gcore-command-1.0-5.el6.x86_64
libsemanage-2.0.43-4.2.el6.x86_64
gnome-power-manager-2.28.3-7.el6_4.x86_64
man-pages-overrides-6.6.3-2.el6.noarch
erlang-pman-R14B-04.3.el6.x86_64
crash-trace-command-1.0-5.el6.x86_64
[root@localhost python]# rpm -qi man
Name : man Relocations: (not relocatable)
Version : 1.6f Vendor: CentOS
Release : 32.el6 Build Date: Fri 22 Feb 2013 10:13:10 AM CST
Install Date: Wed 19 Jul 2017 06:15:20 PM CST Build Host: c6b9.bsys.dev.centos.org
Group : System Environment/Base Source RPM: man-1.6f-32.el6.src.rpm
Size : 398388 License: GPLv2
Signature : RSA/SHA1, Sun 24 Feb 2013 01:39:26 AM CST, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem <http://bugs.centos.org>
URL : http://primates.ximian.com/~flucifredi/man/
Summary : A set of documentation tools: man, apropos and whatis
[root@localhost python]# rpm -qi mysql-sever
package mysql-sever is not installed
[root@localhost python]# rpm -ql man | more
/etc/cron.daily/makewhatis.cron
/etc/man.config
/usr/bin/apropos
/usr/bin/man
/usr/bin/man2html
/usr/bin/manpath
/usr/bin/whatis
[root@localhost python]# whereis man 【扩展whereis 来搜索配置文件】
man: /usr/bin/man /etc/man.config /usr/share/man /usr/share/man/man7/man.7.gz /usr/share/man/man1p/man.1p.gz /usr/share/man/man1/man.1.gz
[root@localhost python]# rpm -ivh **.rpm【直接安装】
[root@localhost python]# rpm -ivh /path/to/packege **.rpm 【指定安装目录】
-h:显示进度;-v:显示过程;-v:显示详细过程。
yum:yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记.
yum install httpd 安装httpd的软件包。
yum 中搜索mysql的服务包
yum中查看httpd的信息。
本次案例参考使用阿里云的Yum包来安装。(https://opsx.alibaba.com/mirror)
备份文件【我本地删除所有文件,记得删除先备份】
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@localhost ~]# cd /etc/yum.repos.d
yum.repos.d/ yum.repos.d.backup_backup.tar.gz
[root@localhost ~]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Base.repo.backup
[root@localhost yum.repos.d]# yum clean all 【清除yum之前配置】
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache 【加载yum的缓存】
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.7 kB 00:00
base/group_gz | 242 kB 00:00
base/filelists_db | 6.4 MB 00:02
base/primary_db | 4.7 MB 00:02
base/other_db | 2.8 MB 00:01
extras | 3.4 kB 00:00
extras/filelists_db | 24 kB 00:00
extras/prestodelta | 1.1 kB 00:00
extras/primary_db | 27 kB 00:00
extras/other_db | 28 kB 00:00
updates | 3.4 kB 00:00
updates/filelists_db | 1.7 MB 00:00
updates/prestodelta | 80 kB 00:00
updates/primary_db | 2.4 MB 00:01
updates/other_db | 33 MB 00:26
Metadata Cache Created
[root@localhost yum.repos.d]# yum search openssl 【查询yum中是否有openssl中安装包】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
================================================ N/S Matched: openssl ================================================
openssl-devel.i686 : Files for development of applications which will use OpenSSL
openssl-devel.x86_64 : Files for development of applications which will use OpenSSL
openssl-perl.x86_64 : Perl scripts provided with OpenSSL
openssl-static.x86_64 : Libraries for static linking of applications which will use OpenSSL
perl-Crypt-OpenSSL-Bignum.x86_64 : Perl interface to OpenSSL for Bignum
perl-Crypt-OpenSSL-RSA.x86_64 : Perl interface to OpenSSL for RSA
[root@localhost yum.repos.d]# yum repolist 【已经看到阿里巴巴的Yum库文件了】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base CentOS-6 - Base - mirrors.aliyun.com 6,713
extras CentOS-6 - Extras - mirrors.aliyun.com 35
updates CentOS-6 - Updates - mirrors.aliyun.com 257
repolist: 7,005
案例二【加载本地的CD盘中的资源】
#mkdir /mnt/repos/
#mount /dev/cdrom /mnt/repos/
#cd /mnt/repos/Packages
#cd /etc/yum.repos.d/
#cp CentOS-Base.repo CentOS-Base.repo.aliyun.backup
#mv CentOS-Base.repo my.repo #将原来的文件备份,然后更名修改my.repo的配置参数。
#yum clean all
#yum makecache
[root@localhost yum.repos.d]# yum repolist 【查看本身Cd挂载包的packege包】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base:
* updates: mirrors.cn99.com
repo id repo name status
base CentOS-6 - Base 6,367
updates CentOS-6 - Updates 259
repolist: 6,626
【测试是不是挂载了,这里搜索有些资源来鉴定】
[root@localhost yum.repos.d]# yum search zlib
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base:
* updates: mirrors.aliyun.com
================================================= N/S Matched: zlib ==================================================
jzlib.x86_64 : JZlib re-implementation of zlib in pure Java
jzlib-demo.x86_64 : Examples for jzlib
jzlib-javadoc.x86_64 : Javadoc for jzlib
mingw32-zlib.noarch : MinGW Windows zlib compression librar
[root@localhost yum.repos.d]# yum search openssl-devel 【Openssl-devel资源包不在Cd盘挂载的分区中】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base:
* updates: mirrors.aliyun.com
============================================= N/S Matched: openssl-devel =============================================
openssl-devel.i686 : Files for development of applications which will use OpenSSL
openssl-devel.x86_64 : Files for development of applications which will use OpenSSL
Name and summary matches only, use "search all" for everything.
称热打铁(把挂载的CD盘,进行自动挂载,不需要关机就卸载)
[root@localhost mnt]# mount /dev/cdrom /mnt/repos/ 【确保CD盘已经挂载】
mount: block device /dev/sr0 is write-protected, mounting read-only
mount: /dev/sr0 already mounted or /mnt/repos/ busy
mount: according to mtab, /dev/sr0 is already mounted on /mnt/repos
[root@localhost mnt]# cd repos/
[root@localhost repos]# ls
CentOS_BuildTag GPL Packages RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Testing-6
EFI images RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Debug-6 TRANS.TBL
EULA isolinux repodata
[root@localhost repos]# vim /etc/fstab 【修改文件参数,如图下】
案例3 在系统本身同步阿里云的资源包,保证内网下面安装使用。
[root@localhost repos]# cd /etc/yum 【进去yum的配置文件】
yum/ yum.repos.d/
yum.conf yum.repos.d.backup_backup.tar.gz
[root@localhost repos]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# ls
CentOS-Base.repo.aliyun.backup CentOS-Base.repo.backup my.repo
[root@localhost yum.repos.d]# mv my.repo my.repo_backup
[root@localhost yum.repos.d]# mv CentOS-Base.repo.aliyun.backup CentOS-Base.repo.aliyun
[root@localhost yum.repos.d]# mv CentOS-Base.repo.aliyun CentOS-Base.repo 【同上一样,把配置文件改动回来】
[root@localhost yum.repos.d]# yum claen
Loaded plugins: fastestmirror, refresh-packagekit, security
No such command: claen. Please use /usr/bin/yum --help
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.7 kB 00:00
base/group_gz | 242 kB 00:00
base/filelists_db | 6.4 MB 00:01
base/primary_db | 4.7 MB 00:01
base/other_db | 2.8 MB 00:00
extras | 3.4 kB 00:00
extras/filelists_db | 24 kB 00:00
extras/prestodelta | 1.1 kB 00:00
extras/primary_db | 27 kB 00:00
extras/other_db | 28 kB 00:00
updates | 3.4 kB 00:00
updates/filelists_db | 2.0 MB 00:00
updates/prestodelta | 104 kB 00:00
updates/primary_db | 3.0 MB 00:00
updates/other_db | 42 MB 00:18
Metadata Cache Created
[root@localhost yum.repos.d]# yum repolist 【已经变成回来阿里云的yum库】
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base CentOS-6 - Base - mirrors.aliyun.com 6,713
extras CentOS-6 - Extras - mirrors.aliyun.com 35
updates CentOS-6 - Updates - mirrors.aliyun.com 311
repolist: 7,059
[root@localhost yum.repos.d]# reposync -r base -p /opt/repos/ 【reposync 同步指令,可以用Man reposync来搜索帮助。这里更新阿里云官网的Yum包到本地 repos中】
[base: 1 of 6713 ] Downloading Packages/389-ds-base-1.2.11.15-95.el6_9.x86_64.rpm
389-ds-base-1.2.11.15-95.el6_9.x86_64.rpm | 1.5 MB 00:00
。。。。。【由于太多,我就截图一半了】
[root@localhost repos]# ls 【查看验证】
base
[root@localhost repos]# cd base/
[root@localhost base]# ls
Packages
[root@localhost base]# cd Packages/
[root@localhost Packages]# ls
389-ds-base-1.2.11.15-95.el6_9.x86_64.rpm ConsoleKit-libs-0.4.1-6.el6.x86_64.rpm
389-ds-base-devel-1.2.11.15-95.el6_9.i686.rpm ConsoleKit-x11-0.4.1-6.el6.x86_64.rpm
389-ds-base-devel-1.2.11.15-95.el6_9.x86_6
总结: yum、rpm的操作不简单,也不复杂。熟悉掌握好,可以做本地yum包。用一台专门连接外部网络的机子做支撑,其他需要更新安装YUm包的机子专门连接这台。外部网络互相联通的机子保持资源更新,其他机子保证内网下做大数据、人工智能测试。