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

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

nanshan 2024-10-13 03:47 16 浏览 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左右),视网速而定,第二次或之后视更新数量而定。

相关推荐

在 Ubuntu 上安装 Zabbix(以 Zabbix 6.4 LTS 版本为例)

Zabbix是一个流行的开源监控解决方案,能够监控各种网络参数和服务器健康状态。一、环境准备系统要求Ubuntu20.04/22.04LTS至少2GBRAM(生产环境建议4GB+)至少1...

如何在 Ubuntu 24.04 服务器上安装 Apache Solr

ApacheSolr是一个免费、开源的搜索平台,广泛应用于实时索引。其强大的可扩展性和容错能力使其在高流量互联网场景下表现优异。Solr基于Java开发,提供了分布式索引、复制、负载均衡及自...

如何在 Ubuntu 24.04 LTS 或 22.04/20.04 上安装 Apache Maven

Maven是由Apache托管的开源工具,用于管理Java项目。它包含一个项目对象模型(POM):一个配置文件(XML),其中包含项目的基本信息,包括配置、项目依赖项等。Maven可以处理...

Cursor的终极对手——Trae Pro最新系统提示词

前段时间,字节的AI编程神器Trae国际版,终于甩出了Pro订阅计划!很多对它又爱又恨的小伙伴,直呼:终于等到你。爱它,是因为Trae长期免费+体验真香;恨它?还不是那该死的排队等待,...

AI系统提示词:V0(ai代码提示)

以下是对V0系统提示词(SystemPrompt)的分部分讲解与解读,帮助你理解其核心内容和设计意图。V0系统提示词##CoreIdentity-Youarev0,Vercel&...

8岁男童失踪第13天,搜救人员发现可疑水库,更恶心的事情发生了

Lookingatyourrequest,Ineedtorewritethearticleaboutthe8-year-oldmissingboywhilemaking...

docker常用指令及安装rabbitMQ(docker安装zabbix)

一、docker常用指令启动docker:systemctlstartdocker停止docker:systemctlstopdocker重启docker:systemctlrestart...

三步教你用Elasticsearch+PyMuPDF实现PDF大文件秒搜!

面对100页以上的大型PDF文件时,阅读和搜索往往效率低下。传统关系型数据库在处理此类数据时容易遇到性能瓶颈,而Elasticsearch凭借其强大的全文检索和分布式架构,成为理想解决方案。通过...

ElasticSearch中文分词插件(IK)安装

坚持原创,共同进步!请关注我,后续分享更精彩!!!前言ElasticSearch默认的分词插件对中文支持很不友好。一段话按规则会以每个中文字符来拆解,再分别建立倒排索引。如"中华人民共和国国歌...

SpringBoot使用ElasticSearch做文档对象的持久化存储?

ElasticSearch是一个基于Lucene的开源搜索引擎,广泛应用于日志分析、全文搜索、复杂查询等领域,在有些场景中使用ElasticSearch进行文档对象的持久化存储是一个很不错的选择...

Elasticsearch数据迁移方案(elasticsearch copyto)

前言最近小编要去给客户部署一套系统涉及到了Mysql和ES数据的迁移,下面就给大家分享一下ES数据迁移的几套方案,根据具体的使用场景来选择不同的迁移方案能使你事倍功半,话多说下面就一一介绍。Elast...

Rancher部署单体ElasticSearch(rancher2.5部署)

Rancher是k8s图形管理界面,之前曾有写文章介绍如何安装。ElasticSearch是热门搜索引擎,很多地方都有用到,常规安装部署略显繁琐,本文介绍在k8s下用rancher简易部署ES。1.在...

Elasticsearch在Java项目的搜索实践:从零开始构建高效搜索系统

Elasticsearch在Java项目中的搜索实践:从零开始构建高效搜索系统在现代的Java项目中,数据量激增,传统的数据库查询方式已经无法满足快速检索的需求。这时,Elasticsearch(E...

小白入门-Kibana安装(kibana安装配置)

一Kibana基础1.1介绍Kibana是一款免费且开放的前端应用程序,其基础是ElasticStack,可以为Elasticsearch中索引的数据提供搜索和数据可视化功能。Kiban...

Docker上使用Elasticsearch,Logstash,Kibana

在对一个项目做性能测试时我需要处理我们web服务器的访问日志来分析当前用户的访问情况。因此,我想这是试用ELK的一个好机会。ELK栈首先要注意的是使用它是非常简单的。从决定使用ELK到在本机上搭一个...

取消回复欢迎 发表评论: