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

本地一键自建YUM源仓库服务器,并从阿里云进行自动更新

nanshan 2024-10-13 03:47 24 浏览 0 评论

在企业中或内部数据中心,很多时候由于需要安装一些软件,缺乏依赖包,传统的方式是把原操作系统镜像挂载到系统中,再使用YUM进行安装,如果维护量太大就比较痛苦了。

经过几天的研究,目前我已经将自建YUM源仓库服务器做成了一个方便的Shell脚本,只需要1键运行即可构建属于本地的YUM源服务器。

效果媲美其他公共YUM源服务器。

第一步,我们先安装一台Centos Linux服务器,目前最新的是Centos 7.6。

第二步,选择GNOME桌面版作为本次YUM源服务器的操作系统。

第三步,以root用户登录到服务器,在/root目录下vi新建编辑一个1yum.sh之后:wq保存。

第四步,将后面的shell脚本复制到1yum.sh中。

第五步,使用chmod +x /root/1yum.sh

第六步,使用sh -x /root/1yum.sh 执行,完成后会自动重启。

客户端使用时,将client-centos.repo下载到/etc/yum.repos.d/后,使用yum clean all && yum makecache && yum repolist 命令重建本地缓存即可使用。

下面是命令,必须在命名为1yum.sh,并放在/root目录下,否则后面会出现错误,如果有阅读能力的也可以自行修改。

环境:YUM源本地服务器IP地址是10.0.4.48

本YUM源适用于:Centos、Redhat、Oracle等类redhat系的

[root@bogon ~]# cd ~

[root@bogon ~]# vi 1yum.sh

[root@bogon ~]# chmod +x 1yum.sh

[root@bogon ~]# sh -x 1yum.sh

下面是脚本,直接复制进1yum.sh里

#!/bin/bash
systemctl disable firewalld 
#禁用关闭防火墙
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config 
#禁用SELINUX,需要重启才会生效
echo "30 20 * * * /home/yum-update.sh >>/home/yum/yum-sync.txt 2>&1" >>/var/spool/cron/root 
#计划任务每天20点30分脚本自动定时从阿里云YUM源进行更新
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
#安装nginx需要使用阿里云epel源,下载源文件到目录另存为epel-7.repo文件
yum -y install nginx
#YUM安装nginx HTTP服务器
chkconfig --level 2345 nginx on 
#设置nginx为自启动服务 
tar -cvf /usr/share/nginx/html-dir.tar /usr/share/nginx/html 
#tar备份原nginx WEB访问目录到html-dir.tar文件 
rm -rf /usr/share/nginx/html 
#删除原nginx WEB访问目录 
mkdir -p /home/yum && cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak 
#新建YUM仓库存放目录,备份nginx配置文件
ln -s /home/yum /usr/share/nginx/html 
#软链接本次YUM仓库存放目录到nginx WEB访问目录
sed -i 's#location / {#location / { autoindex on;#g' /etc/nginx/nginx.conf
#更改nginx配置文件启用目录自动索引,否则会报403错误
crontab -l && systemctl list-unit-files |egrep 'nginx|firewalld' && cat /etc/selinux/config |grep 'SELINUX=disabled' 
#作为检查项,检查设置是否正确
sed -n '38,59p' /root/1yum.sh >>/home/yum/client-centos.repo 
#生成客户端的repo文件
sed -n '60,113p' /root/1yum.sh >>/home/yum-update.sh && chmod +x /home/yum-update.sh
#将yum update 另存为脚本,并给予可执行权限 by:stan liu create write date 20181206
yum -y install createrepo yum-utils 
#YUM安装 createrepo yum-utils配置工具(GNOME桌面环境已安装)
/home/yum-update.sh 
#执行同步阿里云YUM源更新的脚本
ln -s /home/yum/centos/6 /home/yum/centos/6Server && ln -s /home/yum/centos/7 /home/yum/centos/7Server 
#软链接方便Redhat系统进行更新
reboot 
#执行YUM更新脚本完成后重启服务器
##################### client yum repo ######################
# CentOS-Base.repo 
[base]
name=CentOS-$releasever - Base 
baseurl=http://10.0.4.48/centos/$releasever/$basearch/base/
gpgcheck=0
 
