Linux yum的使用

Linux yum的使用

1. 强制卸载

[root@localhost mnt]# umount /mnt
umount: /mnt:目标忙。
        (有些情况下通过 lsof(8) 或 fuser(1) 可以
         找到有关使用该设备的进程的有用信息)
[root@localhost mnt]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
mount: /dev/sr0 已经挂载或 /mnt 忙
       /dev/sr0 已经挂载到 /mnt 上
[root@localhost mnt]# cd /mnt/
[root@localhost mnt]# ls
addons  EULA  images    LiveOS      Packages       repodata                 RPM-GPG-KEY-redhat-release
EFI     GPL   isolinux  media.repo  release-notes  RPM-GPG-KEY-redhat-beta  TRANS.TBL
[root@localhost mnt]# ls repodata/
372d69e9829f47feb7dcec7723914ed70b3dd5a6cee2ad9fb88e3c6e47022406-primary.sqlite.bz2
4462ede8e612572878f17ad2511e4fa385957a7a7458c36b6d4c2bb96ffd5e26-filelists.xml.gz
4821b54c29735412a3d190a0427d07683a4ae8e61de0f237544fab418be0bc66-productid.gz
49299e96d4edd28b46448c5693ec0d21e7e921f2ef53b13d1ca6b8893ef23069-comps-Server.x86_64.xml.gz
76a190afa1c59e14d3a03f9b03c3eee31df0099f1193528ebb87d4d493d2b686-comps-Server.x86_64.xml
a6e12fbc8e2c149ed7725f4bcb8c5d1cc0039a9c68398f62f69ad3fdf8e160dc-filelists.sqlite.bz2
bb489be107320e4e5abd178222eda57734151fe274ed2ac9af8ea3d37edc834f-primary.xml.gz
c6874e4d580ec5f210995f2d12c21d8cad1914266f54d547325c9f4f5b86284c-other.xml.gz
fe9e2bd6f545aaf9e1e023a18d0e65de6e506515f6e4c464a6a88cf2d43e2194-other.sqlite.bz2
productid
repomd.xml
TRANS.TBL

[root@localhost mnt]# fuser -sf /mnt
[root@localhost mnt]# df -h
文件系统               容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root   18G  902M   17G    6% /
devtmpfs               908M     0  908M    0% /dev
tmpfs                  914M     0  914M    0% /dev/shm
tmpfs                  914M  8.5M  906M    1% /run
tmpfs                  914M     0  914M    0% /sys/fs/cgroup
/dev/sda1              497M   96M  401M   20% /boot
/dev/sr0               3.5G  3.5G     0  100% /mnt

2. 本地配置repo文件

[root@localhost mnt]# vi aa.repo
[root@localhost mnt]# cat aa.repo
cat: aa.repo: 没有那个文件或目录
[root@localhost mnt]# cd /etc/yum
yum/         yum.conf     yum.repos.d/ 
[root@localhost mnt]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vi aa.repo
[root@localhost yum.repos.d]# cat aa.repo 
name=aa
baseurl=file:///mnt
gpgcheck=0
enable=1

3. curl:下载yum仓库

[root@localhost ~]# curl -o /etc/yum.repos.d/Cent0S-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0  15596      0 --:--:-- --:--:-- --:--:-- 15670
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
aa.repo  Cent0S-Base.repo

4. redhat7使用centos7的yum源

(1). 卸载红帽yum源

[root@localhost ~]# rpm -e $(rpm -qa|grep yum) --nodeps
警告:文件 /usr/share/doc/yum-3.4.3/comps.rng: 移除失败: 没有那个文件或目录
警告:文件 /usr/share/bash-completion/completions/yummain.py: 移除失败: 没有那个文件或目录
警告:文件 /usr/share/bash-completion/completions/yum: 移除失败: 没有那个文件或目录

(2). 删除所有repo的相关文件

[root@localhost ~]# rm -f /etc/yum.conf
[root@localhost ~]# rm -rf /etc/yum.repos.d/
[root@localhost ~]# rm -rf /var/cache/yum

(3). 下载centos相关yum组件

a. yum-3.4.3-161.el7.centos.noarch.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-3.4.3-163.el7.centos.noarch.rpm--2019-09-29 06:14:48--  http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-3.4.3-163.el7.centos.noarch.rpm
正在解析主机 mirror.centos.org (mirror.centos.org)... 111.90.139.14, 2401:78c0::e00e
正在连接 mirror.centos.org (mirror.centos.org)|111.90.139.14|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1297332 (1.2M) [application/x-rpm]
正在保存至: “yum-3.4.3-163.el7.centos.noarch.rpm”

100%[=======================================================================>] 1,297,332   5.59KB/s 用时 3m 0s  

