Linux系统yum源相关配置

1.yum源概述
本地和网络yum源的配置
rpm -ivh xxx
手动添加依赖,yum不执行安装,自动处理依赖管理
yum优点
rpm安装(下载软件,单独安装,需要解决依赖关系)
源码安装 confgure make make install
yum基于rpm,相当于rpm升级版自动解决依赖关系
本地yum源
yum仓库在本地,系统光盘/镜像文件
查看现有的yum仓库镜像
[root@web1 ~]# ls -l /etc/yum.repos.d/
总用量 4
-rw-r--r--. 1 root root 62 5月  26 00:04 dvd.repo
[root@web1 ~]# yum repolist all //查看所有镜像
[root@web1 ~]# tar -zcvf /etc/yum.repos.d/bak.tar.gz /etc/yum.repos.d/* #打包压缩
[root@web1 ~]# rm -rf /etc/yum.repos.d/*.repo #删除
[root@web1 ~]# rm -rf /mnt/*
[root@web1 ~]# mount -o ro /dev/sr0 /mnt/
 选项 -o 表示挂载方式
 ro=readonly
 rw=read and write
将光盘数据挂载到/mnt目录中,就可以在该目录读取光盘的数据
[root@web1 ~]# lsblk 
[root@web1 ~]# vim /etc/rc.local #开机自动挂载
mount -o ro /dev/sr0 /mnt/
yum仓库格式
【仓库名称】可以有多个仓库
name=仓库名称
baseurl=仓库的路径,⽀持多种格式 file:// ftp:// http/s://
gpgcheck= gpg秘钥检测 0不检测,1检测,如果需要配置秘钥链接
enable= 0/1 是否启⽤当前仓库
[root@web1 ~]# vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
enable=1
[root@web1 ~]# yum clean all //清除缓存
[root@web1 ~]# yum makecache //生成缓存
[root@web1 ~]# yum -y install httpd //测试安装httpd
网络yum源
[root@web1 ~]# mv /etc/yum.repos.d/local.repo /etc/yum.repos.d/local.repo.backup
[root@web1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@web1 ~]# yum clean all 
[root@web1 ~]# yum makecache 
[root@web1 ~]# yum list | grep python3
sl(火车代码)
[root@web1 ~]# mount -o ro /dev/sr0 /mnt/
[root@web1 ~]# yum makecache 
[root@web1 ~]# yum -y install epel-release.noarch 
[root@web1 ~]# yum -y install sl
[root@web1 ~]# sl


