跳到主要内容

Setup immich at Synology DSM

·776 字

1.代理设置 #

由于国内无法访问 ghcr.io ,需要给它配置代理,或者使用他人提供的镜像。

此处使用最简单的方法,即直接在 DSM 中配置 HTTP 代理,HTTP 代理请自行配置。

Setup_HTTP_Proxy

如图所示,在 控制面板-网络-代理服务器中填入 IP地址和端口,确定后 Docker 服务也会自动配置相同的代理,可通过 docker system info 验证。

$ docker system info
Client:
 Version:    24.0.2
 Context:    default
 Debug Mode: false

Server:
 Containers: 21
  Running: 10
  Paused: 0
  Stopped: 11
 Images: 28
 Server Version: 24.0.2
 Storage Driver: btrfs
  Btrfs: 
 Logging Driver: db
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs db fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 067f5021280b8de2059026fb5c43c4adb0f3f244
 runc version: 0320c58
 init version: ed96d00
 Security Options:
  apparmor
 Kernel Version: 5.10.55+
 Operating System: Synology NAS
 (containerized)
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.18GiB
 Name: DSM
 ID: a5a189e8-40bb-4b63-9fe6-4b8d70705fe6
 Docker Root Dir: /volume2/@docker
 Debug Mode: false
 HTTP Proxy: 192.168.123.19:7890 # 此处发现代理已经自动同步过来
 HTTPS Proxy: 192.168.123.19:7890
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support

2.建立项目 #

由于在上一步已经配置好了代理,此处直接使用 docker-compose 建立项目,需要映射的文件夹请自己提前建立好。

我修改的地方不多:

  1. 手动指定了版本号

  2. 配置好了 Nvidia 显卡加速,但默认并没有启用,需要启用的话将 image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release} 改为 image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}-cuda 即可。

  3. 直接将机器学习放模型的位置映射出来,便于手动下载

.env:

# You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables

# The location where your uploaded files are stored
UPLOAD_LOCATION=./library
# The location where your database files are stored
DB_DATA_LOCATION=./postgres

# To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
TZ=Asia/Shanghai

# The Immich version to use. You can pin this to a specific version like "v1.71.0"
IMMICH_VERSION=v1.130.1

# Connection secret for postgres. You should change it to a random password
# Please use only the characters `A-Za-z0-9`, without special characters or spaces
DB_PASSWORD=YOUR_PASSWORD

# The values below this line do not need to be changed
###################################################################################
DB_USERNAME=postgres
DB_DATABASE_NAME=immich

compose.yaml:

#
# WARNING: To install Immich, follow our guide: https://immich.app/docs/install/docker-compose
#
# Make sure to use the docker-compose.yml of the current release:
#
# https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
#
# The compose file on main may not be compatible with the latest release.

name: immich

services:
  immich-server:
    container_name: immich_server
    image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
    # extends:
    #   file: hwaccel.transcoding.yml
    #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
    volumes:
      # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    env_file:
      - .env
    ports:
      - '2283:2283'
    depends_on:
      - redis
      - database
    restart: always
    healthcheck:
      disable: false

  immich-machine-learning:
    container_name: immich_machine_learning
    # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
    # Example tag: ${IMMICH_VERSION:-release}-cuda
    image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities:
                - gpu
    # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration
    #   file: hwaccel.ml.yml
    #   service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable
    volumes:
      - ./model-cache:/cache
    env_file:
      - .env
    restart: always
    healthcheck:
      disable: false

  redis:
    container_name: immich_redis
    image: docker.io/redis:6.2-alpine@sha256:148bb5411c184abd288d9aaed139c98123eeb8824c5d3fce03cf721db58066d8
    healthcheck:
      test: redis-cli ping || exit 1
    restart: always

  database:
    container_name: immich_postgres
    image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:739cdd626151ff1f796dc95a6591b55a714f341c737e27f045019ceabf8e8c52
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_DB: ${DB_DATABASE_NAME}
      POSTGRES_INITDB_ARGS: '--data-checksums'
    volumes:
      # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
      - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
    healthcheck:
      test: >-
        pg_isready --dbname="$${POSTGRES_DB}" --username="$${POSTGRES_USER}" || exit 1;
        Chksum="$$(psql --dbname="$${POSTGRES_DB}" --username="$${POSTGRES_USER}" --tuples-only --no-align
        --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')";
        echo "checksum failure count is $$Chksum";
        [ "$$Chksum" = '0' ] || exit 1        
      interval: 5m
      #start_interval: 30s
      start_period: 5m
    command: >-
      postgres
      -c shared_preload_libraries=vectors.so
      -c 'search_path="$$user", public, vectors'
      -c logging_collector=on
      -c max_wal_size=2GB
      -c shared_buffers=512MB
      -c wal_compression=on      
    restart: always

将镜像拉回来,然后启动,观察日志没问题就可以稳定运行了。

docker-compose pull
docker-compose up

3.导入图片 #

我之前使用的是 DS Photos, 记录一下导入的方法,使用的是immich-cli

$ sudo docker run -it -v "/volume1/Photos":/import:ro -e IMMICH_INSTANCE_URL=http://192.168.123.16:2283/api -e IMMICH_API_KEY=YOUR_API_KEY ghcr.io/immich-app/immich-cli:latest upload --recursive /import/ --ignore **/\@eaDir/**
Crawling for assets...
Hashing files           | ████████████████████████████████████████ | 100% | ETA: 0s | 16441/16441 assets
Checking for duplicates | ████████████████████████████████████████ | 100% | ETA: 0s | 16441/16441 assets
Found 15669 new files and 772 duplicates
Uploading assets | ██░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ | 4% | ETA: 5h25m | 774 MB/17.9 GB

东西很简单,需要修改的有:

  1. IMMICH_API_KEY, 在后台建立一个直接复制进去就行了;
  2. IMMICH_INSTANCE_URL, 自己的访问地址复制进去;
  3. -v "/volume1/Photos":/import:ro` 这个是挂载需要上传的照片目录;
  4. --ignore **/\@eaDir/** 的目的是屏蔽 DS Photos 生成的预览图。

4. 配置机器学习 #

虽然前文配置好了 DSM 的代理,但是对于 Docker 内部的容器并不会起作用。我采用的方法是直接手动下载放在对应的位置,经测试也没有问题。

模型一共有 2 个需要下载,XLM-Roberta-Large-Vit-B-16Plus 是用来以文搜图、智能搜图的。buffalo_l 是用来人脸识别的。

我展示一下目录结构,以便于手动放置。

$ ls
compose.yaml  library  model-cache  postgres
$ tree model-cache/ -L 3
model-cache/
├── clip
│   └── XLM-Roberta-Large-Vit-B-16Plus
│       ├── config.json
│       ├── textual
│       └── visual
└── facial-recognition
    └── buffalo_l
        ├── detection
        └── recognition

9 directories, 1 file

参考资料:

  1. https://github.com/immich-app/immich
  2. https://immich.app/docs/features/libraries
  3. https://immich.app/docs/install/docker-compose
  4. https://immich.app/docs/features/command-line-interface/