LoginSignup
3
2
個人開発エンジニア応援 - 個人開発の成果や知見を共有しよう!-

Ubuntu 22.04LTSでNode-RED の最新バージョン(3.1)をインストールする

Last updated at Posted at 2023-09-19

普段Dockerでインストールすることが多くなったので、
あまり気になっていなかったのですが、OSに直接node-redをインストールするタイミングができたので、
備忘録を兼ねて記載します。

書こうと思ったきっかけ: Node.jsのインストーラがSCRIPT DEPRECATION WARNINGとなった

なんか赤いバーが強調してもう使えないよと・・・(カラーコードOnのTerminalではそれはもうびっくりするくらい目立ちました)

$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -

================================================================================
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
================================================================================

                           SCRIPT DEPRECATION WARNING


  This script, located at https://deb.nodesource.com/setup_X, used to
  install Node.js is deprecated now and will eventually be made inactive.

  Please visit the NodeSource distributions Github and follow the
  instructions to migrate your repo.
  https://github.com/nodesource/distributions

  The NodeSource Node.js Linux distributions GitHub repository contains
  information about which versions of Node.js and which Linux distributions
  are supported and how to install it.
  https://github.com/nodesource/distributions


                          SCRIPT DEPRECATION WARNING

================================================================================
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
================================================================================

TO AVOID THIS WAIT MIGRATE THE SCRIPT
Continuing in 60 seconds (press Ctrl-C to abort) ...

^C

潔くCtl+Cで抜けます。

NODESOURCEのページを見ると、たしかにだいぶ手順が変わったので、おとなしく
この手順に従ってみよう

導入手順

Node.js 18 をインストール

NODE_MAJOR=18のところがバージョン指定なので20とか適当に変更ができる。
今回はNode-REDの推奨Node.JSバージョンが現在18なので、18で指定。

~$ sudo apt-get update
~$ sudo apt-get install -y ca-certificates curl gnupg
~$ sudo mkdir -p /etc/apt/keyrings
~$ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
~$ NODE_MAJOR=18
~$ echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
~$ sudo apt-get update
~$ sudo apt-get install nodejs -y

Node-REDのインストール

インストールは以下を参考に実施

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

Node-REDの自動起動設定

このままだとOS再起動しても上がってこないので、pm2を入れて自動起動を設定。

~$ sudo npm install -g pm2
~$ pm2 start /usr/bin/node-red -- -v
~$ pm2 save
~$ pm2 startup

起動したか確認

~$ pm2 status
┌────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name        │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ node-red    │ default     │ N/A     │ fork    │ 25216    │ 10m    │ 0    │ online    │ 0%       │ 90.9mb   │ user  │ disabled │
└────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

設定して再起動するとき

~$ pm2 restart node-red

ログ確認をするとき

黙ってtail -f と同じ状況になる。

~$ pm2 logs node-red

設定ファイルのありか

導入に使用したアカウントの~/.node-red配下にファイルが作られている。
このままでは認証なしなので、適宜設定を行う必要がある。

設定したもの

パスワード変更

以下をコメントアウトする。

    //adminAuth: {
    //    type: "credentials",
    //    users: [{
    //        username: "admin",
    //        password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.",
    //        permissions: "*"
    //    }]
    //},

password部分はハッシュ化する必要があるので、

$ node-red admin hash-pw
Password: 聞かれるのでここで入力する
{ハッシュ値}

戻ってきた{ハッシュ値}をコピーして、password: "{ここ}",に入れる。

UIパスの変更

以下をコメントアウトする。

httpAdminRoot: '/admin',

これでUIがhttp://{ipaddress}:1880/adminに変わる。文字は好きなものでもよいと思われ

TODO?

  • どっかでansible playbook作っておくと便利そうだな
  • Dockerでも良いならそっちのほうが楽だな
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2