Linux-yum源

本文详细介绍了Linux中的yum源,包括其作用、常用命令以及如何建立和部署共享型yum源。此外,还讲解了rpm命令的使用,对比了yum与rpm在安装软件时的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.yum源简介
1.全称
yum=yellow dog update modified
2.作用
可以解决软件包的依赖问题,它可以从很多源中搜索软件并找出他们的依赖包,自行安装相应的依赖包。在使用yum安装软件则至少需要一个yum源,用户可以用http等访问yum源
二.yum命令
yum clean all ##清除原有缓存
yum repolist ##列出仓库信息
yum install software ##安装
yum uptade ##更新
yum list software ##查看软件

[root@localhost ~]# yum list dhcp
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Installed Packages
dhcp.x86_64                       12:4.2.5-42.el7                       @rhel7.2

yum list all ##查看所有软件
yum list installed ##列出已安装的软件
yum list available ##列出可安装软件
yum reinstall software ##重新安装软件
yum remove software ##卸载
在这里插入图片描述
yum info software ##查看软件信息
在这里插入图片描述
yum search software信息 ##根据软件信息查找软件
yum whatprovides file ##根据文件找出包含此文件的软件
yum history ##产看系统中软件的管理信息
yum history info 数字 ##对该数字为id的信息进行显示
yum groups list ##列出软件组
在这里插入图片描述
yum groups info ##查看软件组的信息
yum groups install sfgroup ##安装软件组
yum groups remove sfgroup ##卸载软件组
三.软件仓库的建立
1.在虚拟机上安装光驱
注意:在虚拟机关闭的情况下安装光驱
在这里插入图片描述
在这里插入图片描述
2.建立软件仓库
(1)查看文件挂载点

[root@localhost yum.repos.d]# df  
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root   7350272 3128708   4221564  43% /
devtmpfs                 492400       0    492400   0% /dev
tmpfs                    508252     144    508108   1% /dev/shm
tmpfs                    508252    7152    501100   2% /run
tmpfs                    508252       0    508252   0% /sys/fs/cgroup
/dev/vda1                508580  169312    339268  34% /boot
tmpfs                    101652       4    101648   1% /run/user/42
tmpfs                    101652      16    101636   1% /run/user/0
/dev/sr0                3704296 3704296         0 100% /run/media/root/RHEL-7.3 Server.x86_64

(2)编辑yum仓库指向文件

[root@localhost ~]# ls /run/media/root
RHEL-7.3 Server.x86_64
[root@localhost ~]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# vim westos.repo  ##仓库名必须以repo结尾
[root@localhost yum.repos.d]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# cat westos.repo
[westos]
name=rhel7.3
baseurl=file:///run/media/root/"RHEL-7.3 Server.x86_64"
gpgcheck=0

在这里插入图片描述

[root@localhost yum.repos.d]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root   7350272 3128708   4221564  43% /
devtmpfs                 492400       0    492400   0% /dev
tmpfs                    508252     144    508108   1% /dev/shm
tmpfs                    508252    7152    501100   2% /run
tmpfs                    508252       0    508252   0% /sys/fs/cgroup
/dev/vda1                508580  169312    339268  34% /boot
tmpfs                    101652       4    101648   1% /run/user/42
tmpfs                    101652      16    101636   1% /run/user/0
/dev/sr0                3704296 3704296         0 100% /run/media/root/RHEL-7.3 Server.x86_64

(3)安装DHCP

[root@localhost yum.repos.d]# yum install dhcp  ##安装dhcp
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
westos                                                   | 4.1 kB     00:00     
(1/2): westos/group_gz                                     | 136 kB   00:00     
(2/2): westos/primary_db                                   | 3.9 MB   00:00     
Resolving Dependencies
      .....
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 12:dhcp-4.2.5-47.el7.x86_64                                  1/1 
westos/productid                                         | 1.6 kB     00:00     
  Verifying  : 12:dhcp-4.2.5-47.el7.x86_64                                  1/1 

Installed:
  dhcp.x86_64 12:4.2.5-47.el7                                                   

Complete!  ##安装成功

四.共享型yum源的部署–共享服务httpd的安装
httpd 作用:实现服务资源的共享
1.安装httpd服务

[root@localhost ~]# yum install httpd -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
.....
Total                                               14 MB/s | 1.5 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-3.el7.x86_64                                       1/5 
  Installing : apr-util-1.5.2-6.el7.x86_64                                  2/5 
  Installing : httpd-tools-2.4.6-45.el7.x86_64                              3/5 
  Installing : mailcap-2.1.41-2.el7.noarch                                  4/5 
  Installing : httpd-2.4.6-45.el7.x86_64                                    5/5 
  Verifying  : httpd-tools-2.4.6-45.el7.x86_64                              1/5 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                  2/5 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                  3/5 
  Verifying  : httpd-2.4.6-45.el7.x86_64                                    4/5 
  Verifying  : apr-1.4.8-3.el7.x86_64                                       5/5 

