替代群晖相册 - PhotoPrism 部署教程

前几天分享了部署 immich 的部署教程,今天我们再来部署一个值得一试的 PhotoPrism。PhotoPrism 是一款比较成熟的自托管照片应用,网页端的体验非常舒服,替代 Google Photo 也没什么问题。

替代群晖相册 - PhotoPrism 部署教程

前几天分享了部署 immich 的部署教程,今天我们再来部署一个值得一试的 PhotoPrism。PhotoPrism 是一款比较成熟的自托管照片应用,网页端的体验非常舒服,替代 Google Photo 也没什么问题。唯一美中不足的是,官方没有比较好用的第三方客户端,只能用 PhotoSync 这款第三方付费 App 或者免费的 Syncthing 来解决。

使用 Docker Compose 部署 PhotoPrism

如果你直接从 Unraid 的应用中心部署 PhotoPrism,默认使用的是 sqlite 数据库,这种数据库仅适合进行测试用途,如果照片数量较多,运行起来就显得比较吃力。所以如果是用来备份照片,那还是使用官方推荐的 mariadb。

单独安装 PhotoPrism,还得安装一个 mariadb,填写数据库的时候比较容易出错,而 PhotoPrism 官方就提供了 Docker Compose 配置文件。只需要修改下相关的配置、存储路径和密码就可以,简单而且不容易出错。

如果你的 Unraid 没有安装 Docker Compose,可以先到应用里搜索安装。

我修改好的 Docker Compose 文件如下:

version: "3.5"

# Example Docker Compose config file for PhotoPrism (Linux / AMD64)
#
# Note:
# - Hardware transcoding is only available for sponsors due to the high maintenance and support effort.
# - Running PhotoPrism on a server with less than 4 GB of swap space or setting a memory/swap limit can cause unexpected
#   restarts ("crashes"), for example, when the indexer temporarily needs more memory to process large files.
# - If you install PhotoPrism on a public server outside your home network, please always run it behind a secure
#   HTTPS reverse proxy such as Traefik or Caddy. Your files and passwords will otherwise be transmitted
#   in clear text and can be intercepted by anyone, including your provider, hackers, and governments:
#   https://docs.photoprism.app/getting-started/proxies/traefik/
#
# Setup Guides:
# - https://docs.photoprism.app/getting-started/docker-compose/
# - https://docs.photoprism.app/getting-started/raspberry-pi/
#
# Troubleshooting Checklists:
# - https://docs.photoprism.app/getting-started/troubleshooting/
# - https://docs.photoprism.app/getting-started/troubleshooting/docker/
# - https://docs.photoprism.app/getting-started/troubleshooting/mariadb/
#
# CLI Commands:
# - https://docs.photoprism.app/getting-started/docker-compose/#command-line-interface
#
# All commands may have to be prefixed with "sudo" when not running as root.
# This will point the home directory shortcut ~ to /root in volume mounts.

