安装gcc
yum install gcc

安装git
yum install git

安装GO语言环境
yum install go
go version

下载ngrok源码
cd /usr/local/src
git clone https://github.com/inconshreveable/ngrok.git
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=flask.huchangyi.com" -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/CN=flask.huchangyi.com" -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000

将新生成的证书,替换掉assets/client/tls下的证书
yes|cp rootCA.pem assets/client/tls/ngrokroot.crt
yes|cp device.crt assets/server/tls/snakeoil.crt
yes|cp device.key assets/server/tls/snakeoil.key

编译生成ngrokd(服务端)
这里是交叉编译,linux系统GOOS=linux,64位系统GOARCH=amd64,32位系统GOARCH=386
当前系统可用go env查看
GOOS=linux GOARCH=amd64 make release-server

启动服务端(/usr/local/src/ngrok目录下)
nohup /usr/local/src/ngrok/bin/ngrokd -tlsKey="assets/server/tls/snakeoil.key" -tlsCrt="assets/server/tls/snakeoil.crt" -domain="flask.huchangyi.com" -httpAddr=":8081" -httpsAddr=":8082" -tunnelAddr=":8083" &

添加新的域名解析
*.flask

编译生成ngrok(客户端)
linux版客户端: make release-client
windows客户端32位: GOOS=windows GOARCH=386 make release-client
windows客户端64位: GOOS=windows GOARCH=amd64 make release-client
MAC: GOOS=darwin GOARCH=amd64 make release-client

客户端执行
nohup /home/ngrok/bin/ngrok -config /home/ngrok/bin/ngrok.cfg -proto tcp 22 &
nohup /home/ngrok/bin/ngrok -subdomain rasp -config /home/ngrok/bin/ngrok.cfg 80 &
或者
nohup /home/ngrok/bin/ngrok -subdomain rasp -config /home/ngrok/bin/ngrok.cfg start http https ssh

配置文件格式(ngrok.cfg)

server_addr: "flask.huchangyi.com:8083"
trust_host_root_certs: false
tunnels:
  http:
    subdomain: "www"
    proto:
      http: "8090"
      
  https:
    subdomain: "www"
    proto:
      https: "8091"
 
  ssh:
    remote_port: 3333
    proto:
      tcp: "22"

编译树莓派上的ngrok客户端
将刚才用来编译ngrok服务端的ngrok源码文件夹全部复制到树莓派上:
cd ./ngrok
make release-client
出错时
把源码目录下bin/go-bindata删除,然后执行make release-client
直接下载已经编译好的
wget http://huchangyi.com/doc/ngrok-rasp.zip
unzip ngrok-rasp.zip
mv ngrok-rasp ngrok
vim /etc/rc.local
bash /home/ngrok/start-ngrok.sh

标签: none

评论已关闭