参考文章:
http://blog.csdn.net/sdfgsdfg1444/article/details/72793313
http://www.jianshu.com/p/b254547b9fe5
http://blog.csdn.net/u013216667/article/details/50782084

1.安装依赖环境
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++ unzip

2.安装git
先下载:https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz
cd /usr/
wget https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz
tar zxvf git-2.6.0.tar.gz

配置git环境
cd /usr/git-2.6.0
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo “export PATH=$PATH:/usr/local/git/bin” >> /etc/bashrc
source /etc/bashrc
git version

3.go下载:https://pan.baidu.com/s/1hs1VzjY 放到/usr/local
解压 tar zxvf go1.4.2.linux-amd64.tar.gz
环境go配置 添加环境变量,
编辑 vim /etc/profile
在最后添加
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
保存后,使环境变量生效
source /etc/profile
或者创建软连接: ln -s /usr/local/go/bin/* /usr/bin/
检查版本
go version

4.ngrok下载:https://pan.baidu.com/s/1i5ckSdR zip解压放到/usr/local/ngrok下
配置ngrok
cd /usr/local/ngrok
export GOPATH=/usr/local/ngrok/
export NGROK_DOMAIN=”hongpy.xin”
cd /usr/local/ngrok

5.签名:
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 server.key 2048
openssl req -new -key server.key -subj “/CN=$NGROK_DOMAIN” -out server.csr
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000

6.复制签名:
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key

7.编译服务端
cd /usr/local/go/src
GOOS=linux GOARCH=amd64 ./make.bash

cd /usr/local/ngrok/
GOOS=linux GOARCH=amd64 make release-server

8.编译客户端
cd /usr/local/go/src
GOOS=windows GOARCH=amd64 ./make.bash

cd /usr/local/ngrok/
GOOS=windows GOARCH=amd64 make release-client

9.启动服务端
cd 进入根目录直接输入
/usr/local/ngrok/bin/ngrokd -domain=”hongpy.xin” -httpAddr=”:80″ -tunnelAddr=”:4443″

//服务端后台永久运行
nohup /usr/local/ngrok/bin/ngrokd -domain=”hongpy.xin” -httpAddr=”:80″ -tunnelAddr=”:4443″

10.客户端配置新建一个 ngrok.cfg 文件
server_addr: “hongpy.xin:4443”
trust_host_root_certs: false

11.客户端启动新建一个xxx.bat文件
ngrok -config=ngrok.cfg -subdomain hong 8080

注意:
1.如果客户端启动显示reconnection,请检查防火墙端口是否开放80和4443端口

编辑防火墙配置文件 按 i 编辑、按esc退出编辑、输入 :wq
vi /etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 4443 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT

//重启防火墙
service iptables restart

2.如果可以连接,但是不能访问,请检查域名是否开启CNAME记录
路由上虚拟机服务器是否设置端口80/4443/443
192.168.5.110(ngrok所在Linux的ip)、4443是http访问的端口、443是https访问的端口
常用服务器  外部端口 内部端口   IP地址    协议类型
      443   443    192.168.5.110   ALL
      80    80     192.168.5.110   ALL
      4443  4443    192.168.5.110   ALL

 

 

版权声明:本文为yrhong原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/yrhong/p/8898094.html