本地一键自建YUM源仓库服务器,并从阿里云进行自动更新
qiyuwang 2024-10-14 14:27 13 浏览 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左右),视网速而定,第二次或之后视更新数量而定。
相关推荐
- windows开启telnet服务,检测远程服务端口是否可以连通
-
本文介绍windwos开启telnet服务,telnet服务一般可以用于检测远程主机的某个端口服务是否可以连通,在日常的工作中,我们经常会遇到在本地的windows检测远程服务端口是否可以连通。win...
- 仅在Web登录新华三交换机条件下启用设备Telnet登录方式
-
概述Web登录新华三交换机可以在“网络-服务”页面中启用设备Telnet服务或SSH服务,也可以在“设备-管理员”设置管理员用户的可用服务,然而,在设备Web页面中,无法设置lineVTY用户线【l...
- 思科交换机,路由器如何关闭telnet 开启ssh服务
-
SSH为建立在应用层基础上的安全协议。SSH是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用SSH协议可以有效防止远程管理过程中的信息泄露问题。今天我们就来说说思科交换机,路...
- 智能化弱电行业常用的DOS命令,掌握了你也能成为...
-
前言在做智能化弱电项目时,前端摄像头设备安装结束后,我们会对网络摄像头进行调试,调试过程中会遇到前端摄像头没有图像或者图像出来了画面卡顿的现象。我们会采用ping命令来测试网络的连通性和网络承载能力。...
- 「干货」eNSP模拟器之配置Telnet登录
-
配置说明:配置Telnet,使R2(模拟PC)通过SW1登录到R1进行管理和配置。操作步骤:system-view##进入系统视图[Huawei]sysnameR1##改名为R1[R1]int...
- win11开启telnet服务怎么操作 win11打开telent指令是什么
-
telnet服务是我们在进行远程连接的时候,必须要打开的一项功能。但是有不少用户们不清楚在windows11系统中怎么开启telnet服务。今天小编就使用详细的图文教程,来给大家说明一下打开telen...
- 华三(H3C)交换机Telnet的远程登陆
-
一,配置交换机管理IP[SW1]vlan20//创建管理vlan[SW1]interfacevlan20//进入vlan接口[SW1-Vlanif20]ipaddress192.168....
- win10 telnet命令怎么查看端口是否打开
-
可能大家也会遇到这个问题,win10telnet命令查看端口是否打开的步骤是什么?具体方法如下:1、键盘输入快捷键WIN+R,打开运行窗口。2、输入cmd,点击确定按钮。3、弹出cmd命令行窗...
- Windows 7如何打开Telnet功能(win7系统打开telnet)
-
Windows7默认安装后是没有开启telnet客户端功能的,例如,我们在开始菜单中输入cmd,然后使用telnet命令,会弹出下图提示:‘telnet’不是内部或外部命令,也不是可运行程序或批处理文...
- 为锐捷路由器交换机开启web和telnet,实现轻松管理
-
笔者上一篇文章写了关于锐捷二层交换机配置教程,那么接下来讲一下锐捷的路由交换设备配置web、telnet技巧。同样,今天的教程也是基于命令行,比较简单,适合新手小白进行学习。准备工作配置前准备:con...
- 一文学会telnet命令的用途和使用方法
-
Telnet是一个古老的远程登录协议,可以让本地计算机获得远程计算机的工作能力。它采用了TCP的可靠连接方式,可以连接任何网络互通的远程计算机。不过由于它采用了明文传输方式,存在安全风险,目前已经很少...
- Telnet命令是什么?如何使用?(telnet命令在哪里开启)
-
telnet命令是一个常用的远程登陆工具,使用它,我们可以快捷地登陆远程服务器进行操作。那么如何使用telnet命令呢?首先,我们需要打开telnet功能,任何电脑默认是关闭此功能的,开启方式如下:打...
- win11系统如何开启telnet服务(拷贝版本)
-
我们要知道,Telnet协议是Internet远程登陆服务的标准协议,可以使用户在本地计算机上完成远程主机的工作,不过对于一些刚接触win11中文版系统的用户来说,可能还不知道telnet服务在哪...
- 如何开启telnet客户端(如何开启telnet服务)
-
Telnet协议是TCP/IP协议家族中的一员,是Internet远程登陆服务的标准协议和主要方式,Telnet是常用的远程控制Web服务器的方法。工作中经常用到telnet客户端,但在windows...
- Telnet 是什么,如何启用它?(telnet有什么用)
-
对于Internet等TCP/IP网络,Telnet是一个终端仿真程序。Telnet软件在您的系统上运行并将您的个人计算机链接到网络服务器。它将所有数据转换为纯文本这一事实被认为是易受...
你 发表评论:
欢迎- 一周热门
- 最近发表
- 标签列表
-
- navicat无法连接mysql服务器 (65)
- 下横线怎么打 (71)
- flash插件怎么安装 (60)
- lol体验服怎么进 (66)
- ae插件怎么安装 (62)
- yum卸载 (75)
- .key文件 (63)
- cad一打开就致命错误是怎么回事 (61)
- rpm文件怎么安装 (66)
- linux取消挂载 (81)
- ie代理配置错误 (61)
- ajax error (67)
- centos7 重启网络 (67)
- centos6下载 (58)
- mysql 外网访问权限 (69)
- centos查看内核版本 (61)
- ps错误16 (66)
- nodejs读取json文件 (64)
- centos7 1810 (59)
- 加载com加载项时运行错误 (67)
- php打乱数组顺序 (68)
- cad安装失败怎么解决 (58)
- 因文件头错误而不能打开怎么解决 (68)
- js判断字符串为空 (62)
- centos查看端口 (64)