一、安裝ngrok編譯環境
1、安裝git所需要的依賴包
yum -y install zlib-devel openssl-devel perl hg cpio expat-devel gettext-devel curl curl-devel perl-ExtUtils-MakeMaker hg wget gcc gcc-c++ libxslt xmlto
yum -y install asciidoc
2、解除安裝系統自帶git,除非版本高于1.8
git version
Git yum remove git
3、安裝git
yum install git
4、安裝go環境
yum install y golang
檢查go環境
go version
二、安裝ngrok
1、下載下傳ngrok源碼
cd /usr/local/
git clone https://github.com/inconshreveable/ngrok.git
2、安裝證書
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 device.key 2048
openssl req -new -key service.key -subj "/CN=example.com" -out device.csr
openssl x509 -req -in service.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
3、證書拷貝
yes|cp rootCA.pem assets/client/tls/ngrokroot.crt
yes|cp service.crt assets/server/tls/snakeoil.crt
yes|cp service.key assets/server/tls/snakeoil.key
4、交叉編譯
centos服務端:
GOOS=linux GOARCH=amd64
make release-server
windows用戶端:
GOOS=windows GOARCH=amd64
make release-client
5、啟動服務端
ngrok/bin目錄下,可以改變4443端口為其他比如8899:
./ngrokd -domain="example.com" -tunnelAddr=":8899"
背景運作服務端:
setsid ./ngrokd -domain="example.com" -tunnelAddr=":8899"
或者:
yum install screen
scree -S keepngrok
./ngrokd -domain="example.com" -tunnelAddr=":8899"
6、用戶端使用
建立一個ngrok.cfg
server_addr: "example.com:8899"
trust_host_root_certs: false
tunnels:
http:
subdomain: "dev"
proto:
http: "8090"
https:
subdomain: "test"
proto:
https: "8091
ssh:
remote_port: 3311
proto:
tcp: "22"
進入用戶端目錄啟動
cd e:\windows_amd64
ngrok -config ngrok.cfg start http https ssh