services:
  photoprism:
    ## Use photoprism/photoprism:preview for testing preview builds:
    image: photoprism/photoprism:latest
    depends_on:
      - mariadb
    ## Don't enable automatic restarts until PhotoPrism has been properly configured and tested!
    ## If the service gets stuck in a restart loop, this points to a memory, filesystem, network, or database issue:
    ## https://docs.photoprism.app/getting-started/troubleshooting/#fatal-server-errors
    # restart: unless-stopped
    security_opt:
      - seccomp:unconfined
      - apparmor:unconfined
    ports:
      - "2342:2342" # HTTP port (host:container)
    environment:
      PHOTOPRISM_ADMIN_USER: "admin" # superadmin username
      PHOTOPRISM_ADMIN_PASSWORD: "wLr6sYA7megkKE8x2qD3" # initial superadmin password (minimum 8 characters)
      PHOTOPRISM_AUTH_MODE: "password" # authentication mode (public, password)
      PHOTOPRISM_SITE_URL: "http://192.168.2.8:2342/" # server URL in the format "http(s)://domain.name(:port)/(path)"
      PHOTOPRISM_ORIGINALS_LIMIT: 5000 # file size limit for originals in MB (increase for high-res video)
      PHOTOPRISM_HTTP_COMPRESSION: "gzip" # improves transfer speed and bandwidth utilization (none or gzip)
      PHOTOPRISM_LOG_LEVEL: "info" # log level: trace, debug, info, warning, error, fatal, or panic
      PHOTOPRISM_READONLY: "false" # do not modify originals directory (reduced functionality)
      PHOTOPRISM_EXPERIMENTAL: "false" # enables experimental features
      PHOTOPRISM_DISABLE_CHOWN: "false" # disables updating storage permissions via chmod and chown on startup
      PHOTOPRISM_DISABLE_WEBDAV: "false" # disables built-in WebDAV server
      PHOTOPRISM_DISABLE_SETTINGS: "false" # disables settings UI and API
      PHOTOPRISM_DISABLE_TENSORFLOW: "false" # disables all features depending on TensorFlow
      PHOTOPRISM_DISABLE_FACES: "false" # disables face detection and recognition (requires TensorFlow)
      PHOTOPRISM_DISABLE_CLASSIFICATION: "false" # disables image classification (requires TensorFlow)
      PHOTOPRISM_DISABLE_RAW: "false" # disables indexing and conversion of RAW files
      PHOTOPRISM_RAW_PRESETS: "false" # enables applying user presets when converting RAW files (reduces performance)
      PHOTOPRISM_JPEG_QUALITY: 85 # a higher value increases the quality and file size of JPEG images and thumbnails (25-100)
      PHOTOPRISM_DETECT_NSFW: "false" # automatically flags photos as private that MAY be offensive (requires TensorFlow)
      PHOTOPRISM_UPLOAD_NSFW: "true" # allows uploads that MAY be offensive (no effect without TensorFlow)
      # PHOTOPRISM_DATABASE_DRIVER: "sqlite"         # SQLite is an embedded database that doesn't require a server
      PHOTOPRISM_DATABASE_DRIVER: "mysql" # use MariaDB 10.5+ or MySQL 8+ instead of SQLite for improved performance
      PHOTOPRISM_DATABASE_SERVER: "mariadb:3306" # MariaDB or MySQL database server (hostname:port)
      PHOTOPRISM_DATABASE_NAME: "photoprism" # MariaDB or MySQL database schema name
      PHOTOPRISM_DATABASE_USER: "photoprism" # MariaDB or MySQL database user name
      PHOTOPRISM_DATABASE_PASSWORD: "MNaNYWrawnreEK827Ubo9dsX" # MariaDB or MySQL database user password
      PHOTOPRISM_SITE_CAPTION: "AI-Powered Photos App"
      PHOTOPRISM_SITE_DESCRIPTION: "" # meta site description
      PHOTOPRISM_SITE_AUTHOR: "" # meta site author
      ## Run/install on first startup (options: update https gpu tensorflow davfs clitools clean):
      # PHOTOPRISM_INIT: "https gpu tensorflow"
      ## Hardware Video Transcoding:
      # PHOTOPRISM_FFMPEG_ENCODER: "software"        # FFmpeg encoder ("software", "intel", "nvidia", "apple", "raspberry")
      # PHOTOPRISM_FFMPEG_BITRATE: "32"              # FFmpeg encoding bitrate limit in Mbit/s (default: 50)
      ## Run as a non-root user after initialization (supported: 0, 33, 50-99, 500-600, and 900-1200):
      PHOTOPRISM_UID: 1000
      PHOTOPRISM_GID: 1000
      PHOTOPRISM_UMASK: 0000
    ## Start as non-root user before initialization (supported: 0, 33, 50-99, 500-600, and 900-1200):
    user: "1000:1000"
    ## Share hardware devices with FFmpeg and TensorFlow (optional):
    devices:
      - "/dev/dri:/dev/dri" # Intel QSV
    #  - "/dev/nvidia0:/dev/nvidia0"                 # Nvidia CUDA
    #  - "/dev/nvidiactl:/dev/nvidiactl"
    #  - "/dev/nvidia-modeset:/dev/nvidia-modeset"
    #  - "/dev/nvidia-nvswitchctl:/dev/nvidia-nvswitchctl"
    #  - "/dev/nvidia-uvm:/dev/nvidia-uvm"
    #  - "/dev/nvidia-uvm-tools:/dev/nvidia-uvm-tools"
    #  - "/dev/video11:/dev/video11"                 # Video4Linux Video Encode Device (h264_v4l2m2m)
    working_dir: "/photoprism" # do not change or remove
    ## Storage Folders: "~" is a shortcut for your home directory, "." for the current directory
    volumes:
      # "/host/folder:/photoprism/folder"                # Example
      - "/mnt/user/photos:/photoprism/originals" # Original media files (DO NOT REMOVE)
      # - "/example/family:/photoprism/originals/family" # *Additional* media folders can be mounted like this
      # - "~/Import:/photoprism/import"                  # *Optional* base folder from which files can be imported to originals
      - "/mnt/user/appdata/photoprism/storage:/photoprism/storage" # *Writable* storage folder for cache, database, and sidecar files (DO NOT REMOVE)

  ## Database Server (recommended)
  ## see https://docs.photoprism.app/getting-started/faq/#should-i-use-sqlite-mariadb-or-mysql
  mariadb:
    ## If MariaDB gets stuck in a restart loop, this points to a memory or filesystem issue:
    ## https://docs.photoprism.app/getting-started/troubleshooting/#fatal-server-errors
    restart: unless-stopped
    image: mariadb:10.10
    security_opt: # see https://github.com/MariaDB/mariadb-docker/issues/434#issuecomment-1136151239
      - seccomp:unconfined
      - apparmor:unconfined
    command: mysqld --innodb-buffer-pool-size=512M --transaction-isolation=READ-COMMITTED --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max-connections=512 --innodb-rollback-on-timeout=OFF --innodb-lock-wait-timeout=120
    ## Never store database files on an unreliable device such as a USB flash drive, an SD card, or a shared network folder:
    volumes:
      - "/mnt/user/appdata/mariadb/database:/var/lib/mysql" # DO NOT REMOVE
    environment:
      MARIADB_AUTO_UPGRADE: "1"
      MARIADB_INITDB_SKIP_TZINFO: "1"
      MARIADB_DATABASE: "photoprism"
      MARIADB_USER: "photoprism"
      MARIADB_PASSWORD: "MNaNYWrawnreEK827Ubo9dsX"
      MARIADB_ROOT_PASSWORD: "MNaNYWrawnreEK827Ubo9dsX"

  ## Watchtower upgrades services automatically (optional)
  ## see https://docs.photoprism.app/getting-started/updates/#watchtower
  ## activate via "COMPOSE_PROFILES=update docker compose up -d"
  watchtower:
    restart: unless-stopped
    image: containrrr/watchtower
    profiles: ["update"]
    environment:
      WATCHTOWER_CLEANUP: "true"
      WATCHTOWER_POLL_INTERVAL: 7200 # checks for updates every two hours
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "~/.docker/config.json:/config.json" # optional, for authentication if you have a Docker Hub account

