百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文

搭建本机和局域网yum源

nanshan 2024-12-01 01:35 11 浏览 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->使用

  1. 假定系统识别的镜像在/dev/cdrom
mount /dev/cdrom /mnt    // 挂载到mnt目录,mnt目录可以按自己习惯修改
  1. 备份原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,不赘述

  1. 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 
  1. 故采取了手动生成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就没有。
参考

  1. 下载工具
yum install createrepo    yum-utils -y
//yum-utils -y包含reposync 很重要
  1. 备份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
  1. 同步镜像到本地,包很大,约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
  1. 创建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     .
  1. 现场客户端备份、创建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

相关推荐

0722-6.2.0-如何在RedHat7.2使用rpm安装CDH(无CM)

文档编写目的在前面的文档中,介绍了在有CM和无CM两种情况下使用rpm方式安装CDH5.10.0,本文档将介绍如何在无CM的情况下使用rpm方式安装CDH6.2.0,与之前安装C5进行对比。环境介绍:...

ARM64 平台基于 openEuler + iSula 环境部署 Kubernetes

为什么要在arm64平台上部署Kubernetes,而且还是鲲鹏920的架构。说来话长。。。此处省略5000字。介绍下系统信息;o架构:鲲鹏920(Kunpeng920)oOS:ope...

生产环境starrocks 3.1存算一体集群部署

集群规划FE:节点主要负责元数据管理、客户端连接管理、查询计划和查询调度。>3节点。BE:节点负责数据存储和SQL执行。>3节点。CN:无存储功能能的BE。环境准备CPU检查JDK...

在CentOS上添加swap虚拟内存并设置优先级

现如今很多云服务器都会自己配置好虚拟内存,当然也有很多没有配置虚拟内存的,虚拟内存可以让我们的低配服务器使用更多的内存,可以减少很多硬件成本,比如我们运行很多服务的时候,内存常常会满,当配置了虚拟内存...

国产深度(deepin)操作系统优化指南

1.升级内核随着deepin版本的更新,会自动升级系统内核,但是我们依旧可以通过命令行手动升级内核,以获取更好的性能和更多的硬件支持。具体操作:-添加PPAs使用以下命令添加PPAs:```...

postgresql-15.4 多节点主从(读写分离)

1、下载软件[root@TX-CN-PostgreSQL01-252software]#wgethttps://ftp.postgresql.org/pub/source/v15.4/postg...

Docker 容器 Java 服务内存与 GC 优化实施方案

一、设置Docker容器内存限制(生产环境建议)1.查看宿主机可用内存bashfree-h#示例输出(假设宿主机剩余16GB可用内存)#Mem:64G...

虚拟内存设置、解决linux内存不够问题

虚拟内存设置(解决linux内存不够情况)背景介绍  Memory指机器物理内存,读写速度低于CPU一个量级,但是高于磁盘不止一个量级。所以,程序和数据如果在内存的话,会有非常快的读写速度。但是,内存...

Elasticsearch性能调优(5):服务器配置选择

在选择elasticsearch服务器时,要尽可能地选择与当前业务量相匹配的服务器。如果服务器配置太低,则意味着需要更多的节点来满足需求,一个集群的节点太多时会增加集群管理的成本。如果服务器配置太高,...

Es如何落地

一、配置准备节点类型CPU内存硬盘网络机器数操作系统data节点16C64G2000G本地SSD所有es同一可用区3(ecs)Centos7master节点2C8G200G云SSD所有es同一可用区...

针对Linux内存管理知识学习总结

现在的服务器大部分都是运行在Linux上面的,所以,作为一个程序员有必要简单地了解一下系统是如何运行的。对于内存部分需要知道:地址映射内存管理的方式缺页异常先来看一些基本的知识,在进程看来,内存分为内...

MySQL进阶之性能优化

概述MySQL的性能优化,包括了服务器硬件优化、操作系统的优化、MySQL数据库配置优化、数据库表设计的优化、SQL语句优化等5个方面的优化。在进行优化之前,需要先掌握性能分析的思路和方法,找出问题,...

Linux Cgroups(Control Groups)原理

LinuxCgroups(ControlGroups)是内核提供的资源分配、限制和监控机制,通过层级化进程分组实现资源的精细化控制。以下从核心原理、操作示例和版本演进三方面详细分析:一、核心原理与...

linux 常用性能优化参数及理解

1.优化内核相关参数配置文件/etc/sysctl.conf配置方法直接将参数添加进文件每条一行.sysctl-a可以查看默认配置sysctl-p执行并检测是否有错误例如设置错了参数:[roo...

如何在 Linux 中使用 Sysctl 命令?

sysctl是一个用于配置和查询Linux内核参数的命令行工具。它通过与/proc/sys虚拟文件系统交互,允许用户在运行时动态修改内核参数。这些参数控制着系统的各种行为,包括网络设置、文件...

取消回复欢迎 发表评论: