goproxy gitlab 搭建go 私有仓库

goproxy gitlab 搭建go 私有仓库,第1张

gitlab搭建

服务器:

192.168.0.60 gitea gitlab 和 安装nginx 和 go px 代理环境
192.168.0.61 或windows 机器,作为客户端.

# vi /etc/sysconfig/network-scripts/ifcfg-ens33
# systemctl restart network
# hostnamectl set-hostname node70
# logout

192.168.0.60 安装 安装 nginx
作为http或者https代理域名使用


# yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel wget vim

# cd /usr/local/src/
# wget http://nginx.org/download/nginx-1.19.10.tar.gz
# tar xvf nginx-1.19.10.tar.gz
# cd nginx-1.19.10
# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module
# make && make install
# /usr/local/webserver/nginx/sbin/nginx -v
# /usr/local/webserver/nginx/sbin/nginx 

# ps -ef | grep nginx
# vi /usr/local/webserver/nginx/conf/nginx.conf 修改配置文件
# 重新加载配置 /usr/local/webserver/nginx/sbin/nginx -s reload

添加本地https证书
nginx代理,配置ssl证书,达到https要求 
放在nginx/conf/ssl目录
# cd /usr/local/webserver/nginx
# mkdir conf/ssl
#  cd conf/ssl
1.创建服务器证书密钥文件 server.key:
# openssl genrsa -des3 -out server.key 1024
输入密码,确认密码,自己随便定义,但是要记住,后面会用到。
2.创建服务器证书的申请文件 server.csr
# openssl req -new -key server.key -out server.csr
输出内容为:
Enter pass phrase for root.key: ← 输入前面创建的密码
Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音
Locality Name (eg, city) []:BeiJing ← 市的全名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []: ← 此时不输入
Email Address []:[email protected] ← 电子邮箱,可随意填
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入
4.备份一份服务器密钥文件
cp server.key server.key.org
5.去除文件口令
openssl rsa -in server.key.org -out server.key
6.生成证书文件server.crt
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

配置nginx 路由:
防止上传的时候出现错误.
nginx.conf中的http配置段中加入
# vi /usr/local/webserver/nginx/conf/nginx.conf 修改配置文件
// git.fjs.icu 是将代理的域名 和github.com类似 gitlab.com

client_max_body_size 100m;

 server {
        listen       80;
        server_name git.fjs.icu;
        listen 443 ssl;
        ssl_certificate ssl/server.crt;
        ssl_certificate_key ssl/server.key;
        location / {
              root   html;
              proxy_pass http://192.168.0.60:5081;
              index  index.html index.htm;
          }
    }
    
    # 重新加载配置 /usr/local/webserver/nginx/sbin/nginx -s reload
搭建gitlab服务器
挂载磁盘
https://blog.csdn.net/q610376681/article/details/88076551

systemctl stop firewalld
systemctl disable firewalld
vi /etc/sysconfig/selinux
将SELINUX改为disable

然后roboot重启系统
# yum -y install curl policycoreutils openssh-server openssh-clients postfix policycoreutils-python

# cd /usr/local/src/

# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-14.2.1-ce.0.el7.x86_64.rpm
# rpm -i gitlab-ce-14.2.1-ce.0.el7.x86_64.rpm
(yum install -y gitlab-ce)

/opt/gitlab/bin/gitlab-ctl reconfigure

vim  /etc/gitlab/gitlab.rb

[root@gitlab ~]#  vim /etc/gitlab/gitlab.rb 
# 把注释取消然后指定新的仓库存储位置,也可以默认
git_data_dirs({ "default" => { "path" => "/data/gitlab-data" } })

external_url 'http://192.168.0.60:5081'

gitlab-ctl reconfigure
重启gitlab
gitlab-ctl restart

vim /etc/hosts
192.168.0.60 git.fjs.icu


启动 gitlab 上传代码 创建公开仓库 , 最好是公开库吧.我觉得.
https://git.fjs.icu/



http://192.168.0.60:5081/server/go_test_1.git

go.mod

module git.fjs.icu/server/go_test_1

go 1.17

go_test_1.go

package go_test_1

import "fmt"

func Add() {
	fmt.Println("add test1")
}

上传到仓库地址,能够正常访问.

安装golang
# cd /usr/local/src
# wget https://golang.google.cn/dl/go1.17.linux-amd64.tar.gz
# tar xvf go1.17.linux-amd64.tar.gz
# vim /etc/profile
export GOROOT=/usr/local/src/go
#bin目录
export GOBIN=$GOROOT/bin
#工作目录
export GOPATH=/data/go
export PATH=$PATH:$GOPATH:$GOBIN:$GOROOT

source /etc/profile

# go env -w GO111MODULE=on
# go env -w GOPROXY=https://goproxy.io,direct
# go env -w GOSUMDB=off 
安装git
yum install -y git


安装 goproxy
https://goproxy.io/zh/
# mkdir /data/go/src/github.com/goproxyio -p
# cd /data/go/src/github.com/goproxyio
git clone https://github.com/goproxyio/goproxy.git
cd goproxy
make

/data/go/src/github.com/goproxyio/goproxy/bin/goproxy -listen=0.0.0.0:8083 -cacheDir=/data/goproxyio -proxy https://goproxy.cn -exclude "git.fjs.icu/private"


开发机: 任意一台机器即可 windows
git config --global url.“ssh://[email protected]”.insteadOf “https://git.fjs.icu” # 重点
go env -w GOPROXY=http://192.168.0.60:8083 #代理仓库地址
go env -w GOPRIVATE=git.fjs.icu
go env -w GOINSECURE=git.fjs.icu
go env -w GOSUMDB=off

新建另外一个文件夹

main.go
package main

import "git.fjs.icu/server/go_test_1"

func main() {
	go_test_1.Add()
}

go mod init
后续执行 go mod tidy

问题1:

git.fjs.icu/go_test_1: cannot find module providing package git.fjs.icu/go_test_1: unrecognized import path “git.fjs.icu/go_test_1”: parse https://git.fjs.icu/go_test_1?go-get=1: no go-import meta tags ()

注意 git.fjs.icu/go_test_1 包名 go.mod 应该 module git.fjs.icu/server/go_test_1

t3 imports
git.fjs.icu/server/go_test_1: cannot find module providing package git.fjs.icu/server/go_test_1: unrecognized import path “git.fjs.icu/server/go_test_1”: parse https://git.fjs.icu/server/go_test_1?go-get=1: no go-import meta tags (meta tag 192.168.0.60:5081/server/go_test_1 did not match import path git.fjs.icu/server/go_test_1)

go get: unrecognized import path “git.fjs.icu/server/go_test_1”: parse https://git.fjs.icu/server/go_test_1?go-get=1: no go-import meta tags (meta tag 192.168.0.60:5081/server/go_test_1 did not match import path git.fjs.icu/server/go_test_1)

问题2 :

vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
host: git.fjs.icu
port: 80
https: false
gitlab-ctl restart

D:\code\src\t3>go get -v git.fjs.icu/server/go_test_1
get “git.fjs.icu/server/go_test_1”: found meta tag vcs.metaImport{Prefix:“git.fjs.icu/server/go_test_1”, VCS:“git”, RepoRoot:“http://git.fjs.icu/server/go_test_1.git”} at //git.fjs.icu/server/go_test_1?go-get=1
go: downloading git.fjs.icu/server/go_test_1 v0.0.0-20210830150334-650f8e5fd97e
git.fjs.icu/server/go_test_1
go get: added git.fjs.icu/server/go_test_1 v0.0.0-20210830150334-650f8e5fd97e

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/995953.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存