Tổng quan

Hướng dẫn này sẽ giúp bạn nhanh chóng thiết lập và chạy G-BlackHole Forwarder trong vài phút. Chúng ta sẽ:
  1. Xác thực với Registry (nếu sử dụng)
  2. Chạy Forwarder ở foreground để test
  3. Cài đặt Forwarder như service

Bước 1: Xác thực với Registry (tùy chọn)

Nếu bạn sử dụng Registry server, hãy xác thực trước:

Windows

# Xác thực với Registry
.\blackhole-fwd.exe auth --key "your-api-key-here"

Linux

# Xác thực với Registry
./blackhole-fwd auth --key "your-api-key-here"

Bước 2: Chạy Forwarder ở Foreground

Test Forwarder bằng cách chạy ở foreground để xem logs trực tiếp:

Windows

# Chạy Forwarder ở foreground với verbose logging
.\blackhole-fwd.exe start --config config.yml --verbose

# Hoặc với log level debug
.\blackhole-fwd.exe start --config config.yml --log-level debug

Linux

# Chạy Forwarder ở foreground với verbose logging
./blackhole-fwd start --config config.yml --verbose

# Hoặc với log level debug
./blackhole-fwd start --config config.yml --log-level debug
Kiểm tra hoạt động:
  • Xem logs trên console để đảm bảo Forwarder đang chạy các service
  • Kiểm tra MQTT broker đang listen trên port 1883
  • Kiểm tra Rsyslog server đang listen trên port 514
  • Kiểm tra HTTP proxy đang listen trên port 8080
  • Xác nhận dữ liệu được gửi đến sink (Registry nếu đã cấu hình)
Dừng Forwarder:
  • Nhấn Ctrl+C để dừng Forwarder

Bước 3: Cài đặt Forwarder như Service

Sau khi test thành công, cài đặt Forwarder như service để chạy tự động:

Windows

# Cài đặt Windows Service
.\blackhole-fwd.exe service install --config config.yml

# Khởi động service
.\blackhole-fwd.exe service start

# Kiểm tra trạng thái service
Get-Service -Name "blackhole-fwd"

Linux

# Cài đặt systemd service
sudo ./blackhole-fwd service install --config config.yml

# Khởi động service
sudo ./blackhole-fwd service start

# Kiểm tra trạng thái service
sudo systemctl status blackhole-fwd

Xác minh cài đặt

Kiểm tra Service Status

Windows:
# Xem trạng thái service
Get-Service -Name "blackhole-fwd"

# Xem logs của service
Get-EventLog -LogName Application -Source "blackhole-fwd" -Newest 10
Linux:
# Xem trạng thái service
sudo systemctl status blackhole-fwd

# Xem logs của service
sudo journalctl -u blackhole-fwd -f

Kiểm tra Ports Listening

# Kiểm tra các port đang listen
netstat -tlnp | grep -E ":(1883|514|8080)"

# Hoặc sử dụng ss command
ss -tlnp | grep -E ":(1883|514|8080)"

Test các Service

Test MQTT Broker

# Test publish message
mosquitto_pub -h localhost -p 1883 -t "test/topic" -m "Hello Forwarder"

# Test subscribe
mosquitto_sub -h localhost -p 1883 -t "test/topic" -v

Test Rsyslog Server

# Test UDP syslog
echo "test syslog message" | nc -u localhost 514

# Test TCP syslog
echo "test syslog message" | nc localhost 514

Test HTTP CONNECT Proxy

# Test proxy connection
curl --proxy http://localhost:8080 https://httpbin.org/ip

# Test với authentication (nếu đã cấu hình)
curl --proxy http://username:password@localhost:8080 https://httpbin.org/ip

Kiểm tra Logs

Windows:
# Xem log files
Get-Content ".\logs\default.log" -Tail 20
Get-Content ".\logs\default-error.log" -Tail 10
Linux:
# Xem log files
tail -f /var/log/blackhole-forwarder/default.log
tail -f /var/log/blackhole-forwarder/default-error.log

Tóm tắt lệnh

Windows

# Quick Start Commands
.\blackhole-fwd.exe auth --key "your-api-key-here"  # Nếu dùng Registry
.\blackhole-fwd.exe start --config config.yml --verbose  # Test
.\blackhole-fwd.exe service install --config config.yml
.\blackhole-fwd.exe service start

Linux

# Quick Start Commands
./blackhole-fwd auth --key "your-api-key-here"  # Nếu dùng Registry
./blackhole-fwd start --config config.yml --verbose  # Test
sudo ./blackhole-fwd service install --config config.yml
sudo ./blackhole-fwd service start