ลด 50% ทุกแพ็กเกจ เวลาจำกัด เริ่มต้นที่ $2.48/mo
Node-RED

Node-RED

Node-RED คือเครื่องมือเขียนโปรแกรมแบบ visual flow สามารถลากและวางลอจิกสำหรับ IoT, APIs และ pipeline อัตโนมัติภายในบ้าน พร้อม node จากชุมชนกว่า 4,000 รายการ พัฒนาโดย IBM ภายใต้ OpenJS Foundation และเป็น automation engine มาตรฐานในวงการ industrial IoT

Version

Latest

Operating System

Ubuntu Server 24.04 LTS

Min. RAM

1 GB

IP Types

IPV4,IPV6

การเข้าถึง Node-RED

  • เปิดเบราว์เซอร์แล้วไปที่: https://<SERVER_IP>
  • คาดว่าจะมีคำเตือน SSL จากเบราว์เซอร์ (self-signed certificate)
  • ต้องมีการยืนยันตัวตน (Basic Auth popup)
  • วิธียืนยันตัวตน: HTTP Basic Auth
  • ข้อมูล credentials ถูกเก็บอย่างปลอดภัยใน: /root/.cloudzy-creds

ไฟล์และไดเรกทอรีสำคัญ

  • ไดเรกทอรีติดตั้งหลักอยู่ที่ /root/node-red.
  • ไฟล์ orchestration ของ Docker อยู่ที่ /root/node-red/docker-compose.yml.
  • ข้อมูล Node-RED แบบถาวรถูกเก็บไว้ที่ /var/lib/docker/volumes/node-red_node-red-data/_data.
  • ไฟล์การตั้งค่า Nginx อยู่ที่ /etc/nginx/sites-available/node-red.
  • ข้อมูล basic authentication ถูกเก็บไว้ที่ /etc/nginx/auth/node-red.htpasswd.
  • ใบรับรอง TLS ถูกเก็บไว้ใน /etc/nginx/ssl.

Service Management

ตรวจสอบสถานะ container:

docker ps

View logs:

docker compose -f /root/node-red/docker-compose.yml logs -f

รีสตาร์ท Node-RED:

docker compose -f /root/node-red/docker-compose.yml restart

Restart Nginx:

systemctl restart nginx

ผู้ใช้ Admin ของ Node-RED (ทางเลือกแทน Basic Auth)

Node-RED มีระบบยืนยันตัวตนภายในของตัวเอง ซึ่งสามารถใช้แทน HTTP Basic Auth ได้

1. Locate settings.js

ไฟล์คอนฟิกหลักอยู่ใน volume Docker ของ Node-RED: /var/lib/docker/volumes/node-red_node-red-data/_data/settings.js

2. Enable adminAuth

Open settings.js และยกเลิกคอมเมนต์ (หรือเพิ่ม) adminAuth ส่วนนี้ ควรมีหน้าตาประมาณนี้:

  adminAuth: {
      type: "credentials",
      users: [
          {
              username: "admin",
              password: "<HASHED_PASSWORD>",
              permissions: "*"
      }]
  },

3. สร้าง password hash

คุณสามารถสร้าง hash ได้จากภายใน container ของ Node-RED:

docker exec -it node-red-node-red-1 node-red admin hash-pw

ระบบจะให้คุณกรอกรหัสผ่านแบบ plain text

คัดลอก hash ที่ได้และวางเป็นค่าของ password value in settings.js.

4. รีสตาร์ท Node-RED

After editing settings.js:

docker compose -f /root/node-red/docker-compose.yml restart

5. ปิดใช้งาน HTTP Basic Auth ใน Nginx (ไม่บังคับ)

แก้ไขไฟล์ไซต์ Nginx: /etc/nginx/sites-available/node-red

ลบหรือคอมเมนต์บรรทัดเหล่านี้:

auth_basic "Restricted";
auth_basic_user_file /etc/nginx/auth/node-red.htpasswd;

Reload Nginx:

systemctl restart nginx

เปิดใช้งาน SSL พร้อมโดเมน

1. ชี้โดเมนของคุณไปที่ IP ของเซิร์ฟเวอร์

2. แก้ไขไฟล์คอนฟิก Nginx และแทนที่ทั้งสองส่วน server_name <IP>; ด้วยโดเมนของคุณ (<your-domain>) สำหรับทั้งบล็อก HTTP (port 80) และ HTTPS (port 443):

vim /etc/nginx/sites-available/node-red

3. Install Certbot:

apt install -y certbot python3-certbot-nginx

4. รันคำสั่งต่อไปนี้เพื่อสร้างใบรับรอง Let's Encrypt ที่ถูกต้อง:

certbot certonly --nginx --non-interactive --agree-tos --email [email protected] -d yourdomain.com

5. แทนที่พาธ SSL ในไฟล์คอนฟิก Nginx:

vim /etc/apache2/sites-available/node-red
# Before:
    # ssl_certificate /etc/nginx/ssl/fullchain.pem;
    # ssl_certificate_key /etc/nginx/ssl/privkey.pem;
# After:
    # ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    # ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;

6. รีสตาร์ท Nginx เพื่อให้การเปลี่ยนแปลงมีผล:

systemctl restart nginx

7. เปิดเบราว์เซอร์และไปที่: https://yourdomain.com

เพิ่มเติมใน Development Tools

Related apps.

ติดตั้ง Node-RED เลย เริ่มต้นที่ $2.48/เดือน