Home Assistant 搭建日志(七)——安装NodeRed
對于NodeRed的安裝,最簡單的就是直接使用apt來安裝,但是這樣會出現個問題,就是安裝NodeRed時,要安裝依賴NodeJS和NPM,而當前buster源里,NodeJS的版本是10.15.2~dfsg-2+rpi1,NPM的版本是5.8.0+ds6-4,這兩個版本之間并不是完全兼容的,所以使用的時候會一直報警告,使用npm install有些情況還出現錯誤。例如在安裝 NeteaseCloudMusicApi 就一直失敗。
 雖然可以通過命令npm install -g npm把NPM升級到新版,但是之前apt是把NPM安裝在/usr/bin里,升級命令是把新的NPM安裝到/usr/local/bin里,造成同時存在兩個版本的NPM,系統也會默認使用久的NPM?,F在嘗試一下非常規的安裝方法,看看后續會不會發生一些神奇的問題。
1. 手動查看軟件源
有一次,我好奇到軟件源里看了下,看下是不是真的只有NPM 5.8.0+ds6-4這個版本。
 NPM安裝包的軟件源位置
 發現有其它的NPM版本
 
 但是在apt-cache里只能查到5.8.0+ds6-4這個版本
然后就在百度查查查查查了一下,發現了這樣個網頁
 https://packages.debian.org/bullseye/npm
 里面可以看到,6.13.4+ds-2這個版本的NPM在bullseye發行版本可以下載,在buster版本下只能下載5.8.0+ds6-4,那么,如果我直接把下載源更換到bullseye發行版本,那不就可以下載NPM 6.13.4+ds-2?嘗試一下。
2. 更換軟件源
sudo vi /etc/apt/source.list # 把之前舊的 deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib deb-src http://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib=># 更換為新的 deb http://mirrors.aliyun.com/raspbian/raspbian/ bullseye main non-free contrib deb-src http://mirrors.aliyun.com/raspbian/raspbian/ bullseye main non-free contrib更新下軟件源
sudo apt-get update查看下NPM的版本
pi@pi:~ $ apt-cache show npm Package: npm Version: 6.13.4+ds-2 Installed-Size: 3412 Maintainer: Debian Javascript Maintainers <pkg-javascript-devel@lists.alioth.debian.org> Architecture: all Depends: nodejs (>= 6.11~), ca-certificates, node-abbrev (>= 1.1.1~), node-ajv, node-ansi, node-ansi-regex (>= 3.0~), node-ansi-styles, node-ansistyles, node-aproba, node-archy (>= 1.0~), node-are-we-there-yet, node-asap, node-asn1, node-assert-plus, node-asynckit, node-aws4, node-aws-sign2, node-balanced-match, node-bcrypt-pbkdf, node-bl, node-bluebird, node-boxen, node-brace-expansion, node-builtin-modules, node-builtins, node-cacache, node-call-limit, node-camelcase, node-caseless, node-chalk, node-chownr, node-ci-info, node-cli-boxes, node-cliui, node-clone, node-co, node-color-convert, node-color-name, node-colors, node-columnify, node-combined-stream, node-concat-map, node-concat-stream, node-config-chain, node-configstore, node-console-control-strings, node-copy-concurrently, node-core-util-is, node-cross-spawn, node-crypto-random-string, node-cyclist, node-dashdash, node-debug, node-decamelize, node-deep-extend, node-defaults, node-define-properties, node-delayed-stream, node-delegates, node-detect-indent, node-detect-newline, node-dot-prop, node-duplexer3, node-duplexify, node-ecc-jsbn, node-editor, node-encoding, node-end-of-stream, node-err-code, node-errno, node-es6-promise, node-escape-string-regexp, node-execa, node-extend, node-extsprintf, node-fast-deep-equal, node-find-up, node-flush-write-stream, node-forever-agent, node-form-data, node-from2, node-fs.realpath, node-fs-vacuum, node-fs-write-stream-atomic, node-function-bind, node-gauge, node-genfun, node-get-caller-file, node-getpass, node-glob (>= 7.1.2~), node-got, node-graceful-fs (>= 4.1.11~), node-gyp (>= 3.6.2~), node-har-schema, node-har-validator, node-has-flag, node-has-unicode, node-hosted-git-info (>= 2.6~), node-http-signature, node-iconv-lite, node-iferr, node-import-lazy, node-imurmurhash, node-inflight, node-inherits (>= 2.0.3~), node-ini (>= 1.3.5~), node-invert-kv, node-ip, node-ip-regex, node-isarray, node-isexe, node-is-npm, node-is-obj, node-is-path-inside, node-is-retry-allowed, node-is-stream, node-isstream, node-is-typedarray, node-jsbn, node-jsonparse, node-json-parse-better-errors, node-json-schema, node-json-schema-traverse, node-jsonstream (>= 1.3.2~), node-json-stringify-safe, node-jsprim, node-latest-version, node-lazy-property, node-lcid, node-libnpx, node-locate-path, node-lodash, node-lockfile (>= 1.0.3~), node-lowercase-keys, node-lru-cache (>= 4.1.1~), node-make-dir, node-mem, node-mime, node-mime-types, node-mimic-fn, node-minimatch, node-minimist, node-mississippi, node-mkdirp (>= 0.5.1~), node-move-concurrently, node-ms, node-mute-stream, node-nopt, node-normalize-package-data (>= 2.4~), node-npm-bundled, node-npm-package-arg (>= 6.1.1), node-npmlog (>= 4.1.2~), node-number-is-nan, node-oauth-sign, node-object-assign, node-once (>= 1.4~), node-opener, node-osenv (>= 0.1.5~), node-os-locale, node-os-tmpdir, node-package-json, node-parallel-transform, node-path-exists, node-path-is-absolute, node-path-is-inside, node-promise-inflight, node-promise-retry, node-promzard, node-performance-now, node-p-finally, node-pify, node-p-limit, node-p-locate, node-prepend-http, node-process-nextick-args, node-proto-list, node-prr, node-pseudomap, node-psl, node-pump, node-pumpify, node-punycode, node-qs, node-qw, node-rc, node-read (>= 1.0.7~), node-readable-stream, node-read-package-json (>= 2.0.13~), node-registry-auth-token, node-registry-url, node-request (>= 2.83~), node-require-main-filename, node-require-directory, node-resolve-from (>= 4.0~), node-retry (>= 0.10.1~), node-rimraf (>= 2.6.2~), node-run-queue, node-safe-buffer, node-semver (>= 5.5~), node-set-blocking, node-sha (>= 2.0.1~), node-shebang-command, node-shebang-regex, node-signal-exit, node-slide (>= 1.1.6~), node-sorted-object, node-slash, node-semver-diff, node-spdx-correct, node-spdx-exceptions, node-spdx-expression-parse, node-spdx-license-ids, node-sshpk, node-ssri, node-stream-each, node-stream-iterate, node-stream-shift, node-strict-uri-encode, node-string-decoder, node-string-width, node-strip-ansi (>= 4.0~), node-strip-json-comments, node-strip-eof, node-supports-color, node-tar (>= 4.4~), node-term-size, node-text-table, node-through, node-through2, node-timed-out, node-tough-cookie, node-tunnel-agent, node-tweetnacl, node-typedarray, node-uid-number, node-unique-filename, node-unique-string, node-unpipe, node-url-parse-lax, node-util-deprecate, node-uuid, node-validate-npm-package-name, node-verror, node-which (>= 1.3~), node-which-module, node-wide-align, node-widest-line, node-wrap-ansi, node-wrappy, node-wcwidth.js, node-write-file-atomic, node-xdg-basedir, node-xtend, node-yargs, node-yargs-parser, node-yallist, node-y18n Size: 646912 SHA256: 00aba43c95437be619d5a94d138774f06aa866f972e2ddcfb10e07eb6a823aed SHA1: e94e4f762a069060a29a19eed339f05f9f454c8d MD5sum: 046c392aaaaf8e6008549b4cfc9d9630 Description: package manager for Node.jsNode.js is an event-based server-side javascript engine..npm is the package manager for the Node JavaScript platform. It putsmodules in place so that node can find them, and manages dependencyconflicts intelligently..It is extremely configurable to support a wide variety of use cases.Most commonly, it is used to publish, discover, install, and developnode programs. Description-md5: 85ba8bf129c09297837a706dcf08eb1f Homepage: https://docs.npmjs.com/ Section: web Priority: optional Filename: pool/main/n/npm/npm_6.13.4+ds-2_all.deb可以看到版本是6.13.4+ds-2
3. 安裝NodeRed
既然NPM可以下載6.13.4+ds-2版本,那就嘗試下直接安裝NodeRed
sudo apt-get install nodered然后在安裝的時候彈出了這樣一個東西,嚇Q死我
 
 Google翻譯一下,是說更新了一些服務,需要重啟那些服務什么的,那就Yes吧。
 然后就直接安裝完成了。
