如何用树莓派搭建远程服务器 (zerotier)

如何用树莓派搭建远程服务器 (zerotier)

简述

最近一段时间都在使用zerotier,感觉安装和使用起来非常方便,之前在博客中写到的树莓派上外接传感器也可以使用手机远程ssh连接,查看温度、湿度、气压等数据。下边我会把实现的流程写下来,如果有疑问可以留言大家一起讨论。

什么是zerotier

比较直观的解释是将不同网段的设备通过网上一个服务器的中转组成一个局域网,为这些设备分配同一网段的ip。

在使用zerotier之前也有尝试使用花生壳,但是配置起来都感觉有些繁琐,并且花生壳有限制三个设备使用,所以最近发现zerotier是开源的且100个设备连接都是免费的,给了极大的自由度,类似的软件还有frp、nps等。

Our software automatically handles the complexities of networking across physical network boundaries, dealing with mobility, and unifying cloud and edge to free you to spend your time building your projects and running your business.

Our network virtualization technology delivers the power of enterprise software defined networking to every device, service, and application whether it’s located at the edge or in the cloud. With ZeroTier you can treat the entire planet like one data center or cloud region. It’s capable enough for large businesses with complex networking needs but easy enough that tens of thousands of regular people use it to do simple things like play games online or connect to their home PC from their mobile device.

Our software and SDKs help developers build distributed and decentralized applications that are both easier to create and pleasurable to use. We work to solve the hard technical problems underlying decentralized application development so you can deliver applications that offer a positive low-friction user experience while avoiding the cost, liability, and security/privacy impact of a large highly involved cloud presence.

——来自官网的说明

安装

注册

官网注册账号,注册好方便后边连接使用,主界面如下,点击my.zerotier.com:

在这里插入图片描述
点进去后没有账号注册一个即可,登录后可以看到下述界面:

在这里插入图片描述

勾选上边的free,接下来点Networks这里红框选中两个id相同,是之后不同设备连接同一网络的辨识码。点击蓝色的那个ID可以跳入下一个界面

在这里插入图片描述

这个界面可以不勾选Authorized,这样就不需要验证直接就能连接上完,如果勾选的话需要验证才能分配IP,先连接后再这个页面勾选下边复选框,可以起名字辨识不同设备,我发现勾选的话可以比较方便的看到IP地址,也好控制。

在这里插入图片描述

树莓派端安装(linux类均可使用该方法)

安装软件

在树莓派上开一个命令窗口,运行下述命令:

curl -s https://install.zerotier.com | sudo bash

添加网络

下载安装完成后,通过下边连接服务器,将“#”换成Network ID:

sudo zerotier-cli join ################

通过下边这个命令可以查看连接网络:

sudo zerotier-cli listnetworks

在这里插入图片描述
这样就是连接成功了。

配置自启动

sudo systemctl start zerotier-one
#启动
sudo systemctl stop zerotier-one
#停止
systemctl enable zerotier-one
#打开开机自启
systemctl disable zerotier-one
#关闭开机自启

安卓手机安装

http://download.zerotier.com/dist/ZeroTierOne.apk

可以直接从官网下载,还挺快的。

添加网络

点击加号
在这里插入图片描述

这里输入Network ID,两个选项均不勾选。

在这里插入图片描述

连接网络

点一下下边的slid bar就会连接。

在这里插入图片描述

连接成功

连接成功如下所示,如果显示offline,退出程序重新点开连接(感觉手机端app有点抽抽,每次都是退出后重新点击下立刻就获得了ip)

在这里插入图片描述

windows安装

https://download.zerotier.com/dist/ZeroTier%20One.msi

windows配置思路与前两个相同。

使用

手机上也已经连接上了zerotier,怎么使用手机连接树莓派,我使用的是JuiceSSH。

在这里插入图片描述

通过ssh+组成内网的IP就可以连接到树莓派,如下所示,你已经远程连接上树莓派了!

在这里插入图片描述

附录

这里提供网上找到的一个合集,方便大家尝试自己做些东西~

【合集】用Raspberry Pi(树莓派)打造各种服务器

Raspberry Pi(树莓派)有很多的应用,其中搭建服务器是大家应用比较多的,今天就整理一个合集用Raspberry Pi(树莓派)打造各种服务器。
欢迎大家提出宝贵意见,更欢迎大家补充您用树莓派所做的好玩的应用!