特定软件源配置nginx
[root@web1 ~]# yum -y install nginx.x86_64 
[root@web1 ~]# nginx //启动服务
[root@web1 ~]# whereis nginx //查看指令
[root@web1 ~]# curl http://localhost //访问服务器
[root@web1 ~]# nginx -s stop //停用nginx
[root@web1 ~]# yum remove nginx.x86_64 
缓存某些软件到本地
[root@web1 ~]# vim /etc/yum.conf 
cachedir=/var/cache/yum/$basearch/$releaserver # 定义软件包缓存路径
keepcache=1 #开启缓存(修改为1)
[root@web1 ~]# yum -y install tree //测试
[root@web1 ~]# find /var/cache/yum/x86_64/7/ -name "*tree*"
[root@web1 ~]# ls -l /var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm
[root@web1 ~]# yum -y install --downloadonly --downloaddir=./soft/ samba
[root@web1 ~]# yum -y install createrepo #安装createrepo制作仓库的软件
[root@web1 ~]# createrepo soft/ #把soft⽂件夹做成⼀个本地的⾃建仓库
[root@web1 ~]# vim /etc/yum.repos.d/soft.repo
[soft]
name=soft
baseurl=file:///root/soft/
gpgcheck=0
enable=1
[root@web1 ~]# yum clean all 
[root@web1 ~]# yum makecache 
[root@web1 ~]# yum -y install samba //再次安装samba

  • 30
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在Linux系统中,yum源是用来管理软件包的工具。配置yum源可以让我们方便地安装和更新软件包。以下是配置yum源的步骤: 1. 打开终端,以root用户身份登录。 2. 编辑yum源配置文件,一般在/etc/yum.repos.d/目录下,可以使用vi或nano等编辑器打开。 3. 备份原有的yum源配置文件,以防出现问题。 4. 在配置文件中添加需要的yum源,可以从官方网站或其他可信渠道获取。 5. 保存配置文件并退出编辑器。 6. 运行yum clean all命令清除缓存。 7. 运行yum makecache命令生成新的缓存。 8. 完成yum源配置,可以使用yum命令安装和更新软件包。 ### 回答2: yum是一种包管理器,是一个用于在Linux操作系统中自动从互联网上寻找、安装和更新软件包的工具。yum源就是指存储软件包的所在位置,配置yum源是为了下载安装软件包时可以方便快捷地从服务器上获取,提高下载速度和效率。下面介绍linux系统yum源配置。 1.备份原有yum源配置yum源之前,应该先备份原有的yum源配置文件。我们可以通过执行以下命令进行备份: sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 这个命令会将原有的yum配置文件备份为CentOS-Base.repo.bak。 2.下载新的yum源配置文件 我们可以从CentOS官方网站上下载最新的yum源配置文件。通过执行以下命令进行下载: sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 这个命令会从阿里云上下载CentOS-7的yum源配置文件。 3.启用新的yum源 当我们下载了新的yum源配置文件后,需要将其启用。我们可以通过修改配置文件中的enabled参数来实现。执行如下命令打开配置文件: sudo vim /etc/yum.repos.d/CentOS-Base.repo 找到[base]、[updates]和[extras]这三个段落,将其中的enabled参数修改为1,启用新的yum源: [base] name=CentOS-$releasever - Base baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 enabled=1 [updates] name=CentOS-$releasever - Updates baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 enabled=1 [extras] name=CentOS-$releasever - Extras baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 enabled=1 完成后保存并退出配置文件。 4.清除旧的yum缓存 当yum源配置修改后,需要先清除旧的yum缓存,再进行新的yum源缓存的更新。执行以下命令进行清除: sudo yum clean all 5.生成新的yum缓存 清除旧的yum缓存之后,就可以生成新的yum缓存了。执行以下命令进行更新: sudo yum makecache 这个命令会从新的yum源下载软件包列表并生成新的缓存文件。 通过以上的步骤,我们就可以对linux系统进行yum源配置配置yum源后,我们可以更方便快捷地下载和安装软件包了。同时,我们可以通过定期的更新来保持yum源的最新版本,提高系统的稳定性和安全性。 ### 回答3: Linux系统yum源是指一个可用于在线安装和更新软件包的软件仓库。它通常包含各种软件包,如应用程序、库和驱动程序等。Linux系统yum源是一种非常有用的工具,可以使用户轻松地管理和安装软件包。 配置Linux系统yum源可以让用户在系统上安装所需的软件包,而无需下载或手动安装。它可以让用户在系统上安装软件时更加方便快捷,并获得最新的软件更新和安全补丁。下面是一个基本的步骤,用于配置Linux系统yum源。 1. 打开终端,并以root用户身份登录系统 2. 备份原有yum源配置文件,命名为/etc/yum.repos.d/backup 3. 下载并安装新的yum源 1)访问Linux系统yum源官网,选择所需的软件源 2)按照官网的指示下载并安装所选的软件源文件 3)解包软件源文件 # tar zxvf source_name.tar.gz 4)安装软件源 # rpm -ivh rpm_name.rpm 4. 更新yum源 在安装新的yum源时,可使用以下命令更新已安装的yum源 # yum update 如果更新时出现错误或异常,请检查修改后的yum源是否存在错误 5. 重新启动Linux系统 安装新的配置文件后,最好重新启动系统,使新文件生效 以上是一个基本的步骤,用于配置Linux系统yum源。需要指出的是,Linux系统开发和更新很快,因此在配置yum源时应选择最新的、最稳定的软件源文件。另外,在使用yum安装软件时,最好使用官方的软件源,以避免非官方软件源中含有恶意软件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值