有一台基于4415软路由安装的ubuntu server系统,在Ubuntu上通过Docker安装了NodeRed。ubuntu通过爱快硬路由与外网连接。爱快硬路由通过动态域名和端口映射实现远程访问ubuntu。
平时通过如下命令运行NodeRed镜像:
docker run -it --rm -e TZ="Asia/Shanghai" -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red
今天想通过NodeRed 的TCP in节点实现tcp sever 远程连接试验。开始构建本地回环试验成功,
源码如下:
[
{
"id": "d84cf2b1f8837955",
"type": "tab",
"label": "本地TCP回环试验",
"disabled": false,
"info": "",
"env": []
},
{
"id": "85e364175e90fb9a",
"type": "inject",
"z": "d84cf2b1f8837955",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 870,
"y": 260,
"wires": [
[
"a8c3cdb131b59931"
]
]
},
{
"id": "ecd663e985f7b601",
"type": "debug",
"z": "d84cf2b1f8837955",
"name": "debug 8",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1020,
"y": 160,
"wires": []
},
{
"id": "665e6d16a4850830",
"type": "tcp in",
"z": "d84cf2b1f8837955",
"name": "",
"server": "server",
"host": "",
"port": "3000",
"datamode": "stream",
"datatype": "utf8",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 860,
"y": 160,
"wires": [
[
"ecd663e985f7b601"
]
]
},
{
"id": "a8c3cdb131b59931",
"type": "tcp out",
"z": "d84cf2b1f8837955",
"name": "",
"host": "127.0.0.1",
"port": "3000",
"beserver": "client",
"base64": false,
"end": false,
"tls": "",
"x": 1030,
"y": 260,
"wires": []
}
]
本地试验成功,开始远程试验。远程试验设置TCP端口为2333,同时爱快软路由的端口映射开放2333端口,设置如图:
远程TCP server 流图
节点设置,注意红线处设置。
流图部署完成后,使用卓岚TCP&UDP调试工具远程连接tcp服务器,但并没有成功。
网络调试工具
经过多次试验终于发现是由于docker没有开放2333端口导致连接试验不成功。后在命令中开放端口得以成功。
增加开放端口完整命令如下:
docker run -it --rm -e TZ="Asia/Shanghai" -p 2333:2333 -p 1880:1880 -v node_red_data:/data --name mynodered nodered/node-red
Docker绑定多个端口的实现
加多个-p
即可
关于端口可参考博主alden_ygq的博客