[updates]
name=CentOS-$releasever - Updates 
baseurl=http://10.0.4.48/centos/$releasever/$basearch/updates/
gpgcheck=0
 
[extras]
name=CentOS-$releasever - Extras 
baseurl=http://10.0.4.48/centos/$releasever/$basearch/extras/
gpgcheck=0
 
[epel]
name=CentOS-$releasever - Epel 
baseurl=http://10.0.4.48/centos/$releasever/$basearch/epel/
gpgcheck=0
############################################################
##################### yum update shell ##################### 
#!/bin/bash
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel-6.repo http://mirrors.aliyun.com/repo/epel-6.repo
sed -i -e 's#$releasever#6#g' -e 's#$basearch#i386#g' /etc/yum.repos.d/CentOS-Base.repo
sed -i 's#$basearch#i386#g' /etc/yum.repos.d/epel-6.repo
yum clean all
yum makecache
yum repolist
reposync -r base -p /home/yum/centos/6/i386
reposync -r extras -p /home/yum/centos/6/i386
reposync -r updates -p /home/yum/centos/6/i386
reposync -r epel -p /home/yum/centos/6/i386
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
wget -O /etc/yum.repos.d/epel-6.repo http://mirrors.aliyun.com/repo/epel-6.repo
sed -i 's#$releasever#6#g' /etc/yum.repos.d/CentOS-Base.repo
yum clean all
yum makecache
yum repolist
reposync -r base -p /home/yum/centos/6/x86_64
reposync -r extras -p /home/yum/centos/6/x86_64
reposync -r updates -p /home/yum/centos/6/x86_64
reposync -r epel -p /home/yum/centos/6/x86_64
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum clean all
yum makecache
yum repolist
reposync -r base -p /home/yum/centos/7/x86_64
reposync -r extras -p /home/yum/centos/7/x86_64
reposync -r updates -p /home/yum/centos/7/x86_64
reposync -r epel -p /home/yum/centos/7/x86_64
echo yum update complete
cd /home/yum/
ls ./*/*/*/base ./*/*/*/extras ./*/*/*/updates ./*/*/*/epel 
rm -rf ./*/*/*/*/repodata 
ls ./*/*/*/base ./*/*/*/extras ./*/*/*/updates ./*/*/*/epel 
createrepo ./centos/7/x86_64/base/
createrepo ./centos/7/x86_64/extras/
createrepo ./centos/7/x86_64/updates/
createrepo ./centos/7/x86_64/epel/
createrepo ./centos/6/x86_64/base/
createrepo ./centos/6/x86_64/extras/
createrepo ./centos/6/x86_64/updates/
createrepo ./centos/6/x86_64/epel/
createrepo ./centos/6/i386/base/
createrepo ./centos/6/i386/extras/
createrepo ./centos/6/i386/updates/
createrepo ./centos/6/i386/epel/
echo yum rpm index complete
############################################################

#其他注意事项:

#如果nginx的配置文件在/etc/nginx/conf.d/default.conf里,则将“location / {”改为“location / { autoindex on;”

#如果/etc/nginx/nginx.conf里用户是"user noboby;"或者"user nginx;"报403错误则改为user root;

#改完之后nginx -s reload 就可以访问了。

#本脚本是基于centos 7.5构建的,如果实在嫌麻烦可以直接使用centos 7.5

#这个脚本最大的方便之处可以将阿里云源链接改为其他源且每天自动更新,更新后的记录也可以方便的在yum-sync.txt里查看。

#第一次运行可能需要10多个小时(我这边64G左右),视网速而定,第二次或之后视更新数量而定。

相关推荐

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虚拟文件系统交互,允许用户在运行时动态修改内核参数。这些参数控制着系统的各种行为,包括网络设置、文件...

取消回复欢迎 发表评论: