{"id":329,"date":"2019-07-02T14:59:40","date_gmt":"2019-07-02T14:59:40","guid":{"rendered":"https:\/\/silviamarin.ro\/?p=76"},"modified":"2019-07-02T14:59:40","modified_gmt":"2019-07-02T14:59:40","slug":"instalare-node-red-2","status":"publish","type":"post","link":"https:\/\/marinelvis.xyz\/index.php\/2019\/07\/02\/instalare-node-red-2\/","title":{"rendered":"INSTALARE SI SECURIZARE NODE-RED"},"content":{"rendered":"<p><strong>Instalare pe Debian<\/strong><br \/>\nSe descarca si executa scriptul de instalare:<\/p>\n<pre>curl -sL https:\/\/deb.nodesource.com\/setup_12.x &gt; setup_12.x \nchmod +x setup_12.x\n.\/setup_12.x<\/pre>\n<p>Se instaleaza NodeJS:<\/p>\n<pre>apt install -y nodejs<\/pre>\n<p>Verificarea versiunii si instalarea Node-RED:<\/p>\n<pre>node -v\u00a0\napt install -y build-essential libssl-dev\nnpm install -g --unsafe-perm node-red<\/pre>\n<p>Node-RED porneste cu:<\/p>\n<pre>node-red -v<\/pre>\n<p><strong>Instalare pe Raspberry Pi<\/strong><br \/>\nSe instaleaza Nodejs 16 apoi Node Red:<\/p>\n<pre>curl -fsSL https:\/\/deb.nodesource.com\/setup_16.x | sudo -E bash -\napt install nodejs\nbash &lt;(curl -sL https:\/\/raw.githubusercontent.com\/node-red\/linux-installers\/master\/deb\/update-nodejs-and-nodered)\nsystemctl enable nodered.service<\/pre>\n<p>Se reporneste sistemul.<\/p>\n<p><strong>Node Red ca serviciu pe Debian<\/strong><\/p>\n<p>Se creeaza fisierul <em>node-red.service<\/em>:<\/p>\n<pre>nano \/etc\/systemd\/system\/node-red.service<\/pre>\n<p>Se introduce urmatorul continut:<\/p>\n<blockquote><p><em># This script work on any system using systemd as the init process.<\/em><br \/>\n<em># It works on Debian\/Raspbian Jessie.<\/em><br \/>\n<em># If you have Debian\/Rapbian Wheezy and want to use this script with systemd <\/em><br \/>\n<em># follow the information here : https:\/\/wiki.debian.org\/systemd<\/em><\/p>\n<p><em># To easily download, install and set at startup:<\/em><br \/>\n<em># wget -O \/tmp\/download https:\/\/gist.github.com\/Belphemur\/3f6d3bf211b0e8a18d93\/download &amp;&amp; sudo tar -zxf \/tmp\/download &#8211;strip-components 1 -C \/etc\/systemd\/system\/ &amp;&amp; sudo systemctl &#8211;reload-daemon &amp;&amp; sudo systemctl enable Node-RED<\/em><\/p>\n<p><em># To consult the log : journalctl -u Node-RED<\/em><br \/>\n<em>[Unit]<\/em><br \/>\n<em>Description=Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.<\/em><br \/>\n<em>After=syslog.target network.target<\/em><br \/>\n<em>Documentation=http:\/\/nodered.org\/<\/em><\/p>\n<p><em>[Service]<\/em><br \/>\n<em>#Environment=&#8221;NODE_OPTIONS=&#8211;max-old-space-size=128&#8243;<\/em><br \/>\n<em>#Environment=&#8221;NODE_RED_OPTIONS=-v&#8221;<\/em><br \/>\n<em>#Full Path to Node.js<\/em><br \/>\n<em>ExecStart=\/usr\/bin\/node-red<\/em><br \/>\n<em>WorkingDirectory=\/root\/.node-red\/<\/em><br \/>\n<em># User\/Group that launches node-RED (it&#8217;s advised to create a new user for Node-RED)<\/em><br \/>\n<em># You can do : sudo useradd node-red<\/em><br \/>\n<em># then change the User=root by User=node-red<\/em><br \/>\n<em>User=root<\/em><br \/>\n<em>Group=root<\/em><br \/>\n<em>Nice=10<\/em><br \/>\n<em>SyslogIdentifier=Node-RED<\/em><br \/>\n<em>StandardOutput=syslog<\/em><br \/>\n<em># Make Node-RED restart if it fails<\/em><br \/>\n<em>Restart=on-failure<\/em><br \/>\n<em># Node-RED need a SIGINT to be notified to stop<\/em><br \/>\n<em>KillSignal=SIGINT<\/em><\/p>\n<p><em>[Install]<\/em><br \/>\n<em>WantedBy=multi-user.target<\/em><\/p><\/blockquote>\n<p>Apoi:<\/p>\n<pre>systemctl daemon-reload\nsystemctl enable node-red.service\nsystemctl start node-red.service<\/pre>\n<pre><\/pre>\n<p><strong>Securizarea Node Red<\/strong><br \/>\nIn folderul unde este instalat Node Red se instaleaza <em>node-red-admin<\/em>:<\/p>\n<pre>cd ~\/.node-red\nnpm install -g node-red-admin<\/pre>\n<p>Se genereaza hash-ul parolei:<\/p>\n<pre>node-red-admin hash-pw<\/pre>\n<p>Se introduce parola si se genereaza hash-ul care se copie si se introduce \u00een <em>settings.js<\/em>:<br \/>\nSe deschide fisierul <em>settings.js<\/em>:<\/p>\n<pre>cd ~\nnano \/.node-red\/settings.js<\/pre>\n<p>In sectiunea Securing Node-RED se activeaza proprietatile <em>adminAuth:<\/em>, <em>https:<\/em> si <em>requireHttps: true<\/em>.<br \/>\nIn campul <em>adminAuth<\/em> se inlocuieste hash-ul parolei cu cel generat anterior cu <em>node-red-admin<\/em>. Se pot crea si alti utilizatori cu hash-urile parolelor generate ca mai sus. Inregistrarile specifice fiecarui utilizator trebuie sa fie despartite cu virgula:<\/p>\n<blockquote><p><em>adminAuth: {<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 type: &#8222;credentials&#8221;,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 users: [{<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 username: &#8222;admin&#8221;,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 password: &#8222;$2a$08$kaZUjDcoXWQRNADAGavWNOej9wrW2Ps0rAdtHcKOaQwQlBEJO00l6&#8221;,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 permissions: &#8222;*&#8221;<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 },<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 username: &#8222;elvis&#8221;,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 password: &#8222;$2a$08$kaZUjDcoXWQRNADAGavWNOej9wrW2Ps0rAdtHcKOaQwQlBEJO00l6&#8221;,<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 permissions: &#8222;*&#8221;<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }]<\/em><br \/>\n<em>\u00a0\u00a0\u00a0 },<\/em><\/p><\/blockquote>\n<p>\u00cen campul <em>https:<\/em> se completeaza calea p\u00e2n\u0103 la certificatele Let\u2019s Encrypt:<\/p>\n<blockquote><p><em>https: {<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 key: fs.readFileSync(&#8216;\/etc\/letsencrypt\/live\/<span style=\"color: #ff0000;\">silviamarin.ro<\/span>\/privkey.pem&#8217;),<\/em><br \/>\n<em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cert: fs.readFileSync(&#8216;\/etc\/letsencrypt\/live\/<span style=\"color: #ff0000;\">silviamarin.ro<\/span>\/cert.pem&#8217;)<\/em><\/p><\/blockquote>\n<p>Pentru securizarea paginii statice generate de Node Red se activeaza <em>httpNodeAuth:<\/em> si <em>httpStaticAuth:<\/em> unde se inlocuieste <em>\u201euser\u201d<\/em> si hash-ul parolei utilizatorulu respectiv. \u00cen ambele campuri trebuie sa fie acelasi utilizator;<\/p>\n<blockquote><p><em>httpNodeAuth: {user:&#8221;elvis&#8221;,pass:&#8221;$2a$08$kaZUjDcoXWQRNADAGavWNOej9wrW2Ps0rAdtHcKOaQwQlBEJO00l6&#8243;},<\/em><br \/>\n<em>\u00a0\u00a0\u00a0 httpStaticAuth: {user:&#8221;elvis&#8221;,pass:&#8221;$2a$08$kaZUjDcoXWQRNADAGavWNOej9wrW2Ps0rAdtHcKOaQwQlBEJO00l6&#8243;},<\/em><\/p><\/blockquote>\n<p>Se salveaza fisierul <em>settings.js<\/em> si se reporneste Node Red<br \/>\nAccesul la Node Red se face la adresa:<\/p>\n<blockquote><p><em>https:\/\/<span style=\"color: #ff0000;\">silviamarin.ro<\/span>:<span style=\"color: #0000ff;\">18800<\/span>\u00a0 (editorul)<\/em><\/p><\/blockquote>\n<p>sau<\/p>\n<blockquote><p><em>https:\/\/<span style=\"color: #ff0000;\">silviamarin.ro<\/span>:<span style=\"color: #0000ff;\">18800<\/span>\/ui\u00a0 (pagina statica)<\/em><\/p><\/blockquote>\n<p><strong>Suplimentar<\/strong><br \/>\nPentru captura imaginilor de pe camerele de supraveghere trebuie instalat <em>ffmpeg<\/em>:<\/p>\n<pre>apt-get install ffmpeg -y<\/pre>\n<p>Pentru captura video de pe camerele de supraveghere trebuie instalat\u00a0<em>video4linux2<\/em>:<\/p>\n<pre>apt-get install v4l-utils -y<\/pre>\n<p>Pentru captura imaginilor de pe webcam-uri USB trebuie instalat\u00a0<em>fswebcam<\/em>:<\/p>\n<pre>apt-get install fswebcam -y<\/pre>\n<p>Pentru NVR se creeaza folderele necesare:<\/p>\n<pre>mkdir \/mnt\/DIVERSE\nmkdir \/mnt\/DIVERSE\/CAM\/\nmkdir \/mnt\/DIVERSE\/CAM\/camPOARTA\nmkdir \/mnt\/DIVERSE\/CAM\/camCURTE\nmkdir \/mnt\/DIVERSE\/CAM\/camHOL\nchmod 777 -R \/mnt &amp;&amp; chown -R nobody:nogroup \/mnt<\/pre>\n<p>Dupa instalarea pe server a\u00a0<em>SQLite<\/em> si <em>InfluxDB<\/em>\u00a0se instaleaza nodurile suplimentare in Node-Red:<br \/>\n<em>node-red-dashboard<\/em><br \/>\n<em>node-red-node-sqlite<\/em><br \/>\n<em>node-red-contrib-bigtimer<\/em><br \/>\n<em>node-red-contrib-tradfri<\/em><br \/>\n<em>node-red-node-pushbullet<\/em><br \/>\n<em>node-red-contrib-pushsafer<\/em><br \/>\n<em>node-red-node-email<\/em><br \/>\n<em>node-red-node-darksky<\/em><br \/>\n<em>node-red-contrib-web-worldmap<\/em><br \/>\n<em>node-red-node-geofence<\/em><br \/>\n<em>node-red-contrib-moment<\/em><br \/>\n<em>node-red-contrib-google-sheets<\/em><br \/>\n<em>node-red-node-mysql<\/em><br \/>\n<em>node-red-contrib-influxdb<\/em><br \/>\n<em>node-red-contrib-dashboard-average-bars<\/em><br \/>\n<em>node-red-contrib-throttle<\/em><br \/>\n<em>node-red-contrib-chronos<\/em><br \/>\n<em>node-red-contrib-fs<\/em><\/p>\n<p>Pentru tradfri trebuie instalate pachetele CoAP:<\/p>\n<pre>cd \/root\/.node-red\napt-get install libtool git build-essential autoconf automake\ngit clone --recursive https:\/\/github.com\/obgm\/libcoap.git\ncd libcoap\ngit checkout dtls\ngit submodule update --init --recursive\n.\/autogen.sh\n.\/configure --disable-documentation --disable-shared\nmake\nmake install<\/pre>\n<p>Calea pentru CoAP va fi:<br \/>\n<em>\/root\/.node-red\/libcoap\/examples\/coap-client<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Instalare pe Debian Se descarca si executa scriptul de instalare: curl -sL https:\/\/deb.nodesource.com\/setup_12.x &gt; setup_12.x chmod +x setup_12.x .\/setup_12.x Se instaleaza NodeJS: apt install -y nodejs Verificarea versiunii si instalarea Node-RED: node -v\u00a0 apt install -y build-essential libssl-dev npm install -g &#8211;unsafe-perm node-red Node-RED porneste cu: node-red -v Instalare pe Raspberry Pi Se instaleaza Nodejs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-329","post","type-post","status-publish","format-standard","hentry","category-fara-categorie"],"_links":{"self":[{"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/posts\/329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":0,"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"wp:attachment":[{"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marinelvis.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}