当前位置: 首页 > news >正文

Centos 用http ftp搭建本地yum源 保姆级教程

Centos7 用http ftp搭建本地yum源

文章标签: centos linux 服务器

一、环境准备

1.准备2-3台虚拟机,一台为服务端(安装yum源),其余的为客户端(测试yum源安装结果),最好是同网段的。

IP地址 角色 备注

192.168.116.5 服务端 将完整镜像上传到这台机器

192.168.116.15 客户端

2.准备镜像文件,这里以CentOS-7-x86_64-2009,当然最好是使用CentOS-7-x86_64-Everything-2207-02.iso(这是完整版,包含了所有软件组件,当然体积也庞大,高达9.58G。对完整版安装盘的软件进行补充,集成所有软件;不要使用mini版)

3.准备远程软件,secucrt或者FinalShell、xshell都可

4.关闭防火墙,每一台都要关闭,包括selinux。

[root@test1 yum.repos.d]# systemctl stop firewalld

[root@test1 yum.repos.d]# systemctl disabled firewalld    //设置防火墙开机不自启

root@test1 yum.repos.d]# setenforce 0        //将selinux临时状态调整为开启

[root@test1 yum.repos.d]# getenforce        //查看selinux状态

5.备份yum源

[root@test1 ~]# cd /etc/yum.repos.d   //yum的配置文件所在

[root@test1 yum.repos.d]# mkdir bak

[root@test1 yum.repos.d]# mv *.repo bak/

[root@test1 yum.repos.d]# ls

bak

//注每台机器都要进行这一步操作

6.创建yum_http.repo文件 (本地yum源)

[root@test1 yum.repos.d]# vi yum_http.repo

将一下内容写入

[centos]

name=centos       

baseurl=file:///opt/centos

gpgcheck=0

enabled=1

7.创建目录将镜像上传至/opt/centos 

[root@test1 yum.repos.d]# mkdir  /opt/centos

[root@test1 yum.repos.d]# cd /opt/centos

[root@test1 centos]# ls

CentOS-7-x86_64-DVD-2009.iso  

[root@test1 centos]# mount /opt/centos/CentOS-7-x86_64-DVD-2009.iso /opt/centos    //挂载镜像文件,简单挂载mount: /dev/loop0 写保护,将以只读方式挂载 

8.安装createrepo  

[root@test1 html]#  yum install -y createrepo  //利用createrepo 创建yum源仓

二、用http服务,配置yum源

1.安装httpd服务

[root@test1 yum.repos.d]# yum -y install httpd

2.配置httpd服务

[root@test1 ~]# cd /var/www/html/            //进入到httpd的默认目录

将/opt/centos下挂载的文件软连接到http默认访问目录下,当然也可以使用cp命令,不过镜像文件较大,使用软连接更快

[root@test1 html]# ln -s /opt/centos/  /var/www/html/

[root@test1 html]# ll

总用量 0

lrwxrwxrwx 1 root root   12 7月   8 16:06 centos -> /opt/centos/

或者cp 复制

[root@test1 html]# mkdir centos

[root@test1 html]# cp -r /opt/centos/*  /var/www/html/centos

[root@test1 html]# createrepo  /var/www/html/centos

Spawning worker 0 with 993 pkgs

Spawning worker 1 with 993 pkgs

Spawning worker 2 with 993 pkgs

Spawning worker 3 with 992 pkgs

3.启动httpd服务

[root@test1 yum.repos.d]# systemctl start httpd

可以在网页上测试一下http://192.168.168.5:8080/centos

4.另外找一台服务器,修改http.repo(这里以自己创建的名字为准)文件中的baseurl为服务端ip

[root@test3 yum.repos.d]# vim http.repo

[centos]

name=centos

baseurl=http://192.168.168.5:8080/centos    

gpgcheck=0

enabled=1

最后做测试

[root@test3 yum.repos.d]# yum -y install vim //可以安装则代表成功

  • 用vsftpd配置yum源

1.安装vsftpd服务

[root@test1 yum.repos.d]# yum -y install vsftpd

2.配置vsftpd服务

[root@test1 ~]# cd /var/ftp/pub/            //进入到vsftpd的默认目录

将/opt/centos下挂载的文件软连接到ftp默认访问目录下,当然也可以使用cp命令,不过镜像文件较大,使用软连接更快

[root@test1 pub]# ln -s /opt/centos/   /var/ftp/pub/

[root@test1 pub]# ll

总用量 0

lrwxrwxrwx 1 root root   12 7月   8 16:06 centos -> /opt/centos/

或者cp 复制

[root@test1 pub]# mkdir centos

[root@test1 pub]# cp -r /opt/centos/*   /var/ftp/pub/centos

用 createrepo 创建仓库

[root@test1 pub]# createrepo /var/ftp/pub/

Spawning worker 0 with 993 pkgs

Spawning worker 1 with 993 pkgs

Spawning worker 2 with 993 pkgs

Spawning worker 3 with 992 pkgs

3.启动vsftpd服务

[root@test1 yum.repos.d]# systemctl start httpd

可以在网页上测试一下ftp://192.168.168.5/pub 有内容则代表成功

4.另外找一台服务器,修改http.repo(这里以自己创建的名字为准)文件中的baseurl为服务端ip

[root@test3 yum.repos.d]# vi ftp.repo

[ftpyum]

name=ftpyum

baseurl=ftp://192.168.168.5/pub

enabled=1

gpgcheck=0

最后做测试

[root@test3 yum.repos.d]# yum -y install vim //可以安装则代表成功

http://www.xdnf.cn/news/1279495.html

相关文章:

  • QML开发:动画元素
  • 企业高性能web服务器Nginx的详细部署(实战篇)
  • [4.2-2] NCCL新版本的register如何实现的?
  • ResponseBodyAdvice是什么?
  • ChatML vs Harmony:深度解析OpenAI全新对话结构格式的变化
  • ARM基础概念 day51
  • Redis应⽤-缓存与分布式锁
  • Vue3从入门到精通:3.1 性能优化策略深度解析
  • 基于SpringBoot+Uniapp的血压监控小程序(Echarts图形化分析)
  • OV5640 相机开发流程
  • Apollo平台下相机和激光雷达手眼联合标定
  • 游戏引擎(Unreal Engine、Unity、Godot等)大对比:选择最适合你的工具
  • 2025世界机器人大会,多形态机器人开启商业化落地浪潮
  • ubuntu24.04设置登陆背景图片
  • 工业相机与智能相机的区别
  • word的正则替换
  • 《解锁 C++ 进阶密码:引用补充与内联函数、nullptr 核心用法》
  • 【测试报告】SoundWave(Java+Selenium+Jmeter自动化测试)
  • 2025 年国内可用 Docker 镜像加速器地址
  • 前端组件库双雄对决:Bootstrap vs Element UI 完全指南
  • Flink TableAPI 按分钟统计数据量
  • Spring AI赋能图像识别:大数据模型驱动下的智能化变革
  • SAE J2716多协议网关的硬件架构与实时协议转换机制解析
  • calamine读取xlsx文件的方法比较
  • 华为虚拟防火墙配置案例详解
  • 未来物联网大模型:物联网硬件+底层驱动+AI 自动生成和调优LUA脚本,
  • 数据备份与进程管理
  • TikTok登录时显示“访问太频繁,请稍后再试”该怎么办?
  • 【数据库】如何使用一款轻量级数据库SqlSugar进行批量更新,以及查看最终的Sql操作语句
  • 【车联网kafka】Kafka核心架构与实战经验(第三篇)