搭建内网穿透利器 ngrok

虽然ngrok很久没有更新了,但是目前还是比较好用的内网穿透利器,这里我就来介绍下如何在centos 7上搭建ngrok服务端和客户端

1、环境安装:

yum  -y  install  gcc  golang  wget

2、下载ngrok:

cd  /usr/local/
git  clone  https://github.com/dollarphper/ngrok.git
cd  ngrok/

3、生成证书:

openssl  genrsa -out  rootCA.key  2048
openssl  req  -x509  -new  -nodes  -key  rootCA.key -subj "/CN=ileiming.com"  -days  5000  -out  rootCA.pem
openssl  genrsa  -out  server.key  2048
openssl  req  -new  -key  server.key  -subj "/CN=ileiming.com"  -out server.csr
openssl  x509  -req  -in  server.csr  -CA  rootCA.pem  -CAkey  rootCA.key  -CAcreateserial  -out  server.crt  -days  5000

4、拷贝证书:

cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key

5、生成服务端文件:

make  release-server

6、生成客户端文件:

#  linux:
GOOS=linux GOARCH=amd64 make release-client
#  windows:
GOOS=windows GOARCH=amd64 make release-client
#  mac
GOOS=darwin GOARCH=amd64 make release-client

7、服务端启动脚本:

vi /usr/local/sbin/ngrok.sh
#!/bin/bash
/usr/local/ngrok/bin/ngrokd -log="/var/log/ngrok/ngrok.log" -domain="ileiming.com" -httpAddr=:80 -httpsAddr=:443 -tunnelAddr=:4443 1> /dev/null 2> /var/log/ngrok/ngrok.log &
echo $! > /var/run/ngrok.pid

8、服务端创建启动服务:

[Unit]  
Description=ngrok
After=network.target 
[Service]  
Type=forking  
PIDFile=/var/run/ngrok.pid
ExecStart=/bin/bash  /usr/local/sbin/ngrok.sh
ExecStop=pkill  ngrok
PrivateTmp=true  
[Install]  
WantedBy=multi-user.target

9、客户端配置:

server_addr: "ileiming.com:4443"
trust_host_root_certs: false
tunnels:
  abc:
    proto:
      http: "10.122.140.84:17109"

10、客户端启动
这里有个小细节,就是ileiming.com我没有在公网解析,所以要在客户端服务器上的/etc/hosts文件上添加服务端IP

/opt/usr/ngrok/ngrok -config=/opt/usr/ngrok/ngrok.cfg start abc
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《搭建内网穿透利器 ngrok》
文章链接:https://zhuji.vsping.com/2854.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。