這里要記得把軟件源從 bullseye 換回 buster,然后更新軟件源
4. 順便替換了NPM國內的源
npm config set registry https://registry.npm.taobao.org5. 啟動NodeRed
sudo systemctl start nodered.service# 查看下運行狀態 systemctl status nodered.service# 一發入魂,直接成功,設置開機自啟 sudo systemctl enable nodered.service6. 修改NodeRed配置
vi ~/.node-red/settings.js慣例修改綁定端口
# 找到 uiPort: process.env.PORT || 1880,# 修改為(小心不要干掉最后的逗號,) uiPort: process.env.PORT || 新的端口,網頁進去的賬號密碼
現在在網頁進入是不需要賬號密碼,直接進到NodeRed的工作臺的首先安裝一個加密庫bcryptjs用于生成密碼npm install bcryptjs 然后在配置文件里面找到adminAuth模塊,把這一整個模塊的注釋去掉,編輯里面內容:adminAuth: {type: "credentials",users: [{username: "你想要的用戶名",password: "加密后的密碼",permissions: "*"}] }, 使用下面的命令生成加密后的密碼,例如密碼為123456node -e "console.log(require('bcryptjs').hashSync(process.argv[1], 8));" 123456 生成出來加密后的密碼$2a$08$2Jq.v9vMdmDmA6issbvRqO/OkNLXT8mH01BdkuYSWwGJI.Gwk/A9. 把這串字符串粘貼到上面配置加密后的密碼那里,就可以通過用戶名和123456登錄到NodeRed控制臺了。當然,要先重啟服務。sudo systemctl restart nodered.service
配置完畢,下一章嘗試創建流程,用NodeRed控制HA的組件(貌似現在只有MPD)。
上一章:Home Assistant 搭建日志(六)——MPD播放器
 下一章:Home Assistant 搭建日志(八)——NodeRed控制HA
總結
以上是生活随笔為你收集整理的Home Assistant 搭建日志(七)——安装NodeRed的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 小屁孩语录
- 下一篇: A2021-A2022年度项目总结(二)
