快速編譯安裝ngrok服務端

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.zip
unzip ngrok.zip -d ./
mv ngrok-master/ ngrok
echo '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 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=example.com" -days 5000 -out rootCA.pem
openssl genrsa -out tunnel.key 2048
openssl req -new -key tunnel.key -subj "/CN=tunnel.example.com" -out tunnel.csr
openssl x509 -req -in tunnel.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out tunnel.crt -days 5000
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp tunnel.crt assets/server/tls/snakeoil.crt
cp tunnel.key assets/server/tls/snakeoil.key
echo '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:4443
trust_host_root_certs: false

執行命令

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

控制檯輸出正常連接的日誌,至此你便可以配置dns解析,然後把bin目錄的各個平臺資源發佈到對應平臺上使用了。

6.如果你覺得這個依然嫌麻煩

請點擊這裏

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章