搭建本机和局域网yum源 搭建本地yum
qiyuwang 2024-10-14 14:28 13 浏览 0 评论
背景
搭建本地yum源大概有下面三种情况:
- ISO镜像搭建本机使用的yum仓库
- ISO镜像搭建局域网使用的yum仓库
- 第三方镜像搭建局域网使用的yum仓库
不管怎样,核心有两点:yum包仓库搭建、repo配置url。
另外,由于包受限于选择的仓库来源,故包的版本取决于选择的仓库,极有可能不是最新版、或者不是自己想要的版本。比如ansible在本次所选择的epel源版本是2.7.2,这是老版本
[root@node1 yum.repos.d]#yum list|grep ansible
ansible.noarch 2.7.2-1.el7 @epel
ansible.noarch 2.9.15-1.el7 epel
ansible-doc.noarch 2.9.15-1.el7 epel
ansible-inventory-grapher.noarch 2.4.4-1.el7 epel
ansible-lint.noarch 3.5.1-1.el7 epel
ansible-openstack-modules.noarch 0-20140902git79d751a.el7 epel
ansible-python3.noarch 2.9.15-1.el7 epel
ansible-review.noarch 0.13.4-1.el7 epel
centos-release-ansible-27.noarch 1-1.el7 extras
centos-release-ansible-28.noarch 1-1.el7 extras
centos-release-ansible-29.noarch 1-1.el7 extras
centos-release-ansible26.noarch 1-3.el7.centos extras
kubernetes-ansible.noarch 0.6.0-0.1.gitd65ebd5.el7 epel
python2-ansible-runner.noarch 1.0.1-1.el7 epel
python2-ansible-tower-cli.noarch 3.3.9-1.el7 epel
vim-ansible.noarch 3.0-1.el7 epel
[root@node1 yum.repos.d]#rpm -qa|grep ansible
ansible-2.7.2-1.el7.noarch
环境
[root@node1 yum.repos.d]#cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
无防火墙、selinux关闭
搭建步骤
1. ISO镜像搭建本机使用的yum仓库,最简单
挂载镜像->修改repo->使用
- 假定系统识别的镜像在/dev/cdrom
mount /dev/cdrom /mnt // 挂载到mnt目录,mnt目录可以按自己习惯修改
- 备份原repo文件,创建新的repo文件
mkdir /etc/yum.repos.d/bak&&mv /etc/yum.repos.d/*repo /etc/yum.repos.d/bak
cat <<EOF >yum.repo
[local]
name=Local_centos
baseurl=file:///mnt //mnt是挂载目录
enable=1
gpcheck=0
EOF
3.使用
yum clean all //删除缓存
[root@node2 yum.repos.d]# yum repolist //查看仓库情况
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
local Local_centos 4,070
repolist: 4,070
yum install * //安装
2. ISO镜像搭建局域网使用的yum仓库
此步骤需要配合http服务,推荐nginx,不赘述
- nginx改局域网yum仓库的html路径。
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
autoindex on; //重要
root /mnt/; # (这里请换成你的实际目录路径)
}
}
}
理论上加入server{}内容,nginx -t检查错语法,重启nginx即可,但是这样修改后在客户端总是404
[root@node2 yum.repos.d]# cat yum.repo //客户端已备份原有repo,创建repo配置
[centos]
name=Local_centos
baseurl=http://192.168.44.11/
enable=1
gpcheck=0
404报错
[root@node2 yum.repos.d]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
http://192.168.44.11/yum/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
正在尝试其它镜像。
To address this issue please refer to the below wiki article
https://wiki.centos.org/yum-errors
If above article doesn't help to resolve this issue please use https://bugs.centos.org/.
元数据缓存已建立
猜想原因是nginx为yum安装,/etc/nginx/nginx.conf加入的server配置其实根本没有生效,验证手段:改端口80位8081,重启服务,查看端口,发现仍旧是80。说明猜想正确。
[root@node1 yum.repos.d]#netstat -antp|grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2883/nginx: master
- 故采取了手动生成yum仓库的办法
- 进入nginx默认html目录,手动创建包仓库信息
cd /usr/share/nginx/html/
mkdir yum
ln -s /mnt/Packages Packages //关键,创建包的软连接。直接拷贝过来也行
createrepo yum/ //创建仓库索引信息,createrepo可能需要安装
createrepo之后,yum的目录结构:包、html索引
[root@node1 logs]#ll /usr/share/nginx/html/yum/
总用量 4
lrwxrwxrwx 1 root root 13 11月 26 19:08 Packages -> /mnt/Packages
drwxr-xr-x 2 root root 4096 11月 26 19:10 repodata
修改客户端repo配置文件的url目录
[root@node2 yum.repos.d]# cat yum.repo //客户端已备份原有repo,创建repo配置
[centos]
name=Local_centos
baseurl=http://192.168.44.11/yum //比之前多了yum
enable=1
gpcheck=0
客户端再次yum clean all和yum makecache不再报错
[root@node2 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: centos
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@node2 yum.repos.d]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
centos | 2.9 kB 00:00:00
元数据缓存已建立
[root@node2 yum.repos.d]# yum repolist
已加载插件:fastestmirror
Determining fastest mirrors
centos | 2.9 kB 00:00:00
centos/primary_db | 3.3 MB 00:00:00
源标识 源名称 状态
centos Local_centos 4,070
repolist: 4,070
3. 第三方镜像搭建局域网使用的yum仓库,比如阿里云repo和epel
举一反三,由步骤2引出第三个方法,如果有第三方的包,那本地全部下载后重复步骤2,创建包目录、仓库索引页。这样会生成一个更全的仓库,因为毕竟centos镜像文件还是会缺包,比如nginx就没有。
参考
- 下载工具
yum install createrepo yum-utils -y
//yum-utils -y包含reposync 很重要
- 备份repo,下载阿里云repo/epel
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@node1 yum.repos.d]#ll
总用量 12
drwxr-xr-x 2 root root 263 11月 26 20:36 bak
-rw-r--r-- 1 root root 2523 6月 16 2018 CentOS-Base.repo
-rw-r--r-- 1 root root 664 5月 11 2018 epel.repo
- 同步镜像到本地,包很大,约30G。
[root@prometheus yum.repos.d]# yum clean all #清除之前的yum源缓存
[root@prometheus yum.repos.d]# yum makecache #创建缓存
[root@prometheus yum.repos.d]# yum repolist #查看当前可用的YUM源
cd ~ //切换到用户家目录
[root@prometheus ~]# reposync -r base #reposync将根据刚下载的repo下载rpm包到指定文件夹
[root@prometheus ~]# reposync -r extras
[root@prometheus ~]# reposync -r updates
[root@prometheus ~]# reposync -r epel
- 创建yum仓库索引
[root@prometheus ~]# cd /root/base
[root@prometheus ~]# createrepo ./
[root@prometheus ~]# cd /root/extras
[root@prometheus ~]# createrepo ./
[root@prometheus ~]# cd /root/updates
[root@prometheus ~]# createrepo ./
[root@prometheus ~]# cd /root/epel
[root@prometheus ~]# createrepo ./
此时/root/下面主要目录是下面四个,每个目录下面会有Packages和repodata两个目录,打包拷贝到现场。
9.0G ./base
748M ./extras
3.4G ./updates
16G ./epel
29G .
- 现场客户端备份、创建repo配置文件。
5.1 无nginx,只创建本机仓库 ,即本机就是客户端 。 解压包到/root/yum
[root@node1 ~]# vim /etc/yum.repos.d/base.repo
[base]
name=CentOS-Base
baseurl=file:///root/yum/base
path=/
enabled=1 #是否将该仓库做为软件包提供源
gpgcheck=0 #是否进行gpg校验
[updates]
name=CentOS-Updates
baseurl=file:///root/yum/updates
path=/
enabled=1
gpgcheck=0
[extras]
name=CentOS-Extras
baseurl=file:///root/yum/extras
path=/
enabled=1
gpgcheck=0
[root@node1 ~]# vim /etc/yum.repos.d/epel.repo
[epel]
name=CentOS-Epel
baseurl=file:///root/yum/epel
path=/
enabled=1
gpgcheck=0
使用前
yum clean all&&yum makecache
5.2 有nginx,此时可以搭建局域网仓库
解压包到nginx的默认html目录,如/usr/share/nginx/html/yum/
[root@node1 ~]# vim /etc/yum.repos.d/base.repo
[base]
name=CentOS-Base
baseurl=http://192.168.44.11/base
path=/
enabled=1 #是否将该仓库做为软件包提供源
gpgcheck=0 #是否进行gpg校验
[updates]
name=CentOS-Updates
baseurl=http://192.168.44.11/updates
path=/
enabled=1
gpgcheck=0
[extras]
name=CentOS-Extras
baseurl=http://192.168.44.11/extras
path=/
enabled=1
gpgcheck=0
[root@node1 ~]# vim /etc/yum.repos.d/epel.repo
[epel]
name=CentOS-Epel
baseurl=http://192.168.44.11/epel
path=/
enabled=1
gpgcheck=0
使用前
yum clean all&&yum makecache
相关推荐
- windows开启telnet服务,检测远程服务端口是否可以连通
-
本文介绍windwos开启telnet服务,telnet服务一般可以用于检测远程主机的某个端口服务是否可以连通,在日常的工作中,我们经常会遇到在本地的windows检测远程服务端口是否可以连通。win...
- 仅在Web登录新华三交换机条件下启用设备Telnet登录方式
-
概述Web登录新华三交换机可以在“网络-服务”页面中启用设备Telnet服务或SSH服务,也可以在“设备-管理员”设置管理员用户的可用服务,然而,在设备Web页面中,无法设置lineVTY用户线【l...
- 思科交换机,路由器如何关闭telnet 开启ssh服务
-
SSH为建立在应用层基础上的安全协议。SSH是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用SSH协议可以有效防止远程管理过程中的信息泄露问题。今天我们就来说说思科交换机,路...
- 智能化弱电行业常用的DOS命令,掌握了你也能成为...
-
前言在做智能化弱电项目时,前端摄像头设备安装结束后,我们会对网络摄像头进行调试,调试过程中会遇到前端摄像头没有图像或者图像出来了画面卡顿的现象。我们会采用ping命令来测试网络的连通性和网络承载能力。...
- 「干货」eNSP模拟器之配置Telnet登录
-
配置说明:配置Telnet,使R2(模拟PC)通过SW1登录到R1进行管理和配置。操作步骤:system-view##进入系统视图[Huawei]sysnameR1##改名为R1[R1]int...
- win11开启telnet服务怎么操作 win11打开telent指令是什么
-
telnet服务是我们在进行远程连接的时候,必须要打开的一项功能。但是有不少用户们不清楚在windows11系统中怎么开启telnet服务。今天小编就使用详细的图文教程,来给大家说明一下打开telen...
- 华三(H3C)交换机Telnet的远程登陆
-
一,配置交换机管理IP[SW1]vlan20//创建管理vlan[SW1]interfacevlan20//进入vlan接口[SW1-Vlanif20]ipaddress192.168....
- win10 telnet命令怎么查看端口是否打开
-
可能大家也会遇到这个问题,win10telnet命令查看端口是否打开的步骤是什么?具体方法如下:1、键盘输入快捷键WIN+R,打开运行窗口。2、输入cmd,点击确定按钮。3、弹出cmd命令行窗...
- Windows 7如何打开Telnet功能(win7系统打开telnet)
-
Windows7默认安装后是没有开启telnet客户端功能的,例如,我们在开始菜单中输入cmd,然后使用telnet命令,会弹出下图提示:‘telnet’不是内部或外部命令,也不是可运行程序或批处理文...
- 为锐捷路由器交换机开启web和telnet,实现轻松管理
-
笔者上一篇文章写了关于锐捷二层交换机配置教程,那么接下来讲一下锐捷的路由交换设备配置web、telnet技巧。同样,今天的教程也是基于命令行,比较简单,适合新手小白进行学习。准备工作配置前准备:con...
- 一文学会telnet命令的用途和使用方法
-
Telnet是一个古老的远程登录协议,可以让本地计算机获得远程计算机的工作能力。它采用了TCP的可靠连接方式,可以连接任何网络互通的远程计算机。不过由于它采用了明文传输方式,存在安全风险,目前已经很少...
- Telnet命令是什么?如何使用?(telnet命令在哪里开启)
-
telnet命令是一个常用的远程登陆工具,使用它,我们可以快捷地登陆远程服务器进行操作。那么如何使用telnet命令呢?首先,我们需要打开telnet功能,任何电脑默认是关闭此功能的,开启方式如下:打...
- win11系统如何开启telnet服务(拷贝版本)
-
我们要知道,Telnet协议是Internet远程登陆服务的标准协议,可以使用户在本地计算机上完成远程主机的工作,不过对于一些刚接触win11中文版系统的用户来说,可能还不知道telnet服务在哪...
- 如何开启telnet客户端(如何开启telnet服务)
-
Telnet协议是TCP/IP协议家族中的一员,是Internet远程登陆服务的标准协议和主要方式,Telnet是常用的远程控制Web服务器的方法。工作中经常用到telnet客户端,但在windows...
- Telnet 是什么,如何启用它?(telnet有什么用)
-
对于Internet等TCP/IP网络,Telnet是一个终端仿真程序。Telnet软件在您的系统上运行并将您的个人计算机链接到网络服务器。它将所有数据转换为纯文本这一事实被认为是易受...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- navicat无法连接mysql服务器 (65)
- 下横线怎么打 (71)
- flash插件怎么安装 (60)
- lol体验服怎么进 (66)
- ae插件怎么安装 (62)
- yum卸载 (75)
- .key文件 (63)
- cad一打开就致命错误是怎么回事 (61)
- rpm文件怎么安装 (66)
- linux取消挂载 (81)
- ie代理配置错误 (61)
- ajax error (67)
- centos7 重启网络 (67)
- centos6下载 (58)
- mysql 外网访问权限 (69)
- centos查看内核版本 (61)
- ps错误16 (66)
- nodejs读取json文件 (64)
- centos7 1810 (59)
- 加载com加载项时运行错误 (67)
- php打乱数组顺序 (68)
- cad安装失败怎么解决 (58)
- 因文件头错误而不能打开怎么解决 (68)
- js判断字符串为空 (62)
- centos查看端口 (64)