当前位置:网站首页>完整的搭建内网穿透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 //重新加载配置文件
注意事项

边栏推荐
- Adobe是什么?
- C专家编程 第3章 分析C语言的声明 3.1 只有编译器才会喜欢的语法
- “68道 Redis+168道 MySQL”精品面试题(带解析),你背废了吗?
- 工程仪器设备在线监测管理系统常见问题和注意事项
- C专家编程 第1章 C:穿越时空的迷雾 1.9 阅读ANSI C标准,寻找乐趣和裨益
- 请问下这个hologres维表是被缓存了么?怎么直接Finished了
- [Unity Getting Started Plan] Basic Concepts (7) - Input Manager & Input Class
- Halcon 小笔记 C# 图片是否有效
- Hannah荣获第六季完美童模全球总决赛全球人气总冠军
- Web3的开源为何会如此受到人们喜爱?
猜你喜欢

Web3 安全风险令人生畏?应该如何应对?

Component communication - parent-child component communication

高效的组织信息共享知识库是一种宝贵的资源

LeetCode·899.有序队列·最小表示法

Adobe是什么?

沃尔沃:这是会“种草”的“安全感”!

Interviews are no longer hanged!This is the correct way to open the seven schemes of Redis distributed locks

Auto Scaling 弹性伸缩(运维释放人力)

TiKV & TiFlash 加速复杂业务查询丨TiFlash 应用实践
[redis] cache penetration and cache avalanche and cache breakdown solutions
随机推荐
软考 --- 软件工程(1)概念、开发模型
请问下这个hologres维表是被缓存了么?怎么直接Finished了
C专家编程 第1章 C:穿越时空的迷雾 1.7 编译限制
204. Count Primes
J9数字虚拟论:元宇宙的潜力:一股推动社会进步的力量
中小微企业如何简单便捷、低成本实现数字化?360视觉云有妙招
使用uniapp 封装一个request 请求
高效的组织信息共享知识库是一种宝贵的资源
【LeetCode】899. 有序队列
Excuse me this hologres dimension table is cached?How to Finished
掌握Redis的Sentinel哨兵原理,可助你拿到25k的offer
组件通信--下拉菜单案例
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
双指针/滑动窗口问题
C专家编程 第3章 分析C语言的声明 3.6 typedef int x[10]和#define x int[10]的区别
[Unity Starter Plan] Making RubyAdventure01 - Player Creation & Movement
生产环境如何删除表呢?只能在SQL脚本里执行 drop table 吗
产品-Axure9英文版,轮播图效果
Selective Search学习笔记
【系统学习编程-编程入门-全民编程 视频教程】