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

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

qiyuwang 2024-10-14 14:27 15 浏览 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左右),视网速而定,第二次或之后视更新数量而定。

相关推荐

基于Docker方式安装与部署Camunda流程引擎

1Camunda简介官网:https://docs.camunda.org/manual/7.19/installation/docker/Camunda是一个轻量级、开源且高度灵活的工作流和决策自...

宝塔Linux面板如何部署Java项目?(宝塔面板 linux)

通过宝塔面板部署Java还是很方便的,至少不需要自己输入tomcat之类的安装命令了。在部署java项目前,我还是先说下目前的系统环境,如果和我的系统环境不一样,导致部署不成功,那你可能需要去找其他资...

浪潮服务器如何用IPMI安装Linux系统

【注意事项】此处以浪潮服务器为例进行演示所需使用的软件:Chrome浏览器个人PC中需要预先安装java,推荐使用jdk-8u181-windows-x64.exe【操作步骤】1、在服务器的BIOS中...

Centos7环境Hadoop3集群搭建(hadoop集群环境搭建实验报告)

由于项目需要存储历史业务数据,经过评估数据量会达到100亿以上,在原有mongodb集群和ES集群基础上,需要搭建Hbase集群进行调研,所以首先总结一下Hadoop集群的搭建过程。一、三个节点的集群...

Hadoop高可用集群搭建及API调用(hadoop高可用原理)

NameNodeHA背景在Hadoop1中NameNode存在一个单点故障问题,如果NameNode所在的机器发生故障,整个集群就将不可用(Hadoop1中虽然有个SecorndaryNameNo...

使用Wordpress搭建一个属于自己的网站

现在开源的博客很多,但是考虑到wordpress对网站的seo做的很好,插件也多。并且全世界流量排名前1000万的网站有33.4%是用Wordpress搭建的!所以尝试用Wordpress搭建一个网站...

Centos 安装 Jenkins(centos 安装ssh)

1、Java安装查看系统是否已安装Javayumlistinstalled|grepjava...

Java教程:gitlab-使用入门(java中的git)

1导读本教程主要讲解了GitLab在项目的环境搭建和基本的使用,可以帮助大家在企业中能够自主搭建GitLab服务,并且可以GitLab中的组、权限、项目自主操作...

Dockerfile部署Java项目(docker部署java应用)

1、概述本文主要会简单介绍什么是Docker,什么是Dockerfile,如何安装Docker,Dockerfile如何编写,如何通过Dockerfile安装jar包并外置yaml文件以及如何通过do...

如何在Eclipse中搭建Zabbix源码的调试和开发环境

Zabbix是一款非常优秀的企业级软件,被设计用于对数万台服务器、虚拟机和网络设备的数百万个监控项进行实时监控。Zabbix是开放源码和免费的,这就意味着当出现bug时,我们可以很方便地通过调试源码来...

Java路径-02-Java环境配置(java环境搭建及配置教程)

1Window环境配置1.1下载...

35.Centos中安装python和web.py框架

文章目录前言1.Centos7python:2.Centos8python:3.进行下载web.py框架然后应用:4.安装好之后进行验证:5.总结:前言...

《我的世界》服务器搭建(我的世界服务器如何搭建)

1.CentOS7环境1.1更改YUM源#下载YUM源文件curl-o/etc/yum.repos.d/CentOS-Base.repohttps://mirrors.aliyun.com...

CentOS 7 升级 GCC 版本(centos7.4升级7.5)

1.GCC工具介绍GCC编译器:...

Linux安装Nginx详细教程(linux安装配置nginx)

环境准备1.因为Nginx依赖于gcc的编译环境,所以,需要安装编译环境来使Nginx能够编译起来。命令:yuminstallgcc-c++显示完毕,表示安装完成:2.Nginx的http模块需要...

取消回复欢迎 发表评论: