【Linux系列教程】yum工具管理rpm软件

一、yum工具介绍

  1. 优势
    • 自动解决软件的依赖关系
  2. yum源配置文件
    • 事先存在合适的yum源配置文件
    • 说明RPM软件安装的存放位置
  3. yum源类型
    • 本地源
    • FTP源
    • HTTP源
  4. yum源配置文件存放位置
    • /etc/yum.repos.d/*.repo

[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@localhost ~]# yum install httpd

替换centos的base源(华为、阿里、网易) 
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

二、配置本地源安装软件

1、备份自带的HTTP源

[root@localhost ~]# mkdir /etc/yum.repos.d/bak
[root@localhost ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
[root@localhost ~]# ls /etc/yum.repos.d/
bak

2、编写本地源

[root@localhost ~]# vim /etc/yum.repos.d/centos7.repo 
[centos7]
name=centos7
baseurl=file:///opt/software
enabled=1
gpgcheck=0
[root@localhost ~]# mkdir /opt/software
[root@localhost ~]# mount /dev/sr0 /opt/software
mount: /dev/sr0 is write-protected, mounting read-only

3、清除旧的yum缓存

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: centos7
Cleaning up list of fastest mirrors
Other repos take up 145 M of disk space (use --verbose for details)

4、查看可用yum源

[root@localhost ~]# yum repolist     
Loaded plugins: fastestmirror
Determining fastest mirrors
centos7                                                                                                        | 3.6 kB  00:00:00     
(1/2): centos7/group_gz                                                                                        | 166 kB  00:00:00     
(2/2): centos7/primary_db                                                                                      | 6.0 MB  00:00:00     
repo id                                                         repo name                                                       status
centos7                                                         centos7                                                         10,019
repolist: 10,019

5、测试安装软件

[root@localhost ~]# yum install lrzsz 
[root@localhost ~]# rpm -q lrzsz
lrzsz-0.12.20-36.el7.x86_64

[root@localhost ~]# yum install php vsftpd 

三、配置FTP源安装ceph-deploy软件

[root@localhost ~]# cat /etc/yum.repos.d/ceph.repo
[ceph]
name=ceph
baseurl=ftp://10.11.0.254/software/ceph-mimic/
enabled=1
gpgcheck=0
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: centos7 ceph
Cleaning up list of fastest mirrors
Other repos take up 145 M of disk space (use --verbose for details)
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
centos7                                                                                                        | 3.6 kB  00:00:00     
ceph                                                                                                           | 2.9 kB  00:00:00     
(1/3): centos7/group_gz                                                                                        | 166 kB  00:00:00     
(2/3): centos7/primary_db                                                                                      | 6.0 MB  00:00:00     
(3/3): ceph/primary_db                                                                                         | 755 kB  00:00:00     
repo id                                                         repo name                                                       status
centos7                                                         centos7                                                         10,019
ceph                                                            ceph                                                               266
repolist: 10,285

[root@localhost ~]# yum install ceph-deploy 

四、配置HTTP源安装openstack-keystone软件

[root@localhost ~]# cat /etc/yum.repos.d/openstack.repo 
[openstack]
name=openstack
baseurl=http://mirrors.163.com/centos/7.9.2009/cloud/x86_64/openstack-queens/
enabled=1
gpgcheck=0
[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Determining fastest mirrors
centos7                                                                                                        | 3.6 kB  00:00:00     
ceph                                                                                                           | 2.9 kB  00:00:00     
openstack                                                                                                      | 3.0 kB  00:00:00     
(1/4): centos7/group_gz                                                                                        | 166 kB  00:00:00     
(2/4): centos7/primary_db                                                                                      | 6.0 MB  00:00:00     
(3/4): ceph/primary_db                                                                                         | 755 kB  00:00:00     
(4/4): openstack/primary_db                                                                                    | 1.2 MB  00:00:31     
repo id                                                         repo name                                                       status
centos7                                                         centos7                                                         10,019
ceph                                                            ceph                                                               266
openstack                                                       openstack                                                        3,116
repolist: 13,401

[root@localhost ~]# yum install openstack-keystone

五、yum缓存、制作yum仓库

1、yum缓存功能

  • 缓存软件的安装包
[root@localhost ~]# vim /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1

[root@localhost ~]# find /var/cache/yum/ -name "*.rpm" -exec cp {} /openstack/ \;

2、制作yum仓库

# createrepo 目录名称 

六、yum常用功能

1、安装软件

# yum install 软件名称  软件名称 

2、卸载软件

# yum remove 软件名称 软件名称 

3、更新软件

# yum update 软件名称 软件名称

4、清除yum缓存

# yum clean all 

5、查看可用的yum源

# yum repolist 

6、查询文件对应的软件

# yum provides 文件名称