一、安装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