[教程] 将树莓派变成网络打印机服务器(更新PC和手机端设置)!
http://www.eeboard.com/bbs/thread-8818-1-1.html
[心得] 【分享】用树莓派构建你自己的微型服务器,可以外网访问
http://www.eeboard.com/bbs/thread-5526-1-1.html
配置树莓派(Raspberry Pi)成为一台完美的家用服务器
http://www.eeboard.com/bbs/thread-20798-1-1.html
[教程] 将树莓派作为自己的软件代码托管服务器!!!
http://www.eeboard.com/bbs/thread-5568-1-1.html
[教程] 树莓派(raspberry pi)学习之安装ftp服务器
http://www.eeboard.com/bbs/thread-27382-1-1.html
[教程] 将树莓派变成一个Web服务器
http://www.eeboard.com/bbs/thread-27383-1-1.html
[教程] 利用树莓派搭建Git私有服务器
http://www.eeboard.com/bbs/thread-27389-1-1.html
太阳能供电的树莓派FTP服务器
http://www.eeboard.com/bbs/thread-27392-1-1.html
[教程] 如何用树莓派搭建一个低能耗的Minecraft服务器
http://www.eeboard.com/bbs/thread-27395-1-1.html
[教程] 树莓派变身Aria2下载服务器
http://www.eeboard.com/bbs/thread-27396-1-1.html
[教程] 用树莓派打造多功能家庭服务器
http://www.eeboard.com/bbs/thread-27399-1-1.html
[教程] 树莓派教程之小型web服务器
http://www.eeboard.com/bbs/thread-27428-1-1.html
[教程] 用树莓派+移动硬盘+MINIDLNA打造家用媒体服务器
http://www.eeboard.com/bbs/thread-27431-1-1.html
[教程] 树莓派搭建NAS服务器
http://www.eeboard.com/bbs/thread-27434-1-1.html
[教程] Raspberry Pi加速上网体验之设置公共DNS查询服务器
http://www.eeboard.com/bbs/thread-27437-1-1.html
[教程] Raspberry Pi——DIY自己的mail服务器,全球可访问
http://www.eeboard.com/bbs/thread-27438-1-1.html
[教程] 树莓派基于asterisk的SIP电话软件交换服务器(免费电话系统)
http://www.eeboard.com/bbs/thread-27442-1-1.html
[教程] 在树莓派上搭建LAMP(Linux Apache Mysql PHP)服务器
http://www.eeboard.com/bbs/thread-27475-1-1.html
[教程] 树莓派上手实战之配置Samba服务器实现网络存储服务器
http://www.eeboard.com/bbs/thread-27482-1-1.html
[教程] 树莓派搭建网站服务器托管WordPress
http://www.eeboard.com/bbs/thread-27483-1-1.html
[教程] 树莓派廉价媒体服务器方案分享 Raspberry Pi DLNA server

http://www.eeboard.com/bbs/thread-27491-1-1.html

树莓派可以使用Mosquitto来搭建MQTT服务器。首先,你需要在树莓派上安装一些依赖环境,包括libssl-dev和uuid-dev。你可以使用以下命令来安装这些依赖环境: ``` sudo apt-get install libssl-dev uuid-dev ``` 接下来,你需要下载Mosquitto的源码并进行安装。你可以从Mosquitto的官方网站下载源码包。下载完成后,你可以使用以下命令来解压源码包: ``` tar -zxvf mosquitto-1.6.9.tar.gz ``` 解压完成后,进入解压后的目录,执行以下命令来编译和安装Mosquitto: ``` cd mosquitto-1.6.9 make sudo make install ``` 安装完成后,你可以使用以下命令来启动Mosquitto服务: ``` mosquitto ``` 现在,你的树莓派上已经成功搭建了MQTT服务器。你可以使用MQTT的客户端来连接和通信。在MQTT协议中,有三种身份:发布者(Publish)、代理(Broker)(服务器)和订阅者(Subscribe)。发布者和订阅者都是客户端,而代理是服务器。发布者可以同时是订阅者。MQTT传输的消息包括主题(Topic)和负载(payload),主题可以理解为消息的类型,而负载是消息的具体内容。你可以使用MQTT客户端来发布和订阅消息。详情可以参考\[2\]中提供的链接。 #### 引用[.reference_title] - *1* [树莓派-搭建MQTT服务](https://blog.csdn.net/ftswsfb/article/details/118662323)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [在树莓派搭建MQTT服务器](https://blog.csdn.net/qq_43010516/article/details/124651792)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机器人梦想家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值