当前位置:网站首页>完整的搭建内网穿透ngrok详细教程(有图有真相)
完整的搭建内网穿透ngrok详细教程(有图有真相)
2022-08-03 16:58:00 【InfoQ】
准备工作(其实也是硬性条件):
工具:
安装:
1.git安装
# 安装git
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++
2.安装go

tar -zxvf go1.12.4.linux-amd64.tar.gz /usr/local/
# go的命令需要做软连接到/usr/bin
ln -s /usr/local/go/bin/* /usr/bin/
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin
source /etc/profile
go version

go env

3.安装ngrok
cd /usr/local/
//ngrok下载地址
git clone https://github.com/inconshreveable/ngrok.git

export GOPATH=/usr/local/ngrok/
#这里写你自己的域名,不要前缀,比如www.abc.club 填写abc.club (域名已备案)
export NGROK_DOMAIN="abc.club"
4.生成ngrok证书并覆盖原有的证书
cd /usr/local/ngrok
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
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key
生成服务端
cd /usr/local/ngrok/
GOOS=linux GOARCH=amd64 make release-server

生成客户端
cd /usr/local/ngrok/
GOOS=windows GOARCH=amd64 make release-client

#Linux 平台 32 位系统:GOOS=linux GOARCH=386
#Linux 平台 64 位系统:GOOS=linux GOARCH=amd64
#Windows 平台 32 位系统:GOOS=windows GOARCH=386
#Windows 平台 64 位系统:GOOS=windows GOARCH=amd64
#MAC 平台 32 位系统:GOOS=darwin GOARCH=386
#MAC 平台 64 位系统:GOOS=darwin GOARCH=amd64
#ARM 平台:GOOS=linux GOARCH=arm
服务端的启动
./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="abc.club" -httpAddr=":80" -httpsAddr=":443" -tunnelAddr=":4443"
参数说明:
#-domain 访问ngrok是所设置的服务地址生成证书时那个
#-httpAddr http协议端口 默认为80
#-httpsAddr https协议端口 默认为443
#-tunnelAddr 通道端口 默认4443

二级域名的映射设置

客户端的启动
server_addr: "abc.club:4443"
trust_host_root_certs: false
ngrok -config=./ngrok.cfg -subdomain=test 8080
#参数说明
ngrok.cfg 刚才新建的文件
-subdomain=test test:穿透的域名前缀
8080 :穿透的域名映射端口


@echo OFF
color 0a
Title boom Ngrok启动工具
Mode con cols=109 lines=30
:START
set /p clientid= 请输入前缀:
echo.
set /p port= 请输入端口:
echo.
ngrok -config=ngrok.cfg -subdomain %clientid% %port%
PAUSE
goto TUNNEL
图形界面

将ngrok设置为系统服务 并且开机自启
vim /etc/rc.d/init.d/ngrok
#!/bin/bash
#chkconfig: - 99 01
#description:ngrok
case "$1" in
start)
echo "start ngrok service.."
cd /usr/local/ngrok/
setsid ./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="abc.club" -httpAddr=":80" -httpsAddr=":443" -tunnelAddr=":4443"
;;
*)
exit 1
;;
esac
###参数说明:
### cd /usr/local/ngrok/:进入ngrok目录
### setsid:开始没有这个 结果关闭窗口 发现服务停掉了 加上目前好用
### setsid ./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="abc.club" -httpAddr=":80" -httpsAddr=":443" -tunnelAddr=":4443" :启动ngrok服务端命令
chmod 755 ngrok
chkconfig --add ngrok
chkconfig

service ngrok start
systemctl enable ngrok.service //加入开机启动
systemctl daemon-reload //重新加载配置文件
注意事项

边栏推荐
猜你喜欢
protobuf 反射使用总结
[Unity Getting Started Plan] Basic Concepts (7) - Input Manager & Input Class
学会 Arthas,让你 3 年经验掌握 5 年功力!
组件通信--下拉菜单案例
2年开发经验去面试,吊打面试官,即将面试的程序员这些笔记建议复习
11. Container With Most Water
[Unity Starter Plan] Making RubyAdventure01 - Player Creation & Movement
“LaMDA 存在种族歧视,谷歌的 AI 伦理不过是‘遮羞布’!”
Web3 安全风险令人生畏?应该如何应对?
蒋松廷 荣获第六季完美童模全球总决赛 全球总冠军
随机推荐
沃尔沃:这是会“种草”的“安全感”!
C专家编程 第3章 分析C语言的声明 3.2 声明是如何形成的
C专家编程 第2章 这不是Bug,而是语言特性 2.1 这关语言特性何事,在Fortran里这就是Bug呀
vant自动上传图片/文件
最强分布式锁工具:Redisson
C专家编程 第3章 分析C语言的声明 3.9 轻松一下---驱动物理实体的软件
Web3的开源为何会如此受到人们喜爱?
#夏日挑战赛#【FFH】OpenHarmony设备开发基础(四)启动流程
高薪程序员&面试题精讲系列132之微服务之间如何进行通信?服务熔断是怎么回事?你熟悉Hystrix吗?
leetcode:202. 快乐数
【系统学习编程-编程入门-全民编程 视频教程】
数据中台“集存通用治”功能场景说明
Promise的 简单使用
如何直击固定资产管理的难题?
FinClip | 2022 年 7 月产品大事记
Looking at the ecological potential of Hongmeng OS from the evolution of MatePad Pro
Description of the functional scenario of "collective storage and general governance" in the data center
5. Longest Palindromic Substring
C专家编程 第3章 分析C语言的声明 3.6 typedef int x[10]和#define x int[10]的区别
After using Stream for many years, does collect still have these "saucy operations"?