ubuntu install node-red
ubuntu install node-red
安装Node-RED
1. 更新系统包列表
首先,更新您的系统包列表以确保所有软件包都是最新的:
sudo apt update
2. 安装Node.js
Node-RED依赖于Node.js,因此我们需要先安装Node.js。可以使用Ubuntu的包管理器来安装:
sudo apt install nodejs npm
安装完成后,验证Node.js的版本:
node -v
npm -v
3. 安装Node-RED
现在我们可以使用npm来安装Node-RED:
sudo npm install -g --unsafe-perm node-red node-red-admin
这个命令将Node-RED全局安装到您的系统上。
4. 启动Node-RED
安装完成后,可以通过以下命令启动Node-RED:
sudo node-red
Node-RED将启动并打开默认的Web界面,通常是在浏览器中访问 http://localhost:1880
配置Node-RED
1. 创建Node-RED用户
为了安全起见,建议为Node-RED创建一个单独的用户:
sudo deluser --remove-home node-red
sudo delgroup node-red
sudo addgroup --system node-red
sudo adduser --system --ingroup node-red --home /home/node-red --disabled-password --shell /bin/false node-red
sudo -u node-red -H id
2. 设置环境变量
将Node-RED用户添加到sudoers文件中,以便它可以运行作为root的命令:
echo "node-red ALL=(ALL) NOPASSWD: $( which node-red )" | sudo tee -a /etc/sudoers.d/node-red
echo "node-red ALL=(ALL) NOPASSWD: $( which node-red-pi )" | sudo tee -a /etc/sudoers.d/node-red
echo "node-red ALL=(ALL) NOPASSWD: $( which node-red-admin )" | sudo tee -a /etc/sudoers.d/node-red
sudo cat /etc/sudoers.d/node-red
3. 使用systemd管理Node-RED
编辑文件 sudo vi /usr/lib/systemd/system/node-red.service
[Unit] Description=Node-RED After=network.target [Service] ExecStart=/usr/local/bin/node-red WorkingDirectory=/home/node-red User=node-red Group=node-red Restart=on-failure KillMode=control-group [Install] WantedBy=multi-user.target
为了方便管理,我们可以使用systemd来启动和停止Node-RED:
sudo systemctl daemon-reload
sudo systemctl stop node-red
sudo systemctl start node-red
sudo systemctl status node-red
sudo systemctl enable node-red
4. 使用systemd管理Node-RED
设置登录密码为 dt123456
node-red-admin hash-pw
Password: $2y$08$/DITs//2YCadPadVBbICGejCO7TuZYStXBd.2V6FllRlBWz3yB5L6
编辑文件 sudo -u node-red -H vi /home/node-red/.node-red/settings.js
adminAuth: { type: "credentials", users: [{ username: "admin", password: "$2y$08$/DITs//2YCadPadVBbICGejCO7TuZYStXBd.2V6FllRlBWz3yB5L6", permissions: "*" }] },
重启服务 sudo systemctl restart node-red.service
========= End