修改的配置如下:

  • PHOTOPRISM_ADMIN_PASSWORD: wLr6sYA7megkKE8x2qD3(PhotoPrism 登录密码,默认用户名为 admin)
  • PHOTOPRISM_SITE_URL: http://192.168.2.8:2342/(PhotoPrism 登录地址,请把这个 IP 改成你的 Unraid IP)
  • PHOTOPRISM_DATABASE_PASSWORD: MNaNYWrawnreEK827Ubo9dsX(PhotoPrism mariadb 数据库密码)
  • MARIADB_PASSWORD: MNaNYWrawnreEK827Ubo9dsX(也就是上面设置的 PHOTOPRISM_DATABASE_PASSWORD,保持一致即可)
  • MARIADB_ROOT_PASSWORD: MNaNYWrawnreEK827Ubo9dsX(如果不想改,也可以和上面的 PHOTOPRISM_DATABASE_PASSWORD 保持一致)

部署之前需要建立一个名为 photos 的共享文件夹。

接下来新建一个 Docker Compose 配置 ADD NEW STACK,填写名称(PhotoPrism)点击确定。点击新建的 PhotoPrism 上的设置(EDIT STACK)编辑 COMPOSE FILE,将上面的  Docker Compose File 直接粘贴到配置文件编辑器里,点击保存(SAVE CHANGES)。

