Introduction
To manage network relays online, three IoT solutions were evaluated: using Alibaba Cloud's IoT component (high cost), developing a custom TCP/IP solution (long cycle, hard to find talent), or self-deploying an MQTT server (highest cost-effectiveness). This guide details deploying Apache Apollo on an Alibaba Cloud Windows Server 2022 instance, with MQTT.fx as the client.
Environment
- Cloud Platform: Alibaba Cloud
- OS: Windows Server 2022 Datacenter
- Memory: 8GB (7.73GB available)
- CPU: x64-based
- MQTT Broker: Apache Apollo 1.7.1
- MQTT Client: MQTT.fx 1.7.1
Prerequisites
- Alibaba Cloud Account: Register at Alibaba Cloud, then complete real-name authentication (individual or enterprise) in the Personal Center.
Configuration Steps
1. Install Java (JDK)
Apache Apollo requires Java. Follow these steps:
- Download JDK: Get JDK 8 (e.g., from Oracle or Java.com).
- Install JDK: Run the installer (e.g.,
jdk-8u271-windows-x64.exe), choose a path without Chinese characters/spaces (e.g.,D:\Programs\Java\jdk1.8.0_271). - Configure Environment Variables:
- Right-click This PC → Properties → Advanced System Settings → Environment Variables.
- New
JAVA_HOME:D:\Programs\Java\jdk1.8.0_271(match your path). - New
CLASSPATH:%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar - Edit
PATH: Add%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin.
- Verify: Run
java -versionin CMD. A version (≥1.7) confirms success.
2. Deploy Apache Apollo
-
Download: Get Apache Apollo 1.7.1 (e.g., from Apache Archives or a Baidu Netdisk link).
-
Create Broker Instance:
- Extract Apollo to
D:\apache-apollo-1.7.1. - Open CMD in
D:\apache-apollo-1.7.1\binand run:apollo.cmd create mqttBroker - This creates a
mqttBrokerdirectory for configuration.
- Extract Apollo to
-
Configure
apollo.xml:- Edit
D:\apache-apollo-1.7.1\bin\mqttBroker\etc\apollo.xml. - Modify
bindattributes to0.0.0.0(for public network access):<web_admin bind="http://0.0.0.0:61680"/> <web_admin bind="https://0.0.0.0:61681"/> <connector id="tcp" bind="tcp://0.0.0.0:61613" connection_limit="2000"/> <connector id="tls" bind="tls://0.0.0.0:61614" connection_limit="2000"/> <connector id="ws" bind="ws://0.0.0.0:61623" connection_limit="2000"/> <connector id="wss" bind="wss://0.0.0.0:61624" connection_limit="2000"/> - This allows external access via the server’s public IP (e.g.,
http://<public-ip>:61680for web admin,tcp://<public-ip>:61613for MQTT).
- Edit
-
Configure Authentication:
users.properties(inmqttBroker\etc):admin=defaultPasswordgroups.properties(inmqttBroker\etc):admins=admin
-
Start the Broker:
- Open CMD in
D:\apache-apollo-1.7.1\bin\mqttBroker\binand run:apollo-broker.cmd run - A successful start shows logs like
Broker startedandListening on tcp://0.0.0.0:61613.
- Open CMD in
-
Test Access:
- Local: Visit
http://localhost:61680orhttp://127.0.0.1:61680in a browser. The Apollo web console confirms success. - Public Network: Use the server’s public IP (e.g.,
http://<public-ip>:61680).
- Local: Visit
-
Install as Windows Service:
- In
D:\apache-apollo-1.7.1\bin\mqttBroker\bin, run:apollo-broker-service install apollo-broker-service start - Verify via
services.msc(look for "Apache Apollo Broker - mqttBroker").
- In
3. Test with MQTT.fx
-
Download MQTT.fx 1.7.1 (e.g., from Softblade or a Baidu Netdisk link).
-
Configure Connection:
- Open MQTT.fx and click the gear icon (Settings).
- Set:
- Profile Name: Alibaba Cloud MQTT
- Broker Address:
tcp://<public-ip>:61613(replace with your server’s public IP) - Cliant ID: Any unique name (e.g.,
mqttfx_client) - Username/Password:
admin/password(fromusers.properties).
- Click Apply → Connect. A green status confirms success.
-
Publish/Subscribe Test:
- Subscribe: Enter a topic (e.g.,
relay/control) and click Subscribe. - Publish: Enter the same topic, a message (e.g.,
{ "action": "toggle" }), and click Publish. The subscribed topic should receive the message.
- Subscribe: Enter a topic (e.g.,
Final Notes
This setup enables remote management of network relays via MQTT. For production, consider securing the broker with TLS/SSL and using strong authentication. Troubleshoot issues by checking Apollo logs (in mqttBroker\log) or MQTT.fx’s connecsion status.