1、安装git
yum install -y git
2、安装go环境
yum install -y epel-release
yum install -y golang
go version
3、clone 代码
git clone https://github.com/inconshreveable/ngrok.git ngrok
cd ngrok
export GOPATH="$(pwd)"
go env
4、生成证书
export NGROK_DOMAIN="ngrok.example.com" #换成你的域名(绑定外网IP的域名或者本地Host解析域名)
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 server.key 2048
openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000
cp rootCA.pem assets/client/tls/ngrokroot.crt -i
cp server.crt assets/server/tls/snakeoil.crt -i
cp server.key assets/server/tls/snakeoil.key -i
5、编译windwos版
5.1 Windows版
服务端x86:GOOS=windows GOARCH=386 make release-server
客户端x86:GOOS=windows GOARCH=386 make release-client
服务端x64:GOOS=windows GOARCH=amd64 make release-server
客户端x64:GOOS=windows GOARCH=amd64 make release-client release-server
5.2 Linux版
服务端x86:GOOS=linux GOARCH=386 make release-server
客户端x86:GOOS=linux GOARCH=386 make release-client
服务端x64:GOOS=linux GOARCH=amd64 make release-server
客户端x64:GOOS=linux GOARCH=amd64 make release-client
5.3 MacOS版
服务端x86:GOOS=darwin GOARCH=386 make release-server
客户端x86:GOOS=darwin GOARCH=386 make release-client
服务端x64:GOOS=darwin GOARCH=amd64 make release-server
客户端x64:GOOS=darwin GOARCH=amd64 make release-client
6、Linux启动
设置hosts:
echo "192.168.94.14 ngrok.example.com" >> /etc/hosts
服务端:
cd /root/ngrok/bin
./ngrokd -domain="ngrok.example.com" -httpAddr=":1222" -httpsAddr=":443"
客户端:
cd /root/ngrok/bin
vim ngrok.cfg
server_addr: ngrok.example.com:4443
trust_host_root_certs: false
tunnels:
http:
proto:
http: 80
subdomain: pi
ssh:
remote_port: 12222
proto:
tcp: 22
mstsc:
remote_port: 13389
proto:
tcp: 3389
启动客户端:
./ngrok -config=ngrok.cfg start ssh
7、Windows启动
服务端:
ngrokd.exe -domain="ngrok.example.com" -httpAddr=":1222" -httpsAddr=":443" -tunnelAddr=":4443"
客户端:
ngrok.exe -config=ngrok.cfg start mstsc
8、客户端修改HOSTS
Windows
echo 192.168.1.102 ngrok.example.com >> C:\Windows\System32\drivers\etc\hosts
Linux
echo 192.168.1.102 ngrok.example.com >> /etc/hosts