最后点击 PhotoPrism 右侧的 COMPOSE UP 按钮就开始部署了,稍等片刻部署成功后,照片应用就可以打开了,默认端口是 2342。

登录后,PhotoPrism 默认语言是英语,可以在设置中修改为中文。

使用手机备份照片

使用手机备份照片到 PhotoPrism 有两种办法,一种是手机上安装 PhotoSync,这是一款付费的照片备份应用,iOS 和 Android 都有客户端,通过 PhotoPrism 支持的 WebDav 可以实现将手机上的照片备份到 NAS。支持自动备份,使用体验还凑合,缺点是不支持中文。第二种方法是使用免费的 Syncthing 来将手机相册同步到 NAS 的 photos 共享文件夹里,设置稍微麻烦一点,但也只需要设置一次即可。而且这款软件不仅仅可以用来备份照片,你也可以用来同步其他文件。

使用 PhotoSync 备份照片

安装 PhotoSync 购买之后,直接在应用中按提示进行设置,连接服务器类型选择 WebDAV,PhotoPrism 的 设置 -> 服务 里提供了 WebDAV 的连接 URL。

7DOitc_QwTnwy

将所需的连接信息填到 PhotoSync 的 WebDAV 配置里。

photosync_5AkuF1

使用 Syncthing 备份照片

syncthing 是一款开源免费跨平台的文件同步工具,在 Unraid 应用里就可以直接部署。

WbujQK_5J2OUb

只需要修改默认的 Path:/data1 为共享的照片目录 /mnt/user/photos/。如果你想把容器内的路径改成 /photos,那就需要把默认的 Path:/data1 移除,重新添加 Path。

部署好之后,就可以打开 8384 这个端口来访问 syncthing 了。在网页端的设置里可以为你的 syncthing 命名,比如我设置的 unraid。

XSde2b_1Ou5nl

手机端安装 syncthing 之后,先和 NAS 端互相添加设备 ID(手机端支持扫码添加)。再把手机端默认就有的 DCIM 文件夹(也就是我们要备份到 NAS 端的相册文件夹)共享给 NAS(如果已经互相添加了设备 ID,那在文件夹里面就可以直接把 NAS 设备的开关打开,比如我的 NAS 名称是 unraid)。

syncthing_bOAHua

最后在 NAS 端就可以看到手机端共享过来的照片文件夹了,如果在部署时没有修改 /data1 这个 Path,那就直接设置保存位置为 /data1 就可以了。手机端会自动把相册里的文件都同步到 NAS 上的 photos 共享文件夹里。

设置 PhotoPrism 索引

通过上面这两种方式可以把照片保存到 PhotoPrism 里,但是 PhotoPrism 需要经过索引才能把照片都显示出来。在 Unraid 上面可以用 User Script 这个插件来设置让 PhotoPrism 定期执行索引任务。

User Script 插件在应用里就可以点击安装。

装好后添加脚本(447d671ed813 为你的 PhotoPrism Docker 容器 ID,使用 docker ps 命令查看后替换成自己的):

/usr/bin/docker exec -i 447d671ed813 /opt/photoprism/bin/photoprism index
93b3hD_XCtGJq

可以直接设置为每小时来索引,这样每次打开基本都可以看到最新备份的照片了。

q64rv8_dR3GKq