安装go
1
apt-get install golang
下载ngrok源码
1
git clone https://github.com/inconshreveable/ngrok.git
配置环境变量
1
2
3
4
sudo vim /etc/profile
export GOPATH=/usr/local/go
export PATH=$PATH:$GOPATH/bin
export NGROK_DOMAIN="m9d2.cn"
生成自签名证书
1
2
3
4
5
openssl genrsa -out base.key 2048
openssl req -new -x509 -nodes -key base.key -days 10000 -subj "/CN=$NGROK_DOMAIN" -out base.pem
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr
openssl x509 -req -in server.csr -CA base.pem -CAkey base.key -CAcreateserial -days 10000 -out server.crt
替换证书
1
2
3
cp base.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key
编译服务端
1
make release-server
启动
1
./ngrokd -tlsKey="../assets/server/tls/snakeoil.key" -tlsCrt="../assets/server/tls/snakeoil.crt" -domain="m9d2.cn" -httpAddr=":8000" -httpsAddr=":8001" &
设置为系统服务
1
2
3
4
5
6
7
8
9
[Unit]
Description=ngrok
After=network.target
[Service]
ExecStart=/home/ubuntu/ngrok/bin/ngrokd -tlsKey="/home/ubuntu/ngrok/assets/server/tls/snakeoil.key" -tlsCrt="/home/ubuntu/ngrok/assets/server/tls/snakeoil.crt" -domain="m9d2.cn" -httpAddr=":1000" -httpsAddr=":1001"
[Install]
WantedBy=multi-user.target
编译客户端
1
2
3
4
5
6
7
32位linux客户端: GOOS=linux GOARCH=386 make release-client
64位linux客户端: GOOS=linux GOARCH=amd64 make release-client
32位windows客户端: GOOS=windows GOARCH=386 make release-client
64位windows客户端: GOOS=windows GOARCH=amd64 make release-client
32位mac平台客户端:GOOS=darwin GOARCH=386 make release-client
64位mac平台客户端:GOOS=darwin GOARCH=amd64 make release-client
ARM平台linux客户端: GOOS=linux GOARCH=arm make release-client
设置本地客户端
windows
配置ngrok.cfg
1
2
server_addr: "m9d2.cn:4443"
trust_host_root_certs: false
启动
http
1
ngrok.exe -subdomain=ngrok -config=ngrok.cfg 80
tcp
1
ngrok.exe -proto=tcp -config=ngrok.cfg start ssh