# Synology 使用Docker架設LibreNMS

##### **運行環境**

- **DSM 7.2**

##### **安裝LibreNMS**

**確認已安裝[Portainer](https://note.homesitetw.com/books/synology/page/synology-portainer-docker#bkmrk-%E5%AE%89%E8%A3%9Ddocker%E5%92%8Cportainer)，在docker內新增資料夾librenms並且在裡面分別新增data、db、redis資料夾**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/czaimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/czaimage.png)

**修改資料夾權限使docker能夠寫入執行**

```
chmod 755 /volume1/docker/librenms -R
```

**進入Portainer，點選堆棧(Stack)，並添加堆棧**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/7hMimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/7hMimage.png)

**名稱填寫`librenms`，並貼到<span dir="auto">編輯器中，指令內PUID和PGID於Shell內執行id並自行替換</span>**

```
user1@synology:~$ id
uid=1026(user1) gid=100(users)
```

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/WN2image.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/WN2image.png)

```
services:
  db:
    image: mariadb:11.4-noble #LTS Long Time Support Until May 29, 2029.
    container_name: LibreNMS-DB
    command:
      - mariadbd
      - --innodb-file-per-table=1
      - --lower-case-table-names=0
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    volumes:
      - /volume1/docker/librenms/db:/var/lib/mysql:rw
    environment:
      TZ: Asia/Taipei
      MARIADB_RANDOM_ROOT_PASSWORD: yes
      MARIADB_DATABASE: librenms
      MARIADB_USER: librenmsuser
      MARIADB_PASSWORD: librenmspass
    restart: on-failure:5

  redis:
    image: redis:7.2-alpine
    container_name: LibreNMS_REDIS
    healthcheck:
     test: ["CMD-SHELL", "redis-cli ping || exit 1"]
    volumes:
      - /volume1/docker/librenms/redis:/data:rw
    environment:
      TZ: Asia/Taipei
    restart: on-failure:5


  librenms:
    image: librenms/librenms:latest
    container_name: LibreNMS
    healthcheck:
      test: ["CMD-SHELL", "nc -z 127.0.0.1 8000 || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 90s
    hostname: librenms
    cap_add:
      - NET_ADMIN
      - NET_RAW
    ports:
      - target: 8000
        published: 28083
        protocol: tcp
    depends_on:
      - db
      - redis
    volumes:
      - /volume1/docker/librenms/data:/data:rw
    environment:
      TZ: Asia/Taipei
      PUID: 1026
      PGID: 100
      SESSION_SECURE_COOKIE: true
      DB_HOST: db
      DB_NAME: librenms
      DB_USER: librenmsuser
      DB_PASSWORD: librenmspass
      DB_TIMEOUT: 120
      MEMORY_LIMIT: 512M
      MAX_INPUT_VARS: 1000
      UPLOAD_MAX_SIZE: 128M
      OPCACHE_MEM_SIZE: 128
      REAL_IP_FROM: 0.0.0.0/32
      REAL_IP_HEADER: X-Forwarded-For
      LOG_IP_VAR: remote_addr
      CACHE_DRIVER: redis
      SESSION_DRIVER: redis
      REDIS_HOST: redis
      LIBRENMS_SNMP_COMMUNITY: librenmsdocker
      LIBRENMS_WEATHERMAP: false
      LIBRENMS_WEATHERMAP_SCHEDULE: "0 0 */2 * * *" # Schedule WeatherMAP every 2 hours
    restart: on-failure:5

  dispatcher:
    image: librenms/librenms:latest
    container_name: LibreNMS-DISPATCHER
    hostname: librenms-dispatcher
    cap_add:
      - NET_ADMIN
      - NET_RAW
    depends_on:
      - librenms
      - redis
    volumes:
      - /volume1/docker/librenms/data:/data:rw
    environment:
      TZ: Asia/Taipei
      PUID: 1026
      PGID: 100
      DB_HOST: db
      DB_NAME: librenms
      DB_USER: librenmsuser
      DB_PASSWORD: librenmspass
      DB_TIMEOUT: 120
      DISPATCHER_NODE_ID: dispatcher1
      SIDECAR_DISPATCHER: 1
      MEMORY_LIMIT: 512M
      MAX_INPUT_VARS: 1000
      UPLOAD_MAX_SIZE: 128M
      OPCACHE_MEM_SIZE: 128
      REAL_IP_FROM: 0.0.0.0/32
      REAL_IP_HEADER: X-Forwarded-For
      LOG_IP_VAR: remote_addr
      CACHE_DRIVER: redis
      SESSION_DRIVER: redis
      REDIS_HOST: redis
      LIBRENMS_SNMP_COMMUNITY: librenmsdocker
      LIBRENMS_WEATHERMAP: false
      LIBRENMS_WEATHERMAP_SCHEDULE: "0 0 */2 * * *" # Schedule WeatherMAP every 2 hours
    restart: on-failure:5
    
  syslogng:
    image: librenms/librenms:latest
    container_name: LibreNMS_SYSLOGNG
    hostname: librenms-syslogng
    healthcheck:
      test: ["CMD-SHELL", "nc -z 127.0.0.1 514 || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 90s
    cap_add:
      - NET_ADMIN
      - NET_RAW
    depends_on:
      - librenms
      - redis
    ports:
      - target: 514
        published: 514
        protocol: tcp
      - target: 514
        published: 514
        protocol: udp
    volumes:
      - /volume1/docker/librenms/data:/data:rw
    environment:
      TZ: Asia/Taipei
      PUID: 1026
      PGID: 100
      DB_HOST: db
      DB_NAME: librenms
      DB_USER: librenmsuser
      DB_PASSWORD: librenmspass
      DB_TIMEOUT: 120
      SIDECAR_SYSLOGNG: 1
      MEMORY_LIMIT: 512M
      MAX_INPUT_VARS: 1000
      UPLOAD_MAX_SIZE: 128M
      OPCACHE_MEM_SIZE: 128
      REAL_IP_FROM: 0.0.0.0/32
      REAL_IP_HEADER: X-Forwarded-For
      LOG_IP_VAR: remote_addr
      CACHE_DRIVER: redis
      SESSION_DRIVER: redis
      REDIS_HOST: redis
      LIBRENMS_SNMP_COMMUNITY: librenmsdocker
      LIBRENMS_WEATHERMAP: false
      LIBRENMS_WEATHERMAP_SCHEDULE: "0 0 */2 * * *" # Schedule WeatherMAP every 2 hours
    restart: on-failure:5

  snmptrapd:
    image: librenms/librenms:latest
    container_name: LibreNMS_SNMPTRAPD
    healthcheck:
      test: ["CMD-SHELL", "nc -z 127.0.0.1 162 || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 90s
    hostname: librenms-snmptrapd
    cap_add:
      - NET_ADMIN
      - NET_RAW
    depends_on:
      - librenms
      - redis
    ports:
      - target: 162
        published: 162
        protocol: tcp
      - target: 162
        published: 162
        protocol: udp
    volumes:
      - /volume1/docker/librenms/data:/data:rw
    environment:
      TZ: Asia/Taipei
      PUID: 1026
      PGID: 100
      DB_HOST: db
      DB_NAME: librenms
      DB_USER: librenmsuser
      DB_PASSWORD: librenmspass
      DB_TIMEOUT: 120
      SIDECAR_SNMPTRAPD: 1
      MEMORY_LIMIT: 512M
      MAX_INPUT_VARS: 1000
      UPLOAD_MAX_SIZE: 128M
      OPCACHE_MEM_SIZE: 128
      REAL_IP_FROM: 0.0.0.0/32
      REAL_IP_HEADER: X-Forwarded-For
      LOG_IP_VAR: remote_addr
      CACHE_DRIVER: redis
      SESSION_DRIVER: redis
      REDIS_HOST: redis
      LIBRENMS_SNMP_COMMUNITY: librenmsdocker
      LIBRENMS_WEATHERMAP: false
      LIBRENMS_WEATHERMAP_SCHEDULE: "0 0 */2 * * *" # Schedule WeatherMAP every 2 hours
    restart: on-failure:5

  scheduler:
    image: librenms/librenms:latest
    container_name: LibreNMS_scheduler
    volumes:
      - /volume1/docker/librenms/data:/data:rw   # 請與主容器掛載的路徑一致
    environment:
      - SIDECAR_CRON=1
      - DB_HOST=db
      - DB_NAME=librenms
      - DB_USER=librenmsuser
      - DB_PASSWORD=librenmspass
      - PUID=1026
      - PGID=100
      - TZ=Asia/Taipei
    depends_on:
      - db
      - redis
      - librenms
    restart: on-failure:5



```

