基于MQTT的开源全平台内网隧道穿透Tunnel服务搭建方法

我们在本地开发的时候经常需要进行公网的访问和调试, 这就需要用到内网穿透技术了, 今天介绍一款基于MQTT协议的, 低功耗,轻量级内网隧道穿透服务端和客户端,   基于go语言开发, 免费开源的内网隧道穿透服务工具 mqtt_tunnel   基于MQTT协议的内网穿透服务端

MQTT服务端 Mosquitto 安装配置

Eclipse Mosquitto™ An open source MQTT broker

#Debian/Ubuntu system:
apt-get install mosquitto
  • Configure Mosquitto

Create /etc/mosquitto/conf.d/acl.conf with just the following contents:

# 访问规则配置文件
acl_file /etc/mosquitto/conf.d/acl.txt

# 禁止匿名用户访问
allow_anonymous false

# 用户密码文件
password_file /etc/mosquitto/conf.d/pwfile.security

# MQTT服务绑定IP 0.0.0.0 表示本地所有可用IP
bind_address 0.0.0.0

MQTT访问规则配置文件 /etc/mosquitto/conf.d/acl.txt

# This affects access control for clients with no username.
topic read $SYS/#

# This only affects clients with username "admin".
user admin
topic foo/bar

# This affects all clients.
pattern readwrite clients/#
# 添加用户 admin/admin888
# 同样连续会提示连续输入两次密码 admin888 。注意第二次创建用户时不用加 -c 如果加 -c 会把第一次创建的用户覆盖。
mosquitto_passwd -c /etc/mosquitto/conf.d/pwfile.security admin

# 重启服务
systemctl restart mosquitto

# 订阅测试
mosquitto_sub -h 192.168.0.99 -u admin -P admin888 -d -t clients/admin

# 消息发布测试 另外打开一个窗口
mosquitto_pub -h 192.168.0.99 -u admin -P admin888 -d -t clients/admin -m "hello, tekin"

MQTT隧道服务端和客户端服务启动

-username=admin -password=admin888 这个是链接MQTT服务的用户名和密码

# 服务端:
# -port=80 这个端口是你的服务访问的端口, 即 admin.example.com 的访问端口
./tunnel-server-linux-amd64 serve -port=80 -host=0.0.0.0 -username=admin -password=admin888

# 客户端 
# -expose="localhost:8000" 这个是你本地要暴露到公网的服务地址和端口, 
# -name=admin 这个是你的服务名 最终访问域名为 admin.example.com
./tunnel-client-linux-amd64 client -expose="localhost:8000" -name=admin -tunnel=example.com  -username=admin -password=admin888

修改你的域名DNS解析,增加泛域名解析到

*.example.com

防火墙开放端口 1883

访问: http://admin.example.com/ 即可访问你在内网服务的 http://localhost:8000/

服务端和客户端下载地址

https://gitee.com/tekintian/mqtt_tunnel/releases/tag/v1.0

  • 28
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值