环境
服务端:Linux
客户端:Linux、Mac
要求:服务器有公网ip+自有域名
编译服务端
参考:https://www.jianshu.com/p/1fafa10af189
完成后,可得到Linux、Windows对应的Server、Client
域名解析
可以使用子域名,如: ngrok.xx.com; 具体tunnel: xx.ngrok.xx.com
这里需要配置两个域名解析
ngrok.xx.com ip
*.ngrok.xx.com ip (泛域名解析)
问题
编译Mac os client:
GOOS=linux GOARCH=amd64 make release-client
该命令能正常编译通过,但在Mac os中不能正常运行:
chen@cc darwin_amd64 % ngrok
fatal error: runtime: bsdthread_register error
runtime stack:
runtime.throw(0x14e8431, 0x21)
/usr/local/go/src/runtime/panic.go:596 +0x95 fp=0x7ff7bfeff7d0 sp=0x7ff7bfeff7b0
runtime.goenvs()
/usr/local/go/src/runtime/os_darwin.go:108 +0xa0 fp=0x7ff7bfeff800 sp=0x7ff7bfeff7d0
runtime.schedinit()
/usr/local/go/src/runtime/proc.go:486 +0xa1 fp=0x7ff7bfeff840 sp=0x7ff7bfeff800
runtime.rt0_go(0x7ff7bfeff870, 0x1, 0x7ff7bfeff870, 0x1000000, 0x1, 0x7ff7bfeff9d0, 0x0, 0x7ff7bfeff9d6, 0x7ff7bfeff9f2, 0x7ff7bfeffa01, ...)
/usr/local/go/src/runtime/asm_amd64.s:158 +0x183 fp=0x7ff7bfeff848 sp=0x7ff7bfeff840
编译Mac客户端
要求:Macbook
1、将编译服务端
的代码拷贝到Mac # client 需要使用与服务端一样的证书
chen@cc ngrok % ls
CONTRIBUTORS LICENSE Makefile README.md assets bin contrib docs pkg src
2、删除源码中 bin
目录 # 服务端编译产生的文件
rm -rf bin/*
3、安装1.14.1 版本Go
https://dl.google.com/go/go1.14.1.darwin-amd64.pkg
4、编译客户端
GOOS=darwin GOARCH=amd64 make release-client
5、验证
chen@cc ngrok % bin/ngrok
Error: Specify a local port to tunnel to, or an ngrok command.
Example: To expose port 80, run 'ngrok 80'
提示ngrok
可执行,增加配置即可使用
遇到的问题:
1、ngrok客户端在Mac运行无法创建链接,日志提示:
ngrok certificate relies on legacy Common Name field, use SANs instead
使用Go 1.14.1
版本进行重编编译
2、编译出现错误:malformed module path "ngrok": missing dot in first path element
chen@cc ngrok % GOOS=darwin GOARCH=amd64 make release-server
GOOS="" GOARCH="" go get github.com/jteeuwen/go-bindata/go-bindata
go: downloading github.com/jteeuwen/go-bindata v3.0.7+incompatible
go get: installing executables with 'go get' in module mode is deprecated.
Use 'go install pkg@version' instead.
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
bin/go-bindata -nomemcopy -pkg=assets -tags=release \
-debug=false \
-o=src/ngrok/client/assets/assets_release.go \
assets/client/...
bin/go-bindata -nomemcopy -pkg=assets -tags=release \
-debug=false \
-o=src/ngrok/server/assets/assets_release.go \
assets/server/...
go get -tags 'release' -d -v ngrok/...
go get ngrok/...: malformed module path "ngrok": missing dot in first path element
make: *** [deps] Error 1
配置环境变量:
export GO111MODULE=off
引用:
3、编译出现错误:...proxy.golang.org..... i/o timeout
切换代理:
go env -w GOPROXY=https://goproxy.cn\n
评论 (0)