为离线的bcliunx euler&龙晰 配置 yum源 nginx代理

需求描述:

(1)192.168.10.201可以访问外网

(2)192.168.10.9 无法访问外网

(3) 在 192.168.10.201 上配置 nginx 代理(docker 容器启动), 代理http://mirrors.cmecloud.cn/bclinux/

(4)让 192.168.10.9 通过访问访问 192.168.10.202 的yum代理,可以访问到 yum 源。

一、192.168.10.2021操作步骤(部署 Nginx 容器反向代理)

1. 安装 Docker(BCLinux/openEuler 系统)

复制代码
# 安装docker
dnf install docker -y
# 开机自启+启动服务
systemctl enable --now docker
# 验证
docker info

2. 创建 Nginx 配置目录与代理配置文件

复制代码
# 新建配置存放目录
mkdir -p /etc/nginx_proxy/conf.d
# 编写反向代理配置
cat > /etc/nginx_proxy/conf.d/bclinux_repo.conf <<EOF
server {
    listen 80;
    server_name _;

    # 匹配内网访问路径 /bclinux/oe22.10/xxx
    location /bclinux/ {
        # 上游官方yum源地址
        proxy_pass http://mirrors.cmecloud.cn/bclinux/;
        proxy_set_header Host mirrors.cmecloud.cn;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;

        # 缓存可选(按需开启,加速重复下载)
        proxy_cache_valid 200 302 12h;
        proxy_cache_valid 404 5m;
    }
}
EOF

3. 启动 Nginx Docker 容器

复制代码
docker run -d \
  --name nginx-yum-proxy \
  --restart always \
  -p 80:80 \
  -v /etc/nginx_proxy/conf.d:/etc/nginx/conf.d \
  nginx:stable

4. 验证代理是否可用(在 201 本机测试)

复制代码
curl http://127.0.0.1/bclinux/oe22.10/OS/x86_64/
# 能返回yum源目录HTML列表,代表代理正常

二、验证yum代理

1. 配置/etc/hosts

bash 复制代码
192.168.10.201 mirrors.cmecloud.cn

2.编辑yum

vi /etc/yum.repos.d/BCLinux.repo

bash 复制代码
#generic-repos is licensed under the Mulan PSL v2.
#You can use this software according to the terms and conditions of the Mulan PSL v2.
#You may obtain a copy of Mulan PSL v2 at:
#    http://license.coscl.org.cn/MulanPSL2
#THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
#PURPOSE.
#See the Mulan PSL v2 for more details.

[OS]
name=OS
baseurl=http://mirrors.cmecloud.cn/bclinux/oe22.10/OS/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-BCLinux-For-Euler

[everything]
name=everything
baseurl=http://mirrors.cmecloud.cn/bclinux/oe22.10/everything/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-BCLinux-For-Euler

[EPOL]
name=EPOL
baseurl=http://mirrors.cmecloud.cn/openeuler/openEuler-22.10-LTS/EPOL/main/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://mirrors.cmecloud.cn/openeuler/openEuler-22.10-LTS/OS/$basearch/RPM-GPG-KEY-openEuler

[debuginfo]
name=debuginfo
baseurl=http://mirrors.cmecloud.cn/bclinux/oe22.10/debuginfo/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-BCLinux-For-Euler

[update]
name=update
baseurl=http://mirrors.cmecloud.cn/bclinux/oe22.10/update/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-BCLinux-For-Euler

3.测试

bash 复制代码
[root@localhost yum.repos.d]# yum clean all
24 files removed
[root@localhost yum.repos.d]# yum grouplist
OS                                                                                                                                                                            1.3 MB/s | 3.5 MB     00:02
everything                                                                                                                                                                    2.4 MB/s |  17 MB     00:06
debuginfo                                                                                                                                                                     2.7 MB/s | 3.8 MB     00:01
update                                                                                                                                                                        2.3 MB/s |  18 MB     00:07
Last metadata expiration check: 0:00:01 ago on 2018年07月12日 星期四 19时10分43秒.
Available Environment Groups:
   带 GUI 的服务器
   服务器
   云服务器
   工作站
   定制操作系统
   虚拟化主机
   万维网服务器
   基础设施服务器
   GNOME 桌面
   开发及生成工作站
Installed Environment Groups:
   最小安装
Available Groups:
   图形管理工具
   RPM 开发工具
   控制台互联网工具
   .NET 核心开发
   Anolis OS cloud kernel
   Deepin New Desktop Environment
   容器管理
   开发工具
   无图形终端系统管理工具
   传统 UNIX 兼容性
   网络服务器
   科学记数法支持
   安全性工具
   系统工具
   智能卡支持
[root@localhost yum.repos.d]#
相关推荐
AlbertS2 小时前
Let‘s Encrypt 证书自动续期并自动应用到Nginx
运维·nginx·ssl·cerbot·renew·续期
泡沫冰@16 小时前
上章节中文件的讲解
前端·网络·nginx
難釋懷1 天前
Nginx内存缓存
nginx·缓存·junit
云计算磊哥@1 天前
运维开发宝典059-大型网站nginx服务器管理全集5
服务器·nginx·运维开发
cesium vue2 天前
nginx 流媒体配置
运维·nginx
zhougl9962 天前
Gateway 和 Nginx 路由区别
运维·nginx·gateway
布兰妮甜2 天前
跨域全方案对比:CORS、Nginx 反向代理、JSONP、iframe、postMessage
nginx·跨域·cors·前端架构·浏览器安全
難釋懷2 天前
Nginx-proxy缓存断点续传缓存 range
运维·nginx·缓存
難釋懷2 天前
Nginx-proxy缓存清理
运维·nginx·缓存