2019-09-29 06:17:50 (7.04 KB/s) - 已保存 “yum-3.4.3-163.el7.centos.noarch.rpm” [1297332/1297332])
b. yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
--2019-09-29 06:20:24--  http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
正在解析主机 mirror.centos.org (mirror.centos.org)... 111.90.139.14, 2401:78c0::e00e
正在连接 mirror.centos.org (mirror.centos.org)|111.90.139.14|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:28348 (28K) [application/x-rpm]
正在保存至: “yum-metadata-parser-1.1.4-10.el7.x86_64.rpm”

100%[=======================================================================>] 28,348      69.4KB/s 用时 0.4s   

2019-09-29 06:20:25 (69.4 KB/s) - 已保存 “yum-metadata-parser-1.1.4-10.el7.x86_64.rpm” [28348/28348])
c. yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm
--2019-09-29 06:23:25--  http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm
正在解析主机 mirror.centos.org (mirror.centos.org)... 111.90.139.14, 2401:78c0::e00e
正在连接 mirror.centos.org (mirror.centos.org)|111.90.139.14|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:34744 (34K) [application/x-rpm]
正在保存至: “yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm”

100%[=======================================================================>] 34,744      11.4KB/s 用时 3.0s   

2019-09-29 06:23:29 (11.4 KB/s) - 已保存 “yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm” [34744/34744])
d. yum-updateonboot-1.1.31-50.el7.noarch.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-52.el7.noarch.rpm
--2019-09-29 06:24:30--  http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-52.el7.noarch.rpm
正在解析主机 mirror.centos.org (mirror.centos.org)... 103.232.121.196, 2401:78c0::e00e
正在连接 mirror.centos.org (mirror.centos.org)|103.232.121.196|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:27556 (27K) [application/x-rpm]
正在保存至: “yum-updateonboot-1.1.31-52.el7.noarch.rpm”

100%[=======================================================================>] 27,556      3.67KB/s 用时 9.8s   

2019-09-29 06:24:41 (2.76 KB/s) - 已保存 “yum-updateonboot-1.1.31-52.el7.noarch.rpm” [27556/27556])
e. yum-utils-1.1.31-50.el7.noarch.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-utils-1.1.31-52.el7.noarch.rpm
--2019-09-29 06:26:43--  http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-utils-1.1.31-52.el7.noarch.rpm
正在解析主机 mirror.centos.org (mirror.centos.org)... 111.90.139.14, 2401:78c0::e00e
正在连接 mirror.centos.org (mirror.centos.org)|111.90.139.14|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:124364 (121K) [application/x-rpm]
正在保存至: “yum-utils-1.1.31-52.el7.noarch.rpm”

100%[=======================================================================>] 124,364     5.76KB/s 用时 23s    

2019-09-29 06:27:07 (5.22 KB/s) - 已保存 “yum-utils-1.1.31-52.el7.noarch.rpm” [124364/124364])

(4). 安装所有相关组件

[root@localhost ~]# rpm -ivh yum-* --nodeps
警告:yum-3.4.3-163.el7.centos.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 20%]
   2:yum-plugin-fastestmirror-1.1.31-5################################# [ 40%]
   3:yum-3.4.3-163.el7.centos         ################################# [ 60%]
   4:yum-updateonboot-1.1.31-52.el7   ################################# [ 80%]
   5:yum-utils-1.1.31-52.el7          ################################# [100%]

(5). 下载base和epel库

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-09-29 06:29:59--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 124.232.158.232, 115.231.71.212, 114.80.24.196, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|124.232.158.232|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[=======================================================================>] 2,523       --.-K/s 用时 0s      

2019-09-29 06:29:59 (386 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

[root@localhost ~]# sed -i 's#\$releasever#7#g' /etc/yum.repos.d/CentOS-Base.repo

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2019-09-29 06:31:00--  http://mirrors.aliyun.com/repo/epel-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 106.117.213.215, 115.231.71.215, 175.6.49.236, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|106.117.213.215|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:664 [application/octet-stream]
正在保存至: “/etc/yum.repos.d/epel.repo”

100%[=======================================================================>] 664         --.-K/s 用时 0s      

2019-09-29 06:31:00 (157 MB/s) - 已保存 “/etc/yum.repos.d/epel.repo” [664/664])

5. yum makecache: 创建源数据缓存

