标签: 照片管理

  • Debian12安装 Immich 进行自托管照片和视频

    Immich 是一个强大的自托管照片和视频管理解决方案,允许用户在自己的服务器上存储、管理和浏览照片,同时提供智能搜索、面部识别等 AI 功能,保护您的隐私。

    1. 介绍 Immich

    Immich 的主要功能

    • 自动备份:支持手机和桌面端自动同步照片和视频。
    • 智能搜索:基于 AI 的搜索和标签功能,快速查找照片。
    • 面部识别:自动识别照片中的人物并进行分类。
    • 隐私保护:完全自托管,确保数据不会泄露到第三方服务器。
    • 高效存储:支持增量备份和重复数据删除,优化存储空间。
    • 跨平台支持:支持 Android、iOS、Web 和桌面端访问。

    2. 安装 Docker 和 Docker Compose

    在 Linux 服务器上运行以下命令安装 Docker:

    curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh

    安装完成后,检查 Docker 版本:

    docker --version

    安装 Docker Compose:

    apt install -y docker-compose

    3. 下载 Immich 并配置环境变量

    3.1 创建 Immich 安装目录

    mkdir ./immich-app && cd ./immich-app

    3.2 下载官方 Docker Compose 文件

    #  docker-compose.yml
    wget -O docker-compose.yml https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
    
    # .env
    wget -O .env https://github.com/immich-app/immich/releases/latest/download/example.env

    docker-compose.yml文件

    #
    # 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}
        # 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
    
    volumes:
      model-cache:

    .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=Etc/UTC
    
    # The Immich version to use. You can pin this to a specific version like "v1.71.0"
    IMMICH_VERSION=release
    
    # 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=postgres
    
    # The values below this line do not need to be changed
    ###################################################################################
    DB_USERNAME=postgres
    DB_DATABASE_NAME=immich

    3.3 配置环境变量

    编辑 .env 文件:

    nano .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=Etc/UTC
    
    # The Immich version to use. You can pin this to a specific version like "v1.71.0"
    IMMICH_VERSION=release
    
    # 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=postgres
    
    # The values below this line do not need to be changed
    ###################################################################################
    DB_USERNAME=postgres
    DB_DATABASE_NAME=immich
    • 指定备份存储位置:
      • 请在UPLOAD_LOCATION中填写您希望存储备份文件的绝对路径。建议选择服务器上具有足够可用空间的新建目录,以确保备份顺利进行。
    • 设置数据库密码:
      • 强烈建议您修改DB_PASSWORD,为其设置一个自定义的强密码。由于PostgreSQL服务仅在本地Docker容器内运行,此密码用于本地身份验证。为避免Docker在解析密码时出现问题,请仅使用A-Za-z0-9范围内的字符。您可以使用pwgen等工具生成安全的随机密码。

    4. 启动 Immich

    运行 Docker Compose 启动 Immich

    docker-compose.yml 所在目录运行:

    docker compose up -d

    5. 访问 Immich Web 界面

    在浏览器中输入:

    http://<服务器IP>:2283

    首次访问时,需要注册一个管理员账户,登录后即可开始使用。