athens 搭建golang私有仓库(踩了各种坑)

RuoiseHone · · 1782 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

环境:

gitlab: gitlab需要配置可信任https。

nginx:两个

git:最新版,!!!重要,不是最新版go get会出现问题

athens

golang

原理:

通过nginx转发,实现外网请求和内网请求路由。配置https://goproxy.io 下载golang等被墙的包。

注意事项:

git一定要是最新版

gitlab一定要配置https。目前athens使用http代理我试了不行,有会配置的同学欢迎指教。

ge get 私有仓库时需要带有.git后缀

网络流程图:

网络流向图


准备:

1.机器3个:(也可以在一个机器上,修改对应端口即可)

private.gitlab.com: 部署私有仓库机器

athens.com: athens仓库入口机器(可以不用,但是这样外网的包就不会缓存在本地)

athens.private.com: 私有gitlab代理。

2.在阿里云上申请可信任的免费CA证书。

private.gitlab.com 部署和相关配置:

1.在该机器上部署gitlab仓库

2.配置nginx https,配置如下:

```

#user nobody;

worker_processes  1;

error_log logs/error.log;

error_log  logs/error.log  notice;

error_log  logs/error.log  info;

#pid logs/nginx.pid;

events {

    worker_connections  1024;

}

http {

# gitlab 服务地址和端口

    upstream gitlab {

        server 10.53.1.234:8081;

    }

server {

        listen 10.53.1.234:80;

        server_name private.gitlab.com;

        # 这里选择重定向到https去

        rewrite ^(.*)$ https://${server_name}$1 permanent;

    }

server {

        listen 443;

        server_name  private.gitlab.com;

        ssl on;

        ssl_session_cache        shared:SSL:10m;

        ssl_session_timeout      20m;

        ssl_session_tickets      on;

        ssl_certificate /etc/nginx/server/2650770_private.gitlab.com.pem;      # 自己ca签发的

        ssl_certificate_key /etc/nginx/server/2650770_private.gitlab.com.key;  # 自己的私钥

        location / {

            proxy_cache off;

            proxy_pass http://gitlab;

            access_log /var/log/nginx_access.log;

        }

        # GOPROXY,vgo download protocol协商软件包的规范

        # 第一步就是获取软件包元数据,格式如下,gitlab暂时不支持,所以需要nginx代理

        location ~* ^/[^/]+/[^/]+$ {

            if ($http_user_agent ~* '^go.*') {

                return 200 "";

            }

            proxy_cache off;

            proxy_pass http://gitlab;

        }

        # 具体协议原理请看这篇文章:http://www.bubuko.com/infodetail-3045365.html 

       location ~* ^/(?[^/]+)/(?[^/]+)/.*$ {

            set $goRedirect 'https://$host/$holder/$project?$args';

            access_log /var/log/nginx_access1.log;

            if ($http_user_agent ~* '^go.*') {

                return 301 $goRedirect;

            }

            proxy_cache off;

            proxy_pass http://gitlab;

        }

}

}

```

athens.com (代理仓库总入口)部署和相关配置:

安装golang环境

设置go环境,export GO111MODULE=on,export GOPROXY=http://private.athens.com

安装athens

private.athens.com (私有仓库代理)部署和相关配置:

安装golang环境 和 git客户端并配置免登陆

设置go环境,export GO111MODULE=on,export GOPROXY=direct

安装athens

安装nginx并配置nginx,相关配置如下:

```

#user nobody;

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    server {

        listen 80;


        # 外部的依赖转发到外面的go proxy

        location / {

            proxy_pass https://goproxy.io;

            #proxy_pass https://athens.azurefd.net;

        }

        # 内部依赖的go proxy,也就是上面启动的athens

        # github的依赖也可以走本地的go proxy,可以做缓存

        location ~ /(private\.gitlab\.com)/ {

            # 私有仓库跳转到私有athens 服务

            proxy_pass http://localhost:3000;

            access_log /var/log/nginx_access.log;

        }

    }

}

```


有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:RuoiseHone

查看原文:athens 搭建golang私有仓库(踩了各种坑)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1782 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传