Installed:
  httpd.x86_64 0:2.4.6-45.el7                                                   

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                 apr-util.x86_64 0:1.5.2-6.el7       
  httpd-tools.x86_64 0:2.4.6-45.el7        mailcap.noarch 0:2.1.41-2.el7       

Complete!

2.设置阿帕奇

[root@localhost ~]# systemctl start httpd  ##开启httpd
[root@localhost ~]# systemctl enable httpd  ##开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

3.设置火墙

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld  ##开机后不启动
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

4.挂载

[root@localhost ~]# mkdir /var/www/html/westos  ##建立挂载文件
[root@localhost ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root   7350272 3162436   4187836  44% /
devtmpfs                 492400       0    492400   0% /dev
tmpfs                    508252     144    508108   1% /dev/shm
tmpfs                    508252    7160    501092   2% /run
tmpfs                    508252       0    508252   0% /sys/fs/cgroup
/dev/vda1                508580  169312    339268  34% /boot
tmpfs                    101652       4    101648   1% /run/user/42
tmpfs                    101652      24    101628   1% /run/user/0
/dev/sr0                3704296 3704296         0 100% /run/media/root/RHEL-7.3 Server.x86_64
[root@localhost ~]# mount /dev/sr0 /var/www/html/westos ##将镜像挂载到这个文件夹--临时
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# vim /etc/rc.d/rc.local  ##对此文件进行编辑;永久挂载镜像 (此文件为管理开机自动执行的命令)      
[root@localhost ~]# mount /dev/sr0 /var/www/html/westos
mount: /dev/sr0 is write-protected, mounting read-only
mount: /dev/sr0 is already mounted or /var/www/html/westos busy
       /dev/sr0 is already mounted on /run/media/root/RHEL-7.3 Server.x86_64
       /dev/sr0 is already mounted on /var/www/html/westos  ##永久挂载成功
[root@localhost ~]# chmod 755 /etc/rc.d/rc.local  ##给此文件赋予执行权限

在这里插入图片描述
5.挂载完后主机验证是否成功
在浏览器中输入地址
172.25.4.205/westos ##此地址为网络yum源地址
在这里插入图片描述
五.第三方软件仓库的搭建
1.将所有的rpm包放入同一目录中,此实验在/mnt中

[root@localhost mnt]# cd /root/mnt
[root@localhost mnt]# ls
FluffyMcAwesome-A-6.4.0-11.r19335.x86_64.rpm
FluffyMcAwesome-B-6.4.0-11.r19335.x86_64.rpm
kolourpaint-4.10.5-4.el7.x86_64.rpm
kolourpaint-libs-4.10.5-4.el7.x86_64.rpm
wps-office-10.1.0.5672-1.a21.x86_64.rpm   ##不能出现其他不以.rpm结尾的文件

2.执行 createrepo -v命令执行成功则会生成repodata目录

[root@localhost mnt]# createrepo -v /root/mnt
Spawning worker 0 with 5 pkgs
Worker 0: reading FluffyMcAwesome-A-6.4.0-11.r19335.x86_64.rpm
Worker 0: reading FluffyMcAwesome-B-6.4.0-11.r19335.x86_64.rpm
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
Worker 0: reading wps-office-10.1.0.5672-1.a21.x86_64.rpm
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Starting other db creation: Wed Apr 10 17:05:06 2019
Ending other db creation: Wed Apr 10 17:05:06 2019
Starting filelists db creation: Wed Apr 10 17:05:06 2019
Ending filelists db creation: Wed Apr 10 17:05:06 2019
Starting primary db creation: Wed Apr 10 17:05:06 2019
Ending primary db creation: Wed Apr 10 17:05:06 2019
Sqlite DBs complete
[root@localhost mnt]# ls
FluffyMcAwesome-A-6.4.0-11.r19335.x86_64.rpm
FluffyMcAwesome-B-6.4.0-11.r19335.x86_64.rpm
kolourpaint-4.10.5-4.el7.x86_64.rpm
kolourpaint-libs-4.10.5-4.el7.x86_64.rpm
repodata                                 ##生成则命令执行成功
wps-office-10.1.0.5672-1.a21.x86_64.rpm

3. 对软件仓库进行编辑

[root@localhost mnt]# vim /etc/yum.repos.d/westos.repo

在这里插入图片描述
4.清除原有yum缓存

[root@localhost mnt]# yum clean all  ##清除原有yum缓存
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: software westos
Cleaning up everything

5.验证是否建立成功

[root@localhost mnt]# yum list kolo  ##验证
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
software                                                 | 2.9 kB     00:00     ##建立成功  
westos                                                   | 4.1 kB     00:00     
(1/3): software/primary_db                                 | 6.2 kB   00:00     
(2/3): westos/group_gz                                     | 136 kB   00:00     
(3/3): westos/primary_db                                   | 3.9 MB   00:00     
Error: No matching Packages to list

六.rpm命令
1.rpm与yum安装软件的区别
使用rpm安装软件,软件存在的依赖性无法解决
使用yum安装软件,可以解决软件的依赖性,但是能安装的软件是有限的
2.rpm命令
rpm -i ##安装
-v ##显示过程
-h ##hash加密
-e ##卸载
-q ##查看
-a ##所有
-p ##软件包
-ql ##查看软件在系统中的安装文件路径
-qlp ##查看未安扎ung的软件如果在系统中安装产生的文件路径
-qf ##根据某个文件找出此文件属于哪个安装包
-qc ##查看软件的配置文件名称
-qd ##查看软件的帮助文件
–scritps ##查看脚本
–nodeps ##安装软件忽略软件的依赖
–force ##强行安装软件
-Kv ##检验软件包是否被篡改
3.rpm安装软件–wps office

[root@localhost ~]# ls /mnt  
FluffyMcAwesome-A-6.4.0-11.r19335.x86_64.rpm
FluffyMcAwesome-B-6.4.0-11.r19335.x86_64.rpm
kolourpaint-4.10.5-4.el7.x86_64.rpm
kolourpaint-libs-4.10.5-4.el7.x86_64.rpm
repodata
wps-office-10.1.0.5672-1.a21.x86_64.rpm
[root@localhost ~]# cd /mnt
[root@localhost mnt]# yum install wps-office-10.1.0.5672-1.a21.x86_64.rpm  ##首次以yum源安装wps用来消除其依赖性
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Examining wps-office-10.1.0.5672-1.a21.x86_64.rpm: wps-office-10.1.0.5672-1.a21.x86_64
Marking wps-office-10.1.0.5672-1.a21.x86_64.rpm to be installed
Resolving Dependencies
.......
Installed:
  wps-office.x86_64 0:10.1.0.5672-1.a21                                         

Dependency Installed:
  libpng12.x86_64 0:1.2.50-10.el7                                               

Complete!
[root@localhost mnt]# rpm -e wps-office  ##卸载wps
[root@localhost mnt]# rpm -ivh wps-office-10.1.0.5672-1.a21.x86_64.rpm  ##以rpm重新安装wps此时没有依赖性安装成功
Preparing...                          ################################# [100%]
Updating / installing...
   1:wps-office-10.1.0.5672-1.a21     ################################# [100%]
[root@localhost mnt]# rpm -ve wps-office  ##显示卸载信息
Preparing packages...
wps-office-10.1.0.5672-1.a21.x86_64
[root@localhost mnt]# rpm -q wps-office  查看wps状态
package wps-office is not installed  ##处于未安装状态
[root@localhost mnt]# rpm -ivh wps-office-10.1.0.5672-1.a21.x86_64.rpm  ##重新安装
Preparing...                          ################################# [100%]
Updating / installing...
   1:wps-office-10.1.0.5672-1.a21     ################################# [100%]
[root@localhost mnt]# rpm -q wps-office  ##查看wps状态
wps-office-10.1.0.5672-1.a21.x86_64
[root@localhost mnt]# rpm -ivh wps-office-10.1.0.5672-1.a21.x86_64.rpm
Preparing...                          ################################# [100%]
	package wps-office-10.1.0.5672-1.a21.x86_64 is already installed
[root@localhost mnt]# rpm -e wps-office  ##卸载
[root@localhost mnt]# rpm -qp wps-office-10.1.0.5672-1.a21.x86_64.rpm  ##查看wps安装包
wps-office-10.1.0.5672-1.a21.x86_64
[root@localhost mnt]# rpm -q wps-office-10.1.0.5672-1.a21.x86_64.rpm  ##查看安装包状态
package wps-office-10.1.0.5672-1.a21.x86_64.rpm is not installed  ##未安装
[root@localhost mnt]# rpm -qlp wps-office-10.1.0.5672-1.a21.x86_64.rpm##wps未安装若安装后产生文件的路径
/etc
/etc/fonts
/etc/fonts/conf.avail
/etc/fonts/conf.avail/40-wps-office.conf
/etc/fonts/conf.d
/etc/fonts/conf.d/40-wps-office.conf
...
[root@localhost mnt]# rpm -qi wps-office
Name        : wps-office
Version     : 10.1.0.5672
Release     : 1.a21
Architecture: x86_64
Install Date: Fri 12 Apr 2019 10:50:16 PM CST
Group       : Applications/Editors
Size        : 361400998
License     : Proprietary
Signature   : (none)
Source RPM  : wps-office-10.1.0.5672-1.a21.src.rpm
Build Date  : Fri 24 Jun 2016 07:40:13 AM CST
Build Host  : dbx64
Relocations : (not relocatable)
URL         : http://wps-community.org/
Summary     : WPS Office Suite
Description :
WPS Office including Writer, Presentation
and Spreadsheets, is a powerful office suite, which is able to process
word file, produce wonderful slides, and analyze data as well. It is
deeply compatible with all of the latest Microsoft Office file formats.
It can easily open and read the documents created with Microsoft Office.
This is the Linux version, and it's now an BETA package.
Welcome to our website: http://wps-community.org
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值