rpm命令是RPM软件包的管理工具。rpm原本是Red Hat Linux发行版专门用来管理Linux各项套件的程序
语法
rpm(选项)(参数)
rpm {-i|--install} [install-options] PACKAGE_FILE ...
rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...
rpm {-F|--freshen} [install-options] PACKAGE_FILE ...
rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts] [--test] PACKAGE_NAME ...
rpm {-q|--query} [select-options] [query-options]
rpm {-V|--verify} [select-options] [verify-options]
选项
-i, --install :安装
-h:hash marks输出进度条;每个#表示2%的进度;
--test:测试安装,检查并报告依赖关系及冲突消息等;
--nodeps:忽略依赖关系;不建议;
--replacepkgs:重新安装;
--nosignature:不检查包签名信息,不检查来源合法性;
--nodigest:不检查包完整性信息;
--foce:强制安装
-U, --update:升级或安装
-F, --freshen :升级
-oldpackage:降级;
--force:强制升级;
-e, --erase:卸载
--allmatches:卸载所有匹配指定名称的程序包的各版本;
--nodeps:忽略依赖关系;
--test:测试卸载,dry run模式;
-q, --query:查询
[select-options]
PACKAGE_NAME:查询指定的程序包是否已经安装,及其版本;
-a, --all:查询所有已经安装过的包;
-f FILE:查询指定的文件由哪个程序包安装生成;
-p, --package PACKAGE_FILE:用于实现对未安装的程序包执行查询操作;
--whatprovides CAPABILITY:查询指定的CAPABILITY由哪个程序包提供;
--whatrequires CAPABILITY:查询指定的CAPABILITY被哪个包所依赖;
[query-options]
--changelog:查询rpm包的changlog;
-l, --list:程序安装生成的所有文件列表;
-i, --info:程序包相关的信息,版本号、大小、所属的包组,等;
-c, --configfiles:查询指定的程序包提供的配置文件;
-d, --docfiles:查询指定的程序包提供的文档;
--provides:列出指定的程序包提供的所有的CAPABILITY;
-R, --requires:查询指定的程序包的依赖关系;
--scripts:查看程序包自带的脚本片断;
-V, --verify:校验
S file Size differs(文件大小是否改变)
M Mode differs (includes permissions and file type)(文件的类型或文件的权限(rwx)是否被改变)
5 digest (formerly MD5 sum) differs(文件MD5校验和是否改变(可看成文件内容是否改变))
D Device major/minor number mismatch(设备的中,从代码是否改变)
L readLink(2) path mismatch(文件路径是否改变)
U User ownership differs(文件的属主(所有者)是否改变)
G Group ownership differs(文件的属组是否改变)
T mTime differs(文件的修改时间是否改变)
P caPabilities differ
--initdb:初始化数据库,当前无任何数据库可实始化创建一个新的;当前有时不执行任何操作;
--rebuilddb:重新构建,通过读取当前系统上所有已经安装过的程序包进行重新创建;
参数
安装文件
安装文件显示进程和详情 -ivh
[root@localhost zabbix]# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
warning: zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-3.4-2.el7 ################################# [100%]
强制安装,忽略依赖包 -ivh --force -- nodeps
[root@localhost zabbix]# rpm -ivh --force --nodeps zabbix-release-3.4-2.el7.noarch.rpm
warning: zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-rele
测试安装 --test
[root@localhost ~]# rpm -ivh --test /tmp/zabbix/zabbix-release-3.4-2.el7.noarch.rpm
warning: /tmp/zabbix/zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
[root@localhost ~]# rpm -qa | grep zabbix
[root@localhost ~]#
查询
根据软件名查询安装包版本信息 -q
[root@localhost ~]# rpm -q wget
wget-1.14-15.el7_4.1.x86_64
查询所有安装的软件 -qa
[root@localhost ~]# rpm -qa
pciutils-3.5.1-1.el7.x86_64
centos-release-7-3.1611.el7.centos.x86_64
dracut-network-033-463.el7.x86_64
filesystem-3.2-21.el7.x86_64
lvm2-libs-2.02.166-1.el7.x86_64
tzdata-2016g-2.el7.noarch
......
根据软件名查询详细信息 -qi
[root@localhost ~]# rpm -qi wget
Name : wget
Version : 1.14
Release : 15.el7_4.1
Architecture: x86_64
Install Date: Thu 29 Mar 2018 10:19:23 PM CST
Group : Applications/Internet
Size : 2055533
............
根据文件查询软件包 -qf
[root@localhost ~]# rpm -qf /usr/share/doc/zabbix-release-3.4
zabbix-release-3.4-2.el7.noarch
根据软件名查询所有的安装路径 -ql
[root@localhost ~]# rpm -ql wget
/etc/wgetrc
/usr/bin/wget
/usr/share/doc/wget-1.14
/usr/share/doc/wget-1.14/AUTHORS
/usr/share/doc/wget-1.14/COPYING
/usr/share/doc/wget-1.14/MAILING-LIST
/usr/share/doc/wget-1.14/NEWS
/usr/share/doc/wget-1.14/README
/usr/share/doc/wget-1.14/sample.wgetrc
........
查询包的依赖关系 -qR or -q --requiress
rpm -qR wget
/bin/sh
/bin/sh
/sbin/install-info
/sbin/install-info
config(wget) = 1.14-15.el7_4.1
libc.so.6()(64bit)
libc.so.6(GLIBC_2.11)(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libc.so.6(GLIBC_2.15)(64bit)
libc.so.6(GLIBC_2.17)(64bit)
libc.so.6(GLIBC_2.2.5)(64bit)
libc.so.6(GLIBC_2.3)(64bit)
libc.so.6(GLIBC_2.3.4)(64bit)
......
根据软件名查询配置文件 -qc
[root@localhost ~]# rpm -qc wget
/etc/wgetrc
根据软件名查询说明文档 -qd
[root@localhost ~]# rpm -qd wget
/usr/share/doc/wget-1.14/AUTHORS
/usr/share/doc/wget-1.14/COPYING
/usr/share/doc/wget-1.14/MAILING-LIST
/usr/share/doc/wget-1.14/NEWS
/usr/share/doc/wget-1.14/README
/usr/share/doc/wget-1.14/sample.wgetrc
/usr/share/info/wget.info.gz
/usr/share/man/man1/wget.1.gz
根据软件名查询版本更新日志 -q --changelog
[root@localhost ~]# rpm -q --changelog wget | less
* Tue Oct 24 2017 Tomas Hozza - 1.14-15.1
- Fixed various security flaws (CVE-2017-13089, CVE-2017-13090)
* Fri May 05 2017 Tomas Hozza - 1.14-15
- Added TLSv1_1 and TLSv1_2 as secure-protocol values to help (#1439811)
- Fixed synchronization in randomly failing unit test Test-proxied-https-auth (#1448440)
* Wed Apr 12 2017 Tomas Hozza - 1.14-14
- TLS v1.1 and v1.2 can now be specified with --secure-protocol option (#1439811)
根据软件名查询软件包提供的能力
[root@localhost ~]# rpm -q --provides wget
bundled(gnulib)
config(wget) = 1.14-15.el7_4.1
webclient
wget = 1.14-15.el7_4.1
wget(x86-64) = 1.14-15.el7_4.1
根据安装包查询程序详细信息
[root@localhost zabbix]# rpm -qpi zabbix-release-3.4-2.el7.noarch.rpm
warning: zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Name : zabbix-release
Version : 3.4
Release : 2.el7
Architecture: noarch
Install Date: (not installed)
Group : System Environment/Base
.........
根据安装包查询程序所有的安装的路径
[root@localhost zabbix]# rpm -qpl zabbix-release-3.4-2.el7.noarch.rpm
warning: zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-3.4
/usr/share/doc/zabbix-release-3.4/GPL
升级
升级安装,覆盖安装 -Uvh
[root@localhost zabbix]# rpm -Uvh zabbix-release-3.4-2.el7.noarch.rpm
warning: zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
package zabbix-release-3.4-2.el7.noarch is already installed
只升级
root@localhost zabbix]# rpm -Fvh zabbix-release-3.4-2.el7.noarch.rpm
warning: zabbix-release-3.4-2.el7.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
卸载
[root@localhost ~]# rpm -evh zabbix-release
Preparing... ################################# [100%]
Cleaning up / removing...
1:zabbix-release-3.4-2.el7 ################################# [100%]
软件校验
修改wget配置文件,后进行校验
[root@localhost zabbix]# rpm -V wget
S.5....T. c /etc/wgetrc
包来源合法性验正和完整性验正CentOS发行版
导入证书:
[root@localhost ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
验证:
(1) 安装此组织签名的程序时,会自动执行验正;
(2) 手动验正:rpm -K PACKAGE_FILE
重建数据路
rpm数据库路径 /var/lib/rpm/
[root@localhost ~]# ll /var/lib/rpm
total 37792
-rw-r--r--. 1 root root 1261568 Mar 30 02:08 Basenames
-rw-r--r--. 1 root root 8192 Mar 28 07:14 Conflictname
-rw-r--r--. 1 root root 270336 Mar 30 02:48 __db.001
-rw-r--r--. 1 root root 81920 Mar 30 02:48 __db.002
-rw-r--r--. 1 root root 1318912 Mar 30 02:48 __db.003
-rw-r--r--. 1 root root 425984 Mar 30 02:08 Dirnames
-rw-r--r--. 1 root root 12288 Mar 30 02:08 Group
-rw-r--r--. 1 root root 12288 Mar 30 02:08 Installtid
-rw-r--r--. 1 root root 24576 Mar 30 02:08 Name
-rw-r--r--. 1 root root 16384 Mar 28 07:14 Obsoletename
-rw-r--r--. 1 root root 33591296 Mar 30 02:08 Packages
-rw-r--r--. 1 root root 1609728 Mar 30 02:08 Providename
-rw-r--r--. 1 root root 131072 Mar 29 22:19 Requirename
-rw-r--r--. 1 root root 40960 Mar 30 02:08 Sha1header
-rw-r--r--. 1 root root 24576 Mar 30 02:08 Sigmd5
-rw-r--r--. 1 root root 8192 Mar 28 07:14 Triggername
初始化数据库
[root@localhost ~]# rpm --initdb
重构数据库
[root@localhost ~]# rpm --rebuilddb
yum命令是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。
语法
yum(选项)(参数)
选项
-y:对所有的提问都回答“yes”;
-c:指定配置文件;
-q:安静模式;
-v:详细模式;
-C:完全从缓存中运行,而不去下载或者更新任何头文件。
参数
install:安装rpm软件包;
update:更新rpm软件包;
check-update:检查是否有可用的更新rpm软件包;
remove:删除指定的rpm软件包;
list:显示软件包的信息;
search:检查软件包的信息;
info:显示指定的rpm软件包的描述信息和概要信息;
clean:清理yum过期的缓存;
shell:进入yum的shell提示符;
resolvedep:显示rpm软件包的依赖关系;
localinstall:安装本地的rpm软件包;
localupdate:显示本地rpm软件包进行更新;
deplist:显示rpm软件包的所有依赖关系。
repolist[all|enabled|disabled]:显示仓库列表
配置文件
/etc/yum.conf:为所有仓库提供公共配置
/etc/yum.repos.d/*.repo:为仓库的指向提供配置
仓库指向的定义
[root@localhost ~]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
......
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
......
定义如下:
[repositoryID]
name=Some name for this repository
baseurl=url://path/to/repository/
enabled={1|0} :启用
gpgcheck={1|0}:校验
gpgkey=URL:校验key地址
enablegroups={1|0}
failovermethod={roundrobin|priority}
默认为:roundrobin,意为随机挑选;
cost=
默认为1000
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
$releasever:表示当前系统的发行版本,可以通过rpm -qi centos-release 或 rpm -q --qf %{version} centos-release;echo
$basearch:系统硬件架构,使用命令arch得到 或rpm -q --qf %{arch} centos-release;echo
[root@localhost ~]# rpm -qi centos-release
Name : centos-release
Version : 7
Release : 3.1611.el7.centos
Architecture: x86_64
Install Date: Wed 28 Mar 2018 06:44:22 AM CST
Group : System Environment/Base
Size : 37000
License : GPLv2
Signature : RSA/SHA256, Wed 30 Nov 2016 02:57:12 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM : centos-release-7-3.1611.el7.centos.src.rpm
Build Date : Wed 30 Nov 2016 02:12:59 AM CST
Build Host : c1bm.rdu2.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem
Vendor : CentOS
Summary : CentOS Linux release file
Description :
CentOS Linux release files
其中Version : 7就是系统版本号
[root@localhost ~]# arch
x86_64
[root@localhost ~]# rpm -q --qf %{version} centos-release;echo
7
[root@localhost ~]# rpm -q --qf %{arch} centos-release;echo
x86_64
实例
显示仓库列表 -repolist[all|enabled|disabled]
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 9,591
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 446
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 2,416
显示程序包 -list
yum list all //显示所有程序包
yum list installed //显示已安装的程序包
yum list updates //显示已升级的程序包
yum list available //显示可安装的程序包
[root@localhost ~]# yum list avaiable httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Available Packages
httpd.x86_64 2.4.6-67.el7.centos.6 updates
安装程序 install
yum install -y httpd
重新安装 reinstall
yum reinstall -y httpd
升级程序包 update
yum update httpd
降级程序包 downgrade
yum downgrade httpd
检查可用升级 check-update
yum check-update
卸载程序包 remove
yum remove httpd
查看程序详细信息 info
[root@localhost ~]# yum info wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Installed Packages
Name : wget
Arch : x86_64
Version : 1.14
Release : 15.el7_4.1
Size : 2.0 M
Repo : installed
From repo : updates
Summary : A utility for retrieving files using the HTTP or FTP protocols
URL : http://www.gnu.org/software/wget/
License : GPLv3+
Description : GNU Wget is a file retrieval utility which can use either the HTTP or
: FTP protocols. Wget features include the ability to work in the
: background while you are logged out, recursive retrieval of
: directories, file name wildcard matching, remote file timestamp
: storage and comparison, use of Rest with FTP servers and Range with
: HTTP servers to retrieve files over slow or unstable connections,
: support for Proxy servers, and configurability.
查看指定的特性是由哪些程序包提供的 provides
[root@localhost ~]# yum provides httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
httpd-2.4.6-67.el7.centos.x86_64 : Apache HTTP Server
Repo : base
httpd-2.4.6-67.el7.centos.2.x86_64 : Apache HTTP Server
Repo : updates
httpd-2.4.6-67.el7.centos.5.x86_64 : Apache HTTP Server
Repo : updates
httpd-2.4.6-67.el7.centos.6.x86_64 : Apache HTTP Server
Repo : updates
清理本地缓存 clean
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
构建缓存 makecache
yum makecache
根据程序查询程序包名称 search
[root@localhost ~]# yum search httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
============================================== N/S matched: httpd ===============================================
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
python2-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
查看指定包所依赖的capabilities:deplist
[root@localhost ~]# yum deplist wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
package: wget.x86_64 1.14-15.el7_4.1
dependency: /bin/sh
provider: bash.x86_64 4.2.46-29.el7_4
dependency: /sbin/install-info
provider: info.x86_64 5.1-4.el7
dependency: libc.so.6(GLIBC_2.17)(64bit)
provider: glibc.x86_64 2.17-196.el7_4.2
dependency: libcrypto.so.10()(64bit)
provider: openssl-libs.x86_64 1:1.0.2k-8.el7
dependency: libcrypto.so.10(libcrypto.so.10)(64bit)
provider: openssl-libs.x86_64 1:1.0.2k-8.el7
dependency: libdl.so.2()(64bit)
provider: glibc.x86_64 2.17-196.el7_4.2
dependency: libidn.so.11()(64bit)
provider: libidn.x86_64 1.28-4.el7
dependency: libidn.so.11(LIBIDN_1.0)(64bit)
provider: libidn.x86_64 1.28-4.el7
dependency: libpcre.so.1()(64bit)
provider: pcre.x86_64 8.32-17.el7
dependency: libssl.so.10()(64bit)
provider: openssl-libs.x86_64 1:1.0.2k-8.el7
dependency: libssl.so.10(libssl.so.10)(64bit)
provider: openssl-libs.x86_64 1:1.0.2k-8.el7
dependency: libuuid.so.1()(64bit)
provider: libuuid.x86_64 2.23.2-43.el7_4.2
dependency: libuuid.so.1(UUID_1.0)(64bit)
provider: libuuid.x86_64 2.23.2-43.el7_4.2
dependency: libz.so.1()(64bit)
provider: zlib.x86_64 1.2.7-17.el7
dependency: rtld(GNU_HASH)
provider: glibc.x86_64 2.17-196.el7_4.2
provider: glibc.i686 2.17-196.el7_4.2
查看yum事务历史
[root@localhost ~]# yum history
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
8 | root | 2018-04-01 18:28 | Erase | 1
7 | root | 2018-04-01 18:06 | Reinstall | 1
6 | root | 2018-04-01 17:47 | Install | 5
5 | root | 2017-12-31 19:17 | Install | 1
4 | root | 2017-12-26 22:31 | Install | 31
3 | root | 2017-12-25 22:30 | I, U | 25
2 | root | 2017-12-25 21:58 | Install | 1
1 | System | 2017-12-23 22:03 | Install | 356
包组相关命令
显示包组 grouplist
[root@localhost ~]# yum grouplist
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Available Environment Groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Available Groups:
Compatibility Libraries
Console Internet Tools
Development Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Scientific Support
Security Tools
Smart Card Support
System Administration Tools
System Management
Done
查看包组信息 groupinfo
[root@localhost ~]# yum groupinfo Development Tools
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Group: Development Tools
Group-Id: development
Description: A basic development environment.
Mandatory Packages:
+autoconf
+automake
binutils
+bison
+flex
+gcc
+gcc-c++
gettext
+libtool
make
+patch
pkgconfig
+redhat-rpm-config
+rpm-build
+rpm-sign
Default Packages:
+byacc
......
安装包组 groupinstall
yum groupinstall Development Tools
更新包组 groupupdate
yum groupupdate Development Tools
移除包组 groupremove
yum groupremove Development Tools
综合实例
配置阿里云epel源
[root@localhost yum.repos.d]# cat Centos-epel.repo
[epel]
name=CentOS-$releasever - epel - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/epel/$releasever/$basearch/
gpgcheck=0
enalbed=1
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 9,591
epel/7/x86_64 CentOS-7 - epel - mirrors.aliyun.com 12,454
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 446
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 2,416
配置本地yum源,以/tmp/os为源文件
[root@localhost os]# ll
total 42964
-rw-r--r--. 1 root root 43988984 Jan 13 2017 java-1.6.0-openjdk-1.6.0.41-1.13.13.1.el7_3.x86_64.rpm
[root@localhost os]# createrepo /tmp/os //创建repodata
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost os]# ll
total 42964
-rw-r--r--. 1 root root 43988984 Jan 13 2017 java-1.6.0-openjdk-1.6.0.41-1.13.13.1.el7_3.x86_64.rpm
drwxr-xr-x. 2 root root 4096 Apr 1 20:04 repodata
[root@localhost os]# cat /etc/yum.repos.d/Centos-Local.repo
[local]
name=CentOS-$releasever - local
baseurl=file:///tmp/os
enabled=1
gpgcheck=0
[root@localhost os]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 9,591
epel/7/x86_64 CentOS-7 - epel - mirrors.aliyun.com 12,454
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 446
local CentOS-7 - local 1
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 2,416
repolist: 24,908
[root@localhost os]#