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

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

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

相关推荐

微软发布Win11/10 ISO镜像Defender更新,提升系统初始安全性

IT之家7月27日消息,除了Setup及WinRE更新外,NeoWin发现微软本周还针对Windows11/10/Server安装镜像发布了新的Defender安全智能...

微软革新Windows装机体验:内置应用全面升级,安全与便捷双提升

Windows内置应用迎来重大变革:更安全、更快速的初始体验如果您曾亲自安装过Windows11,或许注意到其内置应用并非开箱即用,而是一些占位程序,需要首次运行时从微软应用商店(Microsoft...

Hotpatch继续扩展 现在更多Windows PC在更新后无需重启

Windows11最近从其服务器版本中获得了一项非常重要的功能:Windows热补丁。该功能旨在通过允许操作系统在无需重启的情况下安装重要的安全更新来最大限度地减少停机时间和中断。最初,微软在...

微软承认Windows Server六月更新存在BUG:导致DHCP服务器故障

IT之家6月17日消息,科技媒体WindowsLatest今天(6月17日)发布博文,报道称微软承认6月WindowsServer更新存在BUG,可能导致DHCP服...

Windows Server2019安装Hyper-V的2个简单方法!

关于WindowsServer2019WindowsServer2019是微软发布的服务器操作系统,是WindowsServer2016的后续版本。它包含了许多新的特性和改进,适用于数据中心...

如何在不满足系统要求的旧计算机上安装 Windows 11 24H2

如果你想了解这个安装工具以及安装方法(老飞摄影微信公众号内提供安装包下载),请完整的看完后面的文字,以避免在安装过程当中出现问题。Windows11通常需要某些硬件功能,例如TPM和安全启动,...

第 137 期:微软表示 Windows 11 24H2 是迄今为止最稳定的版本

就在刚刚,微软“大言不惭”地声称,Windows1124H2是迄今为止最可靠的Windows版本。我们并不是说它很糟糕,因为我们每天的工作中也在使用它。上述言论只是一份微软的一份官方文件的一...

Windows 11 将推出带有“高级”选项的新设置页面

Windows11即将迎来一个包含一些高级功能的全新“设置”页面。严格来说,它并非全新功能。它更像是“开发者”栏目的重新设计,用户和开发者可以在其中调整各种附加功能。微软可能明白这些东西不仅对开发...

Windows server 2025 重复数据删除

一、概述windowsserver中的重复数据删除功能从windowsserver2012就开始支持了。Windowsserver中默认没有安装重复数据删除功能。在磁盘分区(卷)上启用重复...

Windows Server 2025预览版迎来更新,微软改善Insiders测试体验

在发布WindowsServer的build26040版本之际,微软公布了该产品的官方名称:WindowsServer2025。一同推出的,还有Windows11WindowsInsid...

升不升?Win11 24H2大范围推送了

微软在其官方支持文档中宣布,24H2版现在已经开始向运行Windows11原始版本、22H2和23H2版的合格设备推送。Windows11的24H2更新现已进入新的可用性阶段,这意味着更多符合条件...

微软发布Win11/10/Server安装镜像Defender更新

IT之家6月22日消息,继上个月为Lumma发布更新后,微软本月也为Windows11/10/Server安装镜像发布了新的Defender更新。此更新包很有必要,因为Wi...

第 81 期:微软最近的更新给 Windows Server 带来了 DHCP 问题

近日,微软确认,DHCP服务器服务可能会在WindowsServer安装2025年6月更新后停止响应或拒绝连接。DHCP问题会影响WindowsServer2025(KB50...

windws server 2012 R2 虚拟机windows server2019 经常断网事件

故障现象:在windowsserver2012R2的虚拟主机上面搭建一个Windowsserver2019的虚拟机系统用来做域控。安装完设置好防火墙和IP,经过测试是可以ping同正常访问...

微软扩展热补丁部署,现覆盖ARM架构Win11 24H2设备

IT之家7月9日消息,科技媒体NeoWin今天(7月9日)发布博文,报道称微软扩大热补丁(WindowsHotpatching)覆盖范围,在AMD和英特尔处理器设备外,现覆盖支...

取消回复欢迎 发表评论: