免费Ngrok服务器及Ngrok部署

自己搭建ngrok服务器

   想直接使用Ngrok服务的同学请点击链接 ngrok.zxyun.top数据线Ngrok服务

本环境在香港阿里云 CentOS7 ,

1、GO环境安装

wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.4.1.linux-amd64.tar.gz
sudo echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
sudo echo "export GOROOT=/usr/local/go" >> /etc/profile
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go
sudo chmod 755 /usr/local/go -R
sudo chown `whoami`:root /usr/local/go -R
source /etc/profile

或者,在墙外的
a) apt-get install build-essential golang mercurial git
b) yum install build-essential golang mercurial git
 

2. ngrok下载

cd /usr/local/src
git clone https://github.com/inconshreveable/ngrok.git
sudo chmod 755 /usr/local/src/ngrok -R
sudo chown `whoami`.root /usr/local/src/ngrok -R
export GOPATH=/usr/local/src/ngrok

3.证书生成

cd $GOPATH
mkdir ssl
cd ssl
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/C=CN/ST=GuangDong/L=ShenZhen/O=vkingman.tk/CN=ng.vkingman.tk" -days 3650 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj "/C=CN/ST=GuangDong/L=ShenZhen/O=vkingman.tk/CN=ng.vkingman.tk" -out device.csr
sudo openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 730
cp rootCA.pem $GOPATH/assets/client/tls/ngrokroot.crt
cp device.crt $GOPATH/assets/server/tls/snakeoil.crt 
cp device.key $GOPATH/assets/server/tls/snakeoil.key

4.编译

1)编译server端

下面中编译服务端只选择一种就可以了

GOOS:是目标的OS 
GOARCH:是目标的架构

GOOS=linux GOARCH=386 ./make.bash是更换 交叉编译环境

cd $GOROOT/src
GOOS=linux GOARCH=386 ./make.bash
cd $GOPATH
GOOS=linux GOARCH=386 make release-server

cd $GOROOT/src
GOOS=linux GOARCH=amd64 ./make.bash
cd $GOPATH
GOOS=linux GOARCH=amd64 make release-server

cd $GOROOT/src
GOOS=linux GOARCH=arm ./make.bash
cd $GOPATH
GOOS=linux GOARCH=arm make release-server

cd $GOROOT/src
GOOS=darwin GOARCH=386 ./make.bash
cd $GOPATH
GOOS=darwin GOARCH=386 make release-server

cd $GOROOT/src
GOOS=darwin GOARCH=amd64 ./make.bash
cd $GOPATH
GOOS=darwin GOARCH=amd64 make release-server
  • 错误Error:GOOS="" GOARCH="" go get github.com/jteeuwen/go-bindata/go-bindata

    • 方法1: $GOPATH没有权限,执行sudo chown vk:root $GOPATH -R
    • 方法2:或者就去github.com/jteeuwen/go-bindata中下载,按照
    • 执行命令 : 
          > cd $GOPATH
          > go get -u github.com/jteeuwen/go-bindata/go-bindata
      

    你会发现在$GOPATH/src中有了github.com/jteeuwen/go-bindata目录 
    https://github.com/jteeuwen/go-bindata

  • 错误:package code.google.com/p/log4go: exec: “hg”: executable file not found in $PATH

    • 原因:code.google.com的东西转移到了github上面,code.google.com上没有了log4go酷
    • 找到code.google.com/p/log4go的字符串grep -Rn code.google.com/p/log4go $GOPATH,修改/log/logger.go,替换为:github.com/V-KING/log4go
  • 看看bin目录:有了ngrokd

2)编译client端

选择下面的一种

cd $GOROOT/src
GOOS=windows GOARCH=386 ./make.bash
cd $GOPATH
GOOS=windows GOARCH=386 make release-client

cd $GOROOT/src
GOOS=windows GOARCH=amd64 ./make.bash
cd $GOPATH
GOOS=windows GOARCH=amd64 make release-client

cd $GOROOT/src
GOOS=linux GOARCH=386 ./make.bash
cd $GOPATH
GOOS=linux GOARCH=386 make release-client

cd $GOROOT/src
GOOS=linux GOARCH=amd64 ./make.bash
cd $GOPATH
GOOS=linux GOARCH=amd64 make release-client

cd $GOROOT/src
GOOS=linux GOARCH=arm ./make.bash
cd $GOPATH
GOOS=linux GOARCH=arm make release-client

cd $GOROOT/src
GOOS=darwin GOARCH=386 ./make.bash
cd $GOPATH
GOOS=darwin GOARCH=386 make release-client

cd $GOROOT/src
GOOS=darwin GOARCH=amd64 ./make.bash
cd $GOPATH
GOOS=darwin GOARCH=amd64 make release-client

5. 服务端ngrokd后台启动运行

例如1:系统管理员经常需要SSH 或者telent 远程登录到Linux 服务器,经常运行一些需要很长时间才能完成的任务,比如系统备份、ftp 传输等等。通常情况下我们都是为每一个这样的任务开一个远程终端窗口,因为它们执行的时间太长了。必须等待它们执行完毕,在此期间不能关掉窗口或者断开连接,否则这个任务就会被杀掉,一切半途而废了. 
例如2:执行一个程序的时候如果窗口关闭,或者按住了ctrl+c就会中中止。

  1. 输入下面命令
nohup  /usr/local/src/ngrok/bin/ngrokd -domain="ngrok.zxyun.top" -httpAddr=":80" -httpsAddr=":443" 

6. 内网ngrok来连接ngrokd服务端

1. 创建一个配置文件ngrok.cfg,内容如下

server_addr: "ngrok.zxyun.top:80" 

trust_host_root_certs: false
#下面是运行多个解析地址 

tunnels:
  web1:
    proto:
      http: "80"
  web2: 
    proto:
      tcp: "22"

2. 客户端执行ngrok:

ngrok -config ngrok.cfg start web1  web2

或者  


set  clientid=   ECHO.请输入需映射前缀:  

set  port=       ECHO.请输入需映射端口:

ngrok  -config=ngrok.cfg  -subdomain %clientid% %port%

 

不行就参加下载包里的一键启动脚本吧

 

 

参考: https://blog.csdn.net/yjc_1111/article/details/79353718

展开阅读全文

没有更多推荐了,返回首页