[root@localhost ~]# yum makecache
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                      | 3.6 kB  00:00:00     
epel                                                                                      | 5.4 kB  00:00:00     
extras                                                                                    | 2.9 kB  00:00:00     
updates                                                                                   | 2.9 kB  00:00:00     
base/x86_64/primary_db         FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/04efe80d41ea3d94d36294f7107709d1c8f70db11e152d6ef562da344748581a-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Name or service not known"
正在尝试其它镜像。
(1/17): base/x86_64/group_gz                                                              | 165 kB  00:00:00     
(2/17): epel/x86_64/group_gz                                                              |  88 kB  00:00:01     
(3/17): epel/x86_64/updateinfo                                                            | 1.0 MB  00:00:00     
(4/17): base/x86_64/other_db                                                              | 2.6 MB  00:00:02     
(5/17): epel/x86_64/prestodelta                                                           | 2.3 kB  00:00:00     
(6/17): epel/x86_64/primary_db                                                            | 6.8 MB  00:00:03     
(7/17): epel/x86_64/filelists_db                                                          |  12 MB  00:00:05     
(8/17): epel/x86_64/updateinfo_zck                                                        | 1.5 MB  00:00:00     
(9/17): extras/x86_64/other_db                                                            | 100 kB  00:00:00     
(10/17): extras/x86_64/filelists_db                                                       | 207 kB  00:00:00     
(11/17): epel/x86_64/other_db                                                             | 3.3 MB  00:00:01     
(12/17): updates/x86_64/other_db                                                          | 124 kB  00:00:00     
(13/17): updates/x86_64/filelists_db                                                      | 1.1 MB  00:00:00     
(14/17): base/x86_64/primary_db                                                           | 6.0 MB  00:00:02     
base/x86_64/filelists_db       FAILED                                          
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/41232548001a78473ae0f2d4b92e1ec28f7a0593e0495056515887fe2a39b416-filelists.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(15/17): base/x86_64/filelists_db                                                         | 7.3 MB  00:00:03     
extras/x86_64/primary_db       FAILED                                          
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/4e72f00067036f7cc3d1c01071a0f80f1ca5cb4fe19ee225a766e50912179ab6-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(16/17): extras/x86_64/primary_db                                                         | 152 kB  00:00:00     
updates/x86_64/primary_db      FAILED                                          
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/320c8b1640e6fbb60ae572bf3c6f12cafbdd49d6e03f83578928e411720dc939-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(17/17): updates/x86_64/primary_db                                                        | 1.1 MB  00:00:00

6. yum repolist: 列出所有源名称

[root@localhost ~]# yum repolist disabled
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
源标识                                  源名称                                                                   
centosplus/x86_64                       CentOS-7 - Plus - mirrors.aliyun.com                                     
contrib/x86_64                          CentOS-7 - Contrib - mirrors.aliyun.com                                  
epel-debuginfo/x86_64                   Extra Packages for Enterprise Linux 7 - x86_64 - Debug                   
epel-source                             Extra Packages for Enterprise Linux 7 - x86_64 - Source                  
repolist: 0
[root@localhost ~]# grep 'enabled' /etc/yum.repos.d/epel-testing.repo
grep: /etc/yum.repos.d/epel-testing.repo: 没有那个文件或目录
[root@localhost ~]# grep 'enabled' /etc/yum.repos.d/epel.repo 
enabled=1
enabled=0
enabled=0

7. yum install: 安装软件,安装过程中分析依赖关系后, 直接安装, 无需交互

[root@localhost ~]# yum -y install vim wget gcc gcc-c++ vsftpd
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 gcc.x86_64.0.4.8.5-39.el7 将被 安装
--> 正在处理依赖关系 libgomp = 4.8.5-39.el7,它被软件包 gcc-4.8.5-39.el7.x86_64 需要
--> 正在处理依赖关系 cpp = 4.8.5-39.el7,它被软件包 gcc-4.8.5-39.el7.x86_64 需要
--> 正在处理依赖关系 libgcc >= 4.8.5-39.el7,它被软件包 gcc-4.8.5-39.el7.x86_64 需要
--> 正在处理依赖关系 glibc-devel >= 2.2.90-12,它被软件包 gcc-4.8.5-39.el7.x86_64 需要
......

8. yum update: 更新软件

[root@localhost ~]# rpm -qa|grep sudo
sudo-1.8.19p2-10.el7.x86_64
[root@localhost ~]# yum update sudo
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
......

9. yum info: 显示rpm -qi package的结果

[root@localhost ~]# yum info vsftpd
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
名称    :vsftpd
架构    :x86_64
版本    :3.0.2
发布    :25.el7
大小    :353 k
源    :installed
来自源:base
简介    : Very Secure Ftp Daemon
网址    :https://security.appspot.com/vsftpd.html
协议    : GPLv2 with exceptions
描述    : vsftpd is a Very Secure FTP daemon. It was written completely from
         : scratch.

10. yum provides: 查看指定的文件或特性是由哪个包安装生成的

[root@localhost ~]# yum provides *bin/ls
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
coreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts
源    :base
匹配来源:
文件名    :/bin/ls
文件名    :/usr/bin/ls



coreutils-8.22-18.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts

11. yum search: 以指定的关键字搜索程序包名及summary信息

[root@localhost ~]# yum search httpd
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
============================================== N/S matched: httpd ===============================================
dmlite-apache-httpd.x86_64 : Apache HTTPD frontend for dmlite
iipsrv-httpd-fcgi.noarch : Apache HTTPD files for iipsrv
......

12. yum group: 安装整个组的软件

[root@localhost ~]# yum groups mark install "带 GUI 的服务器"
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
没有安装组信息文件
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
Marked install: 带 GUI 的服务器
[root@localhost ~]# yum grouplist
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装环境分组:
   带 GUI 的服务器
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值