n8n
安装
docker方式
https://docs.n8n.io/hosting/installation/docker/
#https://hub.docker.com/r/n8nio/n8n
docker pull n8nio/n8n:latest
docker rm -f n8n;
docker run -it \
--network macvlan --hostname n8n \
-e TZ="Asia/Shanghai" \
-e GENERIC_TIMEZONE="Asia/Shanghai" \
-e DB_TYPE=mysqldb \
-e DB_MYSQLDB_DATABASE=n8n \
-e DB_MYSQLDB_HOST=192.168.199.100 \
-e DB_MYSQLDB_PORT=3306 \
-e DB_MYSQLDB_USER=root \
-e DB_MYSQLDB_PASSWORD=admin \
--name n8n \
-d -p 5678:5678 \
-v /mnt/usb2/n8n:/home/node/.n8n \
n8nio/n8n:latestn8n start --tunnel
k8s方式
https://truecharts.org/charts/stable/n8n
helm upgrade --install -n n8n --create-namespace my-n8n oci://tccr.io/truecharts/n8n -f values.yaml
values.yaml 如下:
#https://github.com/truecharts/public/blob/master/charts/stable/n8n/values.yaml
env:- name: N8N_SECURE_COOKIEvalue: "false"
使用示例
01.定时执行脚本上报PVE温度
在之前文章中:06.Proxmox ve(PVE) 显示CPU温度、NVME硬盘温度、主板温度(三种方式),介绍了一劳永逸方式,上报温度到InfluxDB中,其中创建定时任务使用的Linux的cron,这次打算使用n8n来实现此功能。下将下面的给注释掉:
nano /etc/cron.d/influx_stats# Upload stats to InfluxDB2
#* * * * * root /root/sensors/pve_temp_stats_to_influxdb2.sh >/dev/null 2>&1
配置两个触发节点:
运行一次:Manual Trigger node
定时触发:Schedule Trigger node
配置SSH执行节点:
SSH Execute Command
bash pve_temp_stats_to_influxdb2.sh >/dev/null 2>&1
执行结果:
node-red
安装
k8s方式
https://truecharts.org/charts/stable/node-red/
helm upgrade --install -n node-red --create-namespace node-red oci://tccr.io/truecharts/node-red
docker-compose 方式
# https://nodered.org/docs/getting-started/docker#docker-stack--docker-compose################################################################################# Node-RED Stack or Compose################################################################################# docker stack deploy node-red --compose-file docker-compose-node-red.yml# docker-compose -f docker-compose-node-red.yml -p myNoderedProject up################################################################################node-red:container_name: node-redimage: nodered/node-red:3.1.9environment:- TZ=Asia/Shanghaiports:- "1880:1880"volumes:- /root/node-red:/data- /root/node-red/node_modules:/usr/src/node-red/node_modulesrestart: unless-stoppedprivileged: truenetwork_mode: host
节点管理
嫌麻烦,可以一键安装:
npm install node-red-contrib-flow-manager node-red-contrib-home-assistant-websocket
node-red-contrib-flow-manager
https://flows.nodered.org/node/node-red-contrib-flow-manager
flow-manager将您的flows.json分离为多个文件,便于今后由于越来越多的flow在一个文件里面不好维护,子目录如下:
● /flows/flow name
● /subflows/subflow name
● /config-nodes.json (global config nodes will be stored here)
安装之前这样:
d@d:/mnt/k8s-csi/pvc-5ddd6131-373b-45eb-811d-493f5fa6ae3d$ ls
flows_cred.json flows.json lib node_modules package.json package-lock.json settings.js
安装之后这样:
d@d:/mnt/k8s-csi/pvc-5ddd6131-373b-45eb-811d-493f5fa6ae3d$ ls
config-nodes.json flow-manager-nodes-order.json flows_cred.json lib package.json settings.js
flow-manager-cfg.json flows flows.json node_modules package-lock.json subflows
node-red-contrib-home-assistant-websocket
https://flows.nodered.org/node/node-red-contrib-home-assistant-websocket
Node-RED通过websocket和REST API与Home Assistant集成
配置
https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/#configuration
demo
这块的内容有点多,到时候合并到home-assistant里面讲
里面的示例可以参考这个:
https://github.com/node-red/node-red/tree/master/packages/node_modules/%40node-red/nodes/examples/common
进阶示例:
https://cookbook.nodered.org/
编辑器教程:
https://nodered.org/docs/user-guide/editor/
问题
1.node-red下载节点很慢怎么办?
输入命令
npm config set registry http://mirrors.cloud.tencent.com/npm/
或
npm config set registry https://registry.npmmirror.com
验证命令
npm config get registry
如果返回https://registry.npmmirror.com,说明镜像配置成功
2.Error: EACCES: permission denied, copyfile
https://github.com/node-red/node-red-docker/issues/221
sudo chown 1000 /root/node-red;