快速编译安装ngrok服务端

来源:互联网 发布:java 未来前景 编辑:程序博客网 时间:2024/06/06 19:32

1.准备环境

(1) .准备一台centos7服务器
(2) .安装必要的软件包
yum -y install git golang openssl

2.下载ngrok资源

ngrok资源仓库地址https://github.com/inconshreveable/ngrok ,可以用wget或者git下载
wget执行命令

wget https://codeload.github.com/inconshreveable/ngrok/zip/master -O ngrok.zipunzip ngrok.zip -d ./mv ngrok-master/ ngrokecho 'ok'

git拉取资源

git clone https://github.com/inconshreveable/ngrok.git

3.生成tunnelAddr的证书

tunnelAddr是ngrok客户端用来链接ngrok服务端的‘server_addr’的域名
执行命令(记得把example.com改为你的域名)

cd ngrok/openssl genrsa -out rootCA.key 2048openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=example.com" -days 5000 -out rootCA.pemopenssl genrsa -out tunnel.key 2048openssl req -new -key tunnel.key -subj "/CN=tunnel.example.com" -out tunnel.csropenssl x509 -req -in tunnel.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out tunnel.crt -days 5000cp rootCA.pem assets/client/tls/ngrokroot.crtcp tunnel.crt assets/server/tls/snakeoil.crtcp tunnel.key assets/server/tls/snakeoil.keyecho 'ok'

4.编译ngrok服务端和客户端

执行命令

# 编译生成linux 64bit(mac可以直接用)版本GOOS=linux GOARCH=amd64 make release-all# 编译生成linux 32bit(mac可以直接用)版本GOOS=linux GOARCH=386 make release-all# 编译生成linux arm(mac可以直接用)版本GOOS=linux GOARCH=arm make release-all# 编译生成windows 64bit版本GOOS=windows GOARCH=amd64 make release-all# 编译生成windows 32bit版本GOOS=windows GOARCH=386 make release-all echo 'ok'

至此便生成了几乎所有的ngrok的服务端客户端

5.测试编译结果

设置host
hosts增加一行

127.0.0.1 tunnel.example.com test.example.com test1.example.com 

启动ngrokd

ngrokd -domain example.com -httpsAddr :443 -httpAddr :80 -tunnelAddr tunnel.example.com:4443

编写ngrok客户端配置文件’ngrok.yml’

server_addr: tunnel.example.com:4443trust_host_root_certs: false

执行命令

ngrok -config ngrok.yml -subdomain test 127.0.0.1:80

控制台输出正常连接的日志,至此你便可以配置dns解析,然后把bin目录的各个平台资源发布到对应平台上使用了。

6.如果你觉得这个依然嫌麻烦

请点击这里

原创粉丝点击