手动配置本地yum源仓库(虚拟机)
参考链接:
https://www.cnblogs.com/baiquan/p/7545710.html
首先挂在iso镜像
mkdir –p /mnt/cdrom #创建目录用于挂载使用
mount /dev/cdrom /mnt/cdrom #将的iso镜像挂载到/mnt/cdrom目录下
vim /etc/yum.repos.d/centos-7-local.repo
[local]
name=centos 7 local repo
baseurl=file:///mnt/cdrom
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-7
enabled=1 #0为禁用,1为开启
查询确认:
yum repolist
创建本地yum源成功:
手动配置清华大学源
vim /etc/yum.repos.d/ tsinghua.repo
[tsinghua]
name=centos 7 tsinghua repo
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
enabled=1
查询确认:
yum repolist
用命令自动创建清华大学源仓库
#安装yum的扩展包
yum install yum-utils –y
#自动配置国内epel仓库:
yum-config-manager --add-repo=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
#手工添加秘钥:
vim /etc/yum.repos.d/mirrors.tuna.tsinghua.edu.cn_centos_7_os_x86_64_.repo
pgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPGKEY-EPEL-7
配置yum网络源:
安装网易的yum源
#首先备份原先的CentOS-Base.repo源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
#下载对应版本repo文件, 放入/etc/yum.repos.d/(操作前请做好相应备份)
wget –P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7-Base-163.repo
#运行以下命令生成缓存
yum clean all
yum makecache
#检查确认
同步外网源:
在企业实际应用场景中,仅仅靠光盘里面的RPM软件包是不能满足需要,我们可以把外网的YUM源中的所有软件包同步至本地,可以完善本地YUM源的软件包数量及完整性。
#安装reposync工具
yum install yum-utils createrepo -y
#同步源
- 创建本地目录
mkdir -p /data/{centos,epel}
- 同步yum源
reposync -r base -r updates -p /data/centos/
#生成元数据
createrepo /data/centos
#修改源地址
#清空缓存
yum clean all
#重建缓存
yum makecache
#再次查看确认
yum repolist
光驱挂载:
#临时挂载,重启linux机器后会失效(/dev/cdrom等同于/dev/sr0)
mount /dev/cdrom /mnt/crom
#永久挂载
vim /etc/fstab
/dev/cdrom /mnt/cdrom iso9660 defaults 0 0 #加入这行内容
卸载:
umount /mnt/cdrom