**部屬堆棧**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/u4dimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/u4dimage.png)

**成功後右上角應會顯示堆棧部署成功**

**等待幾分鐘安裝，確認所有服務已經執行**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/R5pimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/R5pimage.png)

**輸入IP和設定的PORT，例如`http://Synology IP:28083`，進入LibreNMS 安裝頁面**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/Buhimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/Buhimage.png)

**建立管理員後完成安裝**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/f5fimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/f5fimage.png)

<p class="callout warning">**若出現419 Page Expired先清除快取**  
</p>

**點選LibreNMS容器並進入終端**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/aOkimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/aOkimage.png)

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/j06image.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/j06image.png)

```
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear
```

**重新整理網頁後再次登入**

<p class="callout warning">**若輸入網址後直接跳過安裝頁面到登入畫面請手動新增使用者**</p>

**點選LibreNMS容器並進入終端新增使用者**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/aOkimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/aOkimage.png)

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/Wzdimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/Wzdimage.png)

```
lnms user:add --role=admin user1
```

**重新整理網頁後再次登入**

**進行組態驗證確認無錯誤設定，若有依照建議修正**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/JZnimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/JZnimage.png)

##### **開始監控Synology設備**

**開啟SNMP功能**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/cxximage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/cxximage.png)

**LibreNMS新增Synology設備，輸入IP和community**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/hhLimage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/hhLimage.png)

**查看已新增的設備**

[![image.png](https://note.homesitetw.com/uploads/images/gallery/2025-09/scaled-1680-/k9Limage.png)](https://note.homesitetw.com/uploads/images/gallery/2025-09/k9Limage.png)