Edge Box RPi 200 与 Node Red 和 InfluxDB
介绍
在 Edgebox RPi 200(一个树莓派驱动的边缘控制器)上部署 InfluxDB 可以在网络边缘实现强大的时间序列数据收集和分析。这种设置非常适合 IoT 应用,提供实时洞察和监控能力。通过利用轻量级但功能强大的 InfluxDB 数据库,您可以直接在 Edgebox 上高效地管理和分析传感器数据。以下指南概述了在您的 Edgebox RPi 200 上安装、配置和使用 InfluxDB 的步骤,确保无缝集成到您的数据基础设施中。
硬件准备
Edge Box RPi 200 |
---|
![]() |
软件准备
Edge Box 出厂时预装了 Raspberry Pi OS。如果您是第一次启动此设备,请阅读我们的入门指南 Wiki。我们已经准备了一份Node-RED 入门指南。建议您在继续阅读本 wiki 之前先查看此指南。在本教程中,我们将连接运行 YABE 室温模拟器的主机 PC 与运行在 Edge Box 上的 Node-RED。
在 Edgebox RPi 200 上安装 InfluxDB
本指南介绍了在 Edgebox RPi 200 边缘控制器上安装和设置 InfluxDB 的步骤。
步骤 1:更新系统
首先,通过运行以下命令确保您的系统是最新的:SSH 到 EdgeBox 并
sudo apt update
Step 2: Add the InfluxDB Repository
Add the InfluxDB GPG key and repository to your system.
Add the GPG key:
curl https://repos.influxdata.com/influxdata-archive.key | gpg --dearmor | sudo tee /usr/share/keyrings/influxdb-archive-keyring.gpg >/dev/null
Add the repository to the sources list:
echo "deb [signed-by=/usr/share/keyrings/influxdb-archive-keyring.gpg] https://repos.influxdata.com/debian stable main" | sudo tee /etc/apt/sources.list.d/influxdb.list
Step 3: Update Package List
Update the package list to include the InfluxDB repository:
sudo apt update
Step 4: Install InfluxDB
Install InfluxDB version 1
sudo apt install influxdb
Start InfluxDB Server
Enable and start the InfluxDB service:
Step 1. Unmask the service:
sudo systemctl unmask influxdb
Step 2. Enable the service:
sudo systemctl enable influxdb
Step 3. Start the service:
sudo systemctl start influxdb
Testing InfluxDB
Access the InfluxDB CLI tool to perform basic database operations.
Step 1. Open terminal :
influx
Step 2. Create a database:
CREATE DATABASE data
Step 3. Use the database:
USE data
Step 4. Insert a sample data point:
INSERT room,temperature=30.1 humidity=80.2
Step 5. Query the inserted data:
SELECT * FROM room
为 InfluxDB 添加身份验证
步骤 1. 打开终端:
influx
Step 2. Create an admin user with all privileges (replace <password>
with your secure password):
CREATE USER admin WITH PASSWORD '<password>' WITH ALL PRIVILEGES
Step 3. Exit the InfluxDB CLI:
exit
Step 4. Edit the InfluxDB configuration to enable authentication:
sudo nano /etc/influxdb/influxdb.conf
Under the [HTTP]
section, add or modify the following lines:
auth-enabled = true
pprof-enabled = true
pprof-auth-enabled = true
ping-auth-enabled = true
enabled=true
bind-address=":8086"
Step 5. Restart the InfluxDB service to apply the changes:
sudo systemctl restart influxdb
Step 6. Connect to InfluxDB with the admin user:
influx -username admin -password <password>
确保将 <password>
替换为您为管理员用户设置的密码。
通过 Node-RED 向 InfluxDB 发送数据
步骤 1. 在浏览器中打开您的 Node-RED(通常是 http://<your-edgebox-ip>:1880
)。
步骤 2. 使用 Node-RED 管理面板安装 node-red-contrib-influxdb
。
步骤 3. 将一个 inject
节点、一个 function
节点和一个 influxdb out
节点拖放到流画布上,并按如下方式连接它们:
[Inject Node] -> [Function Node] -> [InfluxDB Out Node]
Function 节点
此节点格式化要发送到 InfluxDB 的数据。
步骤 1. 双击 function
节点。
步骤 2. 输入名称(例如,Format Data for InfluxDB
)。
步骤 3. 在函数编辑器中输入以下代码:
msg.payload = [
{
temperature: 30.1,
humidity: 80.2
}
];
return msg;
步骤 4. 点击"Done"。
InfluxDB Out 节点
此节点将格式化的数据发送到 InfluxDB。
步骤 1. 双击 influxdb out
节点。
步骤 2. 输入以下详细信息:
- Name: labdata
- Database: data(之前创建的)
- Measurement: lab
步骤 3. 点击铅笔图标添加新的 InfluxDB 服务器配置。
步骤 4. 输入以下详细信息:
- Name: InfluxDB
- Version: 1.8-flux
- URL:
http://localhost:8086
- Username: admin
- Password:
<password>
(您创建的密码)
步骤 5. 点击"Add"然后点击"Done"。
步骤 6. 点击"Deploy"保存并部署您的流程。
测试流程
-
点击
inject
节点上的按钮手动触发流程。 -
通过在终端运行以下命令检查您的 InfluxDB 数据库,查看数据是否已成功写入:
influx -username admin -password <password>
USE data
SELECT * FROM lab
确保将 <password>
替换为您为管理员用户设置的密码。
技术支持与产品讨论
感谢您选择我们的产品!我们在这里为您提供不同的支持,以确保您使用我们产品的体验尽可能顺畅。我们提供多种沟通渠道,以满足不同的偏好和需求。