章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • linux

  • windows

  • 中间件

  • 网络

  • 安全

  • 存储

  • 防火墙

  • 数据库

  • 系统

    • vmware

    • ftp

    • nexus

      • nexus安装
      • 使用nexus3配置npm私有仓库
      • 使用nexus3配置maven私有仓库
      • 使用nexus3配置go私有仓库
        • 1,创建blob存储。
        • 2,阿里代理
        • 3,官方代理
        • 4,套娃代理。
        • 5,创建group类型的go仓库
    • harbor

    • confluence&jira

    • loki

    • sonarqube

    • svn

    • other

    • openldap

    • influxdb

    • wordpress

    • kvm

    • argocd

    • jfrog

    • nextcloud

    • RustDesk

    • mail

    • ghost

  • docker

  • other

  • 监控

  • 运维
  • 系统
  • nexus
章工运维
2023-06-25
目录

使用nexus3配置go私有仓库

# 1,创建blob存储。

为其创建一个单独的存储空间。

56cfe0528b650efd.jpg

# 2,阿里代理

首先将国内的阿里仓库添加进来,再一次口头表扬阿里,这造福广大开发者的举措。添加的方式非常简单,与其他项目的代理添加方式一致:

  • Name: proxy-go-ali
  • Proxy
    • Remote Storage: 远程仓库地址,这里填写: https://mirrors.aliyun.com/goproxy/
  • Storage: go-hub。

其他的均是默认。

整体配置截图如下:

bade26c61f02a910.jpg

# 3,官方代理

首先将国内的阿里仓库添加进来,再一次口头表扬阿里,这造福广大开发者的举措。添加的方式非常简单,与其他项目的代理添加方式一致:

  • Name: proxy-go-gf
  • Proxy
    • Remote Storage: 远程仓库地址,这里填写: https://goproxy.io (opens new window)
  • Storage: go-hub。

其他的均是默认。

整体配置截图如下:

f1fb8866ec9bdba5.jpg

如上两步都比较简单,直接配置现成的代理即可。接下来进入套娃代理的配置。

# 4,套娃代理。

这里套娃代理的思路非常简单,主要借助于go语言开源的私服工具Athens来实现。

有时候我们要下一些国外的包,或者GitHub上的包,这个时候可能仅仅配置如上两个代理是不够的,因为我们私服到达如上代理的网络可能会有问题,尤其是官方的代理,而阿里的代理又未必我们想要的全都有,于是,我们需要自建一个能够快速下载国外包的代理。

这个代理通过Athens服务进行部署,并且服务器节点放置在国外。为了方便,我们使用docker进行部署。

docker run -d -v /data/athens/storage:/data/athens --net=host -e ATHENS_DISK_STORAGE_ROOT=/data/athens  -e ATHENS_STORAGE_TYPE=disk -e ATHENS_TIMEOUT=3000 -e ATHENS_GOGET_WORKERS=100 -e ATHENS_PROTOCOL_WORKERS=100 --name athens-proxy  --restart always    -p 0.0.0.0:3000:3000 gomods/athens
1

以上将在对外的主机上启动一个私服,主要用于下载外部的一些依赖包。通过如下规则配置一个可供访问的域名,注意需要添加证书认证。

cat athens-out.test.com.conf

server {
    listen 80;
    listen 443 ssl http2;
    server_name  124.156.98.252 athens-out.test.com;
    ssl_certificate     /etc/nginx/secure/test.cer;
    ssl_certificate_key /etc/nginx/secure/test.key;
    ssl_session_timeout 5m;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    access_log /data/log/athens_access.log json;
    error_log /data/log/athens_error.log;
    allow 1.1.1.1; # 这里可以放开公司访问
    deny all;
    location / {
        proxy_pass http://127.0.0.1:3000/;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

现在,我将继续在内网创建一个Athens代理,这个代理主要用于代理内网Gitlab当中的包,并将上边对外的代理一并代理进来,前边所谓的套娃代理,就是从这儿而来。在本地的某台主机上,启动如下服务:

docker run -d --net=host -v /data/athens/storage:/data/athens -v /data/athens/gitconfig/ssh-keys:/root/.ssh  -e ATHENS_DISK_STORAGE_ROOT=/data/athens -e ATHENS_STORAGE_TYPE=disk  -e  ATHENS_GLOBAL_ENDPOINT="https://athens-out.test.com" --add-host  gitlab.test.com:10.3.0.42 --add-host athens-out.test.com:124.156.98.252 --name athens-proxy --restart always -p 0.0.0.0:3000:3000    gomods/athens
1

以上,依旧挂载了 /data/athens/storage作为包存储路径,接着又挂在了一个路径 /data/athens/gitconfig/ssh-keys,这里边存放着连接本地Gitlab的关键信息,大概如下:

$ cd /data/athens/gitconfig/ssh-keys/
$ ls
config  id_rsa  id_rsa.pub  known_hosts
$ cat config
Host gitlab.test.com
Hostname gitlab.test.com
StrictHostKeyChecking no
IdentityFile /root/.ssh/id_rsa
1
2
3
4
5
6
7
8

其余三项内容都是一个常规密钥对的内容,这里的秘钥是在Gitlab当中创建的deploy key,我们的代理就是通过这个key来访问Gitlab项目的。

当本地的代理跑起来之后,同样需要配置一个域名用于访问:

cat athens.test.com.conf

server {
    listen 80;
    listen 443 ssl http2;
    server_name 10.3.0.41 athens.test.com;
    ssl_certificate     /etc/nginx/secure/test.cer;
    ssl_certificate_key /etc/nginx/secure/test.key;
    ssl_session_timeout 5m;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    access_log /data/log/athens_access.log json;
    error_log /data/log/athens_error.log;
    location / {
        proxy_pass http://127.0.0.1:3000/;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

配置完毕之后,就能投入使用了,现在直接将这个对外的地址,作为一个代理配置到nexus中。

  • Name: proxy-go-athens
  • Proxy
    • Remote Storage: 远程仓库地址,这里填写: https://athens.test.com (opens new window)
  • Storage: go-hub。

其他的均是默认。

整体配置截图如下:

1df83edeeef9885a.jpg

# 5,创建group类型的go仓库

  • Name:group-go
  • Storage:选择专用的blob存储go-hub。
  • group : 将左边可选的3个仓库,添加到右边的members下。

整体配置截图如下:

a7544156fe0e9f39.jpg

注意如上三个代理的上下顺序,一定是最好用的越靠上,所有的group类型的代理都遵循这个规律。


参考链接 (opens new window)

微信 支付宝
上次更新: 2023/06/30, 22:33:06

← 使用nexus3配置maven私有仓库 安装harbor并修改默认使用的端口→

最近更新
01
shell脚本模块集合
05-13
02
生活小技巧(认知版)
04-29
03
生活小技巧(防骗版)
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式