Linux系统下的centos7.9发行版搭建本地rpm包仓库

此篇文章将搭建本地园区内的rpm包仓库,此操作的目的一是为了本地服务器搭建服务时安装软件速度快,二是为了本地服务器的安全。

这里以centos7.9系统来搭建,通过网络阿里云镜像站的base仓库来做测试实验,因为博主存储有限,所以就一个base来测试,生产环境请根据需求搭建

一、首先对本地系统进行基础操作

1、先将服务器名称更改为centos7
hostnamectl set-hostname centos7	#临时更改
echo "centos7" > /etc/hostname		#永久更改
exec bash							#立即看到效果
2、将本地服务器IP固定
这里不再多说,能读这篇文档的Linux是有基础的
3、将默认yum仓库更换为阿里云镜像站的base仓库
mkdir /etc/yum.repos.d/CentOS.repos.backup
mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/CentOS.repos.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache
yum repolist

在此看到是aliyun就表示成功了

二、安装rpm包所需服务,配置本地文件

1、安装所需工具,并启动http服务
yum install -y yum-utils createrepo httpd
systemctl start httpd
systemctl enable httpd

在这里插入图片描述

2、创建本地目录并赋权
mkdir -p /var/www/html/repos/{base,extras,updates,epel}
chmod -R 755 /var/www/html/repos

在这里插入图片描述

三、同步rpm包仓库(这里同步时间比较长,单base就有一万多个包)

reposync -n -r base -p /var/www/html/repos/base
reposync -n -r extras -p /var/www/html/repos/extras
reposync -n -r updates -p /var/www/html/repos/updates
reposync -n -r epel -p /var/www/html/repos/epel

在这里插入图片描述

四、创建仓库元数据

createrepo /var/www/html/repos/base
createrepo /var/www/html/repos/extras
createrepo /var/www/html/repos/updates
createrepo /var/www/html/repos/epel

在这里插入图片描述

五、配置本地仓库

1、配置本地仓库文件
cat > /etc/yum.repos.d/local.repo <<EOF
[local-base]
name=Local Base
baseurl=file:///var/www/html/repos/base
enabled=1
gpgcheck=0

[local-extras]
name=Local Extras
baseurl=file:///var/www/html/repos/extras
enabled=1
gpgcheck=0

[local-updates]
name=Local Updates
baseurl=file:///var/www/html/repos/updates
enabled=1
gpgcheck=0

[local-epel]
name=Local EPEL
baseurl=file:///var/www/html/repos/epel
enabled=1
gpgcheck=0
EOF
2、清楚缓存并重新加载
yum clean all
yum makecache

六、设置同步更新

1、创建同步更新脚本,并赋权
cat > /usr/local/bin/repo-sync.sh <<EOF
#!/bin/bash
reposync -n -r base -p /var/www/html/repos/base
createrepo --update /var/www/html/repos/base

reposync -n -r extras -p /var/www/html/repos/extras
createrepo --update /var/www/html/repos/extras

reposync -n -r updates -p /var/www/html/repos/updates
createrepo --update /var/www/html/repos/updates

reposync -n -r epel -p /var/www/html/repos/epel
createrepo --update /var/www/html/repos/epel
EOF

chmod +x /usr/local/bin/repo-sync.sh
2、添加cron任务计划
echo "0 3 * * * root /usr/local/bin/repo-sync.sh" > /etc/cron.d/repo-sync

在这里插入图片描述

七、配置防火墙规则,并通过其他终端访问该仓库

1、永久允许HTTP服务通过,重新加载,并验证是否放通
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
firewall-cmd --list-services
2、关闭selinux服务
setenforce 0
getenforce 

在这里插入图片描述

3、在其他服务器上配置yum仓库的本地位置的文件
cat > /etc/yum.repos.d/local-network.repo <<EOF
[local-base]
name=Local Base
baseurl=http://<your-server-ip>/repos/base
enabled=1
gpgcheck=0

[local-extras]
name=Local Extras
baseurl=http://<your-server-ip>/repos/extras
enabled=1
gpgcheck=0

[local-updates]
name=Local Updates
baseurl=http://<your-server-ip>/repos/updates
enabled=1
gpgcheck=0

[local-epel]
name=Local EPEL
baseurl=http://<your-server-ip>/repos/epel
enabled=1
gpgcheck=0
EOF
4、清除缓存,并验证
yum clean all
yum makecache
yum repolist

新手运维,写的差,大佬勿喷!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值