วันอังคารที่ 6 มิถุนายน พ.ศ. 2566

Linux_Node-RED

Node-red: Install node-red on Ubuntu 20.04

Node-red: Open firewall port ufw allow 1880

sudo apt update Node-red:current version or set version curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash - curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -

cat /etc/apt/sources.list.d/nodesource.list

sudo apt -y install nodejs Node-red: if error

sudo dpkg -i --force-overwrite


node -v

npm -v

sudo npm install -g --unsafe-perm node-red

node-red -v

Node-red: Upgrade for new version

sudo npm install -g --unsafe-perm node-red


**----------------------------------------------

Node-red admin: add new user for startup service

useradd -s /bin/bash -d /home/pm2/ -m -G sudo pm2

passwd pm2

su - pm2

Node-red admin: Installation

npm install -g --unsafe-perm node-red-admin

Node-red admin: get hash admin password

node-red admin hash-pw

Node-red admin: find config path (/home/pm2/.node-red/settings.js)

node-red --settings

CTRL+C Node-red admin: Build "admin" password:

sudo node-red admin hash-pw

Node-red admin: Edit config file from path

vi /home/pm2/.node-red/settings.js


Node-red admin: line adminAuth: and remove //


Node-red admin: Insert Certificate:

ค้นหา //https: { // key: require("fs").readFileSync('privkey.pem'), // cert: require("fs").readFileSync('cert.pem') //}, แก้เป็น




ค้นหา //requireHttps: true, แก้เป็น




**-----------------------------------------------

pm2: Install process management for node-red

su - pm2

sudo npm install -g pm2


pm2: Get path

which node-red


pm2: Create script for boot

vi app.json

[

   {

      "script"    : "/usr/local/bin/node-red",

      "name"      : "node-red:1880"

   },

   {

      "script"    : "/usr/local/bin/node-red",

      "args"      : "/home/pm2/.node-red/api1.json -p 1881",

      "name"      : "node-red api1:1881"

   },

   {

      "script"    : "/usr/local/bin/node-red",

      "args"      : "/home/pm2/.node-red/api2.json -p 1882",

      "name"      : "node-red api2:1881"

   }

]



pm2: run background process

pm2 start api.json -- -v


pm2: run background process
pm2 start /usr/local/bin/node-red -- -v


pm2: config start on boot

pm2 save pm2 startup pm2: copy & past

sudo env PATH=$PATH:/usr/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u pm2 --hp /home/pm2/

pm2 Stop/start Service:

pm2 list pm2 list --sort name:desc pm2 show 0

pm2 stop "all" pm2 start 0 pm2 restart 0 1

pm2 delete 1


pm2: view information

pm2 info node-red

pm2: Log install

pm2 install pm2-logrotate pm2 set pm2-logrotate:rotateInterval '00 00 * * 6' [every sunday 12.00 pm]

pm2 conf


pm2: Log read

pm2 logs node-red pm2 logs 0 pm2 flush


pm2 monit

sudo ps -ef | grep node-red

sudo lsof -i :1880e-red