配置YUM源
YUM简介
yum命令是在Fedora和RedHat以及SUSE中基于rpm的软件包管理器,它可以使系统管理人员交互和自动化地更细与管理RPM软件包,yum 主要功能是更方便的添加/删除/更新RPM 包,自动解决包的倚赖性问题,便于管理大量系统的更新问题。
yum常用命令
yum repolist {all|enabled|disabled} 列出所有/已启用/
已禁用的yum源
yum list {all|installed|avaliable} 列出所有/已安装/
可安装的软件包
yum info package 显示某一个软件包
的信息
yum install package 安装软件包
yum reinstall package 重新安装软件包
yum remove|erase package 卸载软件包
yum provides files 查询某个文件是哪
个软件包生成的
yum search file 查询某个文件是哪个软件包生成的
配置本地源
[root@node1 ~]# mkdir /mnt/cdrom #建一个挂载目录
[root@node1 ~]# mount /dev/cdrom /mnt/cdrom/ #把光盘文件挂载在/mnt/cdrom上
[root@node1 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 37G 1.8G 36G 5% /
devtmpfs 979M 0 979M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 1014M 135M 880M 14% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt/cdrom
[root@node1 /]# vim /etc/yum.repos.d/centos7-local.repo
[local]
name=my localserver
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
[root@node1 etc]# ll /etc/yum.repos.d/
总用量 4
-rw-r--r-- 1 root root 75 11月 30 13:33 centos7-local.repo
找个软件安装测试
[root@node1 /]# yum install bind -y
配置自动仓库
https://mirrors.tuna.tsinghua.edu.cn/ 清华大学开源软件镜像站
http://mirrors.163.com/ 网易开源镜像站
https://developer.aliyun.com/mirror/ 阿里云官方镜像站
安装yum的扩展包:
[root@node1 ~]# yum install yum-utils -y
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 yum-utils-1.1.31-50.el7.noarch 已安装并且是最新版本
自动配置国内epel仓库:
[root@node1 ~]# yum-config-manager --add-repo=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
已加载插件:fastestmirror, langpacks
adding repo from: https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
[mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_]
name=added from: https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
enabled=1
自动添加的yum源没有GPG验证的,需要自己添加如下:
[root@node1 ~]# vim /etc/yum.repos.d/mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_.repo
[mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_]
name=added from: https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/
enabled=1
gpgcheck=1 #添加下面两行
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-7
[root@node1 ~]# yum repolist all #查看仓库状态
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识 源名称 状态
local my localserver 启用: 4,021
!mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ added from: https://mirrors. 启用: 13,464
repolist: 17,485
###yum-config-manager用法
yum-config-manager options:
--save save the current options (useful with --setopt)
--enable enable the specified repos (automatically saves)
--disable disable the specified repos (automatically saves)
--add-repo=ADDREPO add (and enable) the repo from the specified file or
url
【启用或禁用仓库 】
禁用源为 mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ 源标识就是这个源的ID
[root@node1 ~]# yum-config-manager --disable mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ #禁用
[root@node1 ~]# yum repolist all #查看结果为禁用
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识 源名称 状态
local my localserver 启用: 4,021
!mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ added from: https://mirrors.tuna.tsinghua 禁用
repolist: 4,021
启用源为 mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_
[root@node1 ~]# yum-config-manager --enable mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ #启用
[root@node1 ~]# yum repolist all #查看仓库状态
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识 源名称 状态
local my localserver 启用: 4,021
!mirrors.tuna.tsinghua.edu.cn_epel_7_x86_64_ added from: https://mirrors.tuna.tsinghu 启用: 13,464
repolist: 17,485