网上的搭建的教程挺多,尝试搭建的时候遇到了很多问题。
准备
1# 升级yum 2yum update 3# 安装gcc 4yum install gcc
1、GO环境安装
1## 使用1.4版本,不要使用高版本。 2mkdir /root/goproj 3cd /root/goproj 4wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz 5 6 7## 解压 8 9 10###配置go 环境变量 11vi /etc/profile 12export GOROOT=/root/goproj/go 13export PATH=$GOROOT/bin:$PATH 14export GOPATH=/root/goproj/ngrok 15source /etc/profile
2. ngrok下载
1cd /root/goproj 2git clone https://github.com/inconshreveable/ngrok.git 3cd /root/goproj/ngrok
3.证书生成
1openssl genrsa -out rootCA.key 2048 2openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=angrok.cn" -days 5000 -out rootCA.pem 3openssl genrsa -out device.key 2048 4openssl req -new -key device.key -subj "/CN=angrok.cn" -out device.csr 5openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000 6 7cp rootCA.pem assets/client/tls/ngrokroot.crt 8 9 cp device.crt assets/server/tls/snakeoil.crt 10 11cp device.key assets/server/tls/snakeoil.key
4.下载ngrok go包(建议手动下载)
1wget https://github.com/inconshreveable/go-update/archive/v0.zip 2wget https://github.com/go-yaml/yaml/archive/v1.zip 3#将下载的文件解压后的go文件放到 4mkdir /root/goproj/ngrok/src/gopkg.in/inconshreveable/go-update.v0 5mkdir /root/goproj/ngrok/src/gopkg.in/yaml.v1
1)编译server端
1cd /root/goproj/ngrok 2make release-server 3 4#### 编译之前请确保已经 安装了gcc 。。。报错请(yum install gcc)
2)编译客户端
11.Windows客户端 2cd /root/goproj/go/src 3GOOS=windows GOARCH=amd64 ./make.bash 4cd /root/goproj/ngrok 5GOOS=windows GOARCH=amd64 make release-client 6#同理,这里的amd64是64位系统,32位改成386 7#会在 bin/windows_amd64 目录下生成ngrok客户端程序,将ngrok.exe下载到windows操作系统 8 92.Mac客户端 10 11cd /root/goproj/go/src 12GOOS=darwin GOARCH=amd64 ./make.bash 13cd /root/goproj/ngrok 14GOOS=darwin GOARCH=amd64 make release-client 15#会在 bin/darwin_amd64/ 目录下生成ngrok客户端程序
5. 服务端ngrokd后台启动运行
ngrok 服务在关闭远程时候会被杀掉进程。
输入下面命令
1## 安装screen神器 2yum install screen 3 4 5screen -S keepNgrok 6/root/goproj/ngrok/bin/ngrokd -domain="angrok.cn" -httpAddr=":80" -httpsAddr=":8081" -tunnelAddr=":4443" &
6.客户端使用
1#新建 ngrok.cfg 文件,内容: 2server_addr: "angrok.cn:4443" 3trust_host_root_certs: true 4 5 6 7#客户端启动 8./ngrok -config=ngrok.cfg -subdomain=a 8080