准备好域名:ngrok.xxx.cn
1.安装git和go
yum install gcc -y
yum install git -y
yum install mercurial git bzr subversion golang golang-pkg-windows-amd64 golang-pkg-windows-386 -y
2.下载ngrok源码
git clone https://github.com/inconshreveable/ngrok.git
3.生成证书
cd ngrok
mkdir cert
cd cert
export NGROK_DOMAIN="ngrok.xxx.cn"
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
4.生成服务端和客户端
#linux服务端
GOOS=linux GOARCH=386 make release-server (32位)
GOOS=linux GOARCH=amd64 make release-server(64位)
#Mac OS客户端
GOOS=darwin GOARCH=386 make release-client
GOOS=darwin GOARCH=amd64 make release-client
#windows客户端
GOOS=windows GOARCH=386 make release-client
GOOS=windows GOARCH=amd64 make release-client
5.启动指令
./bin/ngrokd -domain="$NGROK_DOMAIN"
6.下载客户端并配置
#mac客户端位置
bin/darwin_386 (32位)
bin/darwin_amd64 (64位)
#windows客户端位置
bin/windows_386
bin/windows_amd64
#进入对应的文件夹,通过sz或者ftp等方式将ngrok下载到你需要使用客户端的电脑中
#在客户端中,新建配置文件ngrok.cfg
#配置服务端连接地址,也就是基础域名。端口则与服务端-tunnelAddr配置相同
server_addr: "ngrok.xxx.cn:4443"
trust_host_root_certs: false
#运行客户端
ngrok -config=ngrok.cfg -subdomain ngrok 80 (windows系统客户端)
7.启动脚本,ngrok目录创建ngrok_start.sh
#ngrok_start.sh写入如下内容:
./bin/ngrokd -domain="ngrok.xxx.cn" -tlsKey="/usr/local/src/ngrok/assets/server/tls/snakeoil.key" -tlsCrt="/usr/local/src/ngrok/assets/server/tls/snakeoil.crt" -httpAddr=":80" -httpsAddr=":443" -tunnelAddr=":4443" -log-level="ERROR"
#后台启动
nohup ./ngrok_start.sh &
#如果windows下不能正常启动需要设置cmd编码
chcp 936
#启动客户端即可
本文章参考:https://www.jianshu.com/p/f5c2a55e77bd实现,仅做记录,方便下次使用。
网友评论