您的位置:首页 > 游戏 > 游戏 > 企业内网自建yum源 仓库 | nginx 反向代理方案

企业内网自建yum源 仓库 | nginx 反向代理方案

2024/10/6 20:29:17 来源:https://blog.csdn.net/wangrui1573/article/details/139115465  浏览:    关键词:企业内网自建yum源 仓库 | nginx 反向代理方案

文章目录

      • 1.背景概述
    • 方案二 Nginx代理法
      • 1. 安装ngnix
        • 1.1 安装nginx并启用
        • 1.2 修改ngnix配置文件
      • 2. 客户端修改repo文件
      • 3.客户端测试

1.背景概述

yum源是一个软件仓库,centos7 停更后,建议企业在内网自建软自己的软件仓库,一般有下列步骤:

  • 取得软件包文件,可以从安装镜像拷贝,本文使用rsync方式从互联网同步
  • 搭建网页文件服务器,本文使用nginx
  • 使用createrepo创建索引
  • 配置客户端yum.repo文件

方案二 Nginx代理法

使用nginx,就不需要同步到本地了,但确保你的ngnix服务器能上外网

但是源端挂了,你也炸了,也没有本地速度快

所以建议本地经常用的,同步到本地,比如mysql,docker,zabbix这些,其他的可以使用代理

这个方法就比较简单了

1. 安装ngnix

1.1 安装nginx并启用
yum -y install nginx
systemctl start nginx
systemctl enable nginx
1.2 修改ngnix配置文件
cd /etc/nginx/conf.d
vi yam.conf
#以下是文件代码server {listen 80;server_name  请修改我;access_log  /var/log/yum.log;location /rocky/ {proxy_pass http://mirrors.ustc.edu.cn/rocky/ ;}location /epel/ {proxy_pass http://mirrors.ustc.edu.cn/epel/ ;}#   没有本地文件就忽略#   location / {#          root /app/yumData/;#          autoindex on;             #开启索引功能#          autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)#          autoindex_localtime on;#   }
}#保存退出
nginx -s reload

在浏览器上访问下域名能否打开,如果打开有问题,请确保权限

nginx 所属,或者直接chown -R 755到目录,或者setenforce 0

2. 客户端修改repo文件

替换关键域名就好

[root@主机 ~]# vi /etc/yum.repos.d/rocky.repo
# rocky.repo
#
# The mirrorlist system uses the connecting IP address of the client and the
# update status of each mirror to pick current mirrors that are geographically
# close to the client.  You should use this for Rocky updates unless you are
# manually picking other mirrors.
#
# If the mirrorlist does not work for you, you can try the commented out
# baseurl line instead.[baseos]
name=Rocky Linux $releasever - BaseOS
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever$rltype
baseurl=http://请修改我/rocky/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
countme=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9[baseos-debug]
name=Rocky Linux $releasever - BaseOS - Debug
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever-debug$rltype
baseurl=http://请修改我/rocky/$releasever/BaseOS/$basearch/debug/tree/
gpgcheck=1
enabled=0
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9[baseos-source]
name=Rocky Linux $releasever - BaseOS - Source
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=BaseOS-$releasever-source$rltype
baseurl=http://请修改我/rocky/$releasever/BaseOS/source/tree/
gpgcheck=1
enabled=0
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9[appstream]
name=Rocky Linux $releasever - AppStream
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=AppStream-$releasever$rltype
baseurl=http://请修改我/rocky/$releasever/AppStream/$basearch/os/
gpgcheck=1
enabled=1
countme=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9[appstream-debug]
name=Rocky Linux $releasever - AppStream - Debug
#mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=AppStream-$releasever-debug$rltype

3.客户端测试

清理并重建缓存,安装软件会发现速度没有内网那么快了

清除yum缓存
yum clean all; yum makecache列出包内容
yum repolist allyum list available

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com