您的位置:首页 > 编程语言 > Go语言

ngrok服务器搭建

2016-08-21 00:00 204 查看
摘要: ngrok server 、ubuntu

参考: http://blog.csdn.net/u013216667/article/details/50782084

前期

clone ngrok源码

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


go long环境配置 : 推荐1.4版本 可能会因为版本出问题
参见最下方


制作签名证书

export GOPATH=/root/ngrok/
export NGROK_DOMAIN="ngrok.resty.xyz"
// 证书制作
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
// 替换自签名证书到相关目录
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp device.crt assets/server/tls/snakeoil.crt
cp device.key assets/server/tls/snakeoil.key

生成客户端服务端

# 指定环境变量位64位linux版本
GOOS=linux GOARCH=amd64
# 生成linux服务端及客户端,生成文件在bin下
make release-server release-client
# 试运行,注意端口占用情况(运行之后 Ctrl+C结束)
./bin/ngrokd -domain="ngrok.resty.xyz" -httpAddr=":9081" -httpsAddr=":9082"
# ngrok server开机自启
cp /root/ngrok/bin/ngrokd /usr/bin/ngrokd
chmod +x /usr/bin/ngrokd
vim /etc/rc.local
nohup ngrokd -tlsKey="/dataApp/ngrokcfg/device.key" -tlsCrt="/dataApp/ngrokcfg/device.crt"  -domain="ngrok.resty.xyz" -httpAddr=":80" -httpsAddr=":8081" -tunnelAddr=":4443"
# linux server client
GOOS=linux GOARCH=amd64
make release-server release-client

注意: 生成windows客户端,需要交叉编译 (如需要参照下面ubuntu下go环境配置)

# apt-get install golang没有该目录,好像 在/usr/lib/下,建议使用最下面推荐的go lang配置方式
cd /usr/local/go/src
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 ./make.bash
cd /dataApp/ngrok
GOOS=windows GOARCH=amd64 make release-server release-client
# 同理 mac端生成
cd /usr/local/go/src
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 ./make.bash
cd /dataApp/ngrok
GOOS=darwin GOARCH=amd64 make release-server release-client

windows端测试

创建客户端配置文件ngrok.cfg 如下:

server_addr: "ngrok.resty.xyz:4443"
trust_host_root_certs: false
tunnels:
http:
proto:
http: 8080
subdomain: web
https:
proto:
https: 8099
subdomain: ssl
ssh:
remote_port: 5000
proto:
tcp: 22

#  启动ngrokd
ngrokd -tlsKey="/dataApp/ngrokcfg/device.key" -tlsCrt="/dataApp/ngrokcfg/device.crt"  -domain="ngrok.resty.xyz" -httpAddr=":80" -httpsAddr=":8081" -tunnelAddr=":4443"
# cmd下启动ngrok
ngrok.exe -config=ngrok.cfg  -log=log start http https ssh

出现以下内容,测试通过

Tunnel Status                 online
Version                       1.7/1.7
Forwarding                    http://web.ngrok.resty.xyz -> 127.0.0.1:8080
Forwarding                    https://ssl.ngrok.resty.xyz:8081 -> 127.0.0.1:8099
Forwarding                    tcp://ngrok.resty.xyz:5000 -> 127.0.0.1:22
Web Interface                 127.0.0.1:4040
# Conn                        0
Avg Conn Time                 0.00ms

问题

web.ngrok.resty.xyz 这些域名必须添加解析,才能在解析到,只添加ngrok.resty.xyz好像不行,标记下。

Ubuntu安装个GO Lang(go 语言)环境配置

参见: http://aevitx.com/2016/03/31/ngrok/

wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz tar -xzf go1.4.1.linux-amd64.tar.gz -C /usr/local

设置系统环境变量
vi /etc/profile 在最后添加:

export GOROOT=/usr/local/go
export GOBIN=$GOROOT/bin
export GOPKG=$GOROOT/pkg/tool/linux_amd64
export PATH=.:$PATH:$GOBIN:$GOPKG

然后编译,使其生效

source /etc/profile

测试:能看见版本号,那么配置成功!

go version
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ngrok Go lang