转载:http://www.haiyun.me/archives/1012.html
首先安装GO环境,http://www.haiyun.me/archives/1009.html
1
2
3
4
|
cd /usr/local/src/
git clone https: //github .com /inconshreveable/ngrok .git
export GOPATH= /usr/local/src/ngrok/
export NGROK_DOMAIN= "haiyun.me"
|
生成自签名SSL证书,ngrok为ssl加密连接:
1
2
3
4
5
6
7
8
9
10
11
12
|
cd ngrok
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 device.key 2048 openssl req -new -key device.key -subj "/CN=$NGROK_DOMAIN" -out device.csr
openssl x509 -req - in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000
cp rootCA.pem assets /client/tls/ngrokroot .crt
cp device.crt assets /server/tls/snakeoil .crt
cp device.key assets /server/tls/snakeoil .key
GOOS=linux GOARCH=386 make clean
make release-server release-client
|
如果一直停留在go get gopkg.in/yaml.v1参考:https://www.haiyun.me/archives/1011.html
启动SERVER:
1
|
bin /ngrokd -domain= "$NGROK_DOMAIN" -httpAddr= ":8000"
|
交叉编译windows客户端,最好安装最新版本Golang,使用yum安装的一直编译不通过。
1
2
3
4
|
cd /usr/local/go/src/
GOOS=windows GOARCH=386 CGO_ENABLED=0 . /make . bash
cd -
GOOS=windows GOARCH=386 make release-server release-client
|
客户端配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
server_addr: "haiyun.me:4443" trust_host_root_certs: false tunnels: http:
subdomain: "example"
auth: "user:12345"
proto:
http: "80"
ssh:
remote_port: 2222
proto:
tcp: "22"
|
启动客户端:
1
|
bin /ngrok -config ngrok.conf start http ssh
|
注意所有domain要一致,不然会出现证书错误:
1
|
Failed to read message: remote error: bad certificate |