自建云相册PhotoPrism

John
2021-10-11 / 0 评论 / 59 阅读 / 正在检测是否收录...

在Github上看到了PhotoPrism这个项目,使用Golang开发,TensorFlow进行照片分类,支持WebDAV协议,并且已经有10多k的star了。
kumsqdog.png

Photoprism的搭建

我选择用Docker-Compose的方案,官方有具体的教程 https://docs.photoprism.org/getting-started/docker-compose/ 这里简单陈述下步骤:

  • 下载配置文件
# 路径仅供参考
mkdir /home/ubuntu/photoprism
cd /home/ubuntu/photoprism
wget https://dl.photoprism.org/docker/docker-compose.yml
vi /home/ubuntu/photoprism/docker-compose.yml
  • 修改配置内容
version: '3.5'
services:
  photoprism:
    # 使用预览版本:
    image: photoprism/photoprism:preview
    # 开机自启动
    restart: unless-stopped
    security_opt:
      - seccomp:unconfined
      - apparmor:unconfined
    ports:
      - 2342:2342
    environment:
      #设置登录密码
      PHOTOPRISM_ADMIN_PASSWORD: "xxxxxx"            # PLEASE CHANGE: Your initial admin password (min 4 characters)
      PHOTOPRISM_HTTP_PORT: 2342                     # Built-in Web server port
      PHOTOPRISM_HTTP_COMPRESSION: "gzip"            # Improves transfer speed and bandwidth utilization (none or gzip)
      PHOTOPRISM_DEBUG: "false"                      # Run in debug mode (shows additional log messages)
      PHOTOPRISM_PUBLIC: "false"                     # No authentication required (disables password protection)
      PHOTOPRISM_READONLY: "false"                   # Don't modify originals directory (reduced functionality)
      PHOTOPRISM_EXPERIMENTAL: "false"               # Enables experimental features
      PHOTOPRISM_DISABLE_WEBDAV: "false"             # Disables built-in WebDAV server
      PHOTOPRISM_DISABLE_SETTINGS: "false"           # Disables Settings in Web UI
      PHOTOPRISM_DISABLE_TENSORFLOW: "false"         # Disables using TensorFlow for image classification
      PHOTOPRISM_DARKTABLE_PRESETS: "false"          # Enables Darktable presets and disables concurrent RAW conversion
      PHOTOPRISM_DETECT_NSFW: "false"                # Flag photos as private that MAY be offensive (requires TensorFlow)
      PHOTOPRISM_UPLOAD_NSFW: "true"                 # Allow uploads that MAY be offensive
      # PHOTOPRISM_DATABASE_DRIVER: "sqlite"         # SQLite is an embedded database that doesn't require a server
      PHOTOPRISM_DATABASE_DRIVER: "mysql"            # Use MariaDB (or MySQL) instead of SQLite for improved performance
      PHOTOPRISM_DATABASE_SERVER: "mariadb:3306"     # MariaDB database server (hostname:port)
      PHOTOPRISM_DATABASE_NAME: "photoprism"         # MariaDB database schema name
      PHOTOPRISM_DATABASE_USER: "photoprism"         # MariaDB database user name
      PHOTOPRISM_DATABASE_PASSWORD: "insecure"       # MariaDB database user password
      PHOTOPRISM_SITE_URL: "http://localhost:2342/"  # Public PhotoPrism URL
      PHOTOPRISM_SITE_TITLE: "PhotoPrism"
      PHOTOPRISM_SITE_CAPTION: "Browse Your Life"
      PHOTOPRISM_SITE_DESCRIPTION: ""
      PHOTOPRISM_SITE_AUTHOR: ""
    volumes:
      # 映射原始文件存储目录为挂载的对象存储的Bucket
      - "/mnt/photoprism/pictures:/photoprism/originals"
      # 缓存、索引文件,可映射到对象存储Bucket
      - "/mnt/photoprism/storage:/photoprism/storage"

  mariadb:
    image: mariadb:10.5
    restart: unless-stopped
    security_opt:
      - seccomp:unconfined
      - apparmor:unconfined
    command: mysqld --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=50
    volumes: 
      # 数据库文件存储在宿主机/home/ubuntu/photoprism/database下
      - "./database:/var/lib/mysql"
    environment:
      MYSQL_ROOT_PASSWORD: please_change
      MYSQL_DATABASE: photoprism
      MYSQL_USER: photoprism
      MYSQL_PASSWORD: insecure

  # 开启自动更新
  watchtower:
    image: containrrr/watchtower
    restart: unless-stopped
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
  • 运行docker-compose
docker-compose -f /home/ubuntu/photoprism/docker-compose.yml up -d
server{
        listen 443 ssl;
        server_name xxxx;  #自定义域名
        ssl_certificate /etc/nginx/cert/xxxx.pem; #SSL证书 pem
        ssl_certificate_key /etc/nginx/cert/xxxx.key; #SSL证书 key
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        client_max_body_size 0;
        location / {
                proxy_pass http://127.0.0.1:2342;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $host;
                proxy_buffering off;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }
}
server{
        listen 80;
        server_name xxxx;   #自定义域名
        rewrite ^/(.*)$ https://xxxxx/$1 permanent;  #自定义域名
}
  • Web访问

使用反向代理的域名登录PhotoPrism后,就可以创建相册, 然后上传照片了。第一次使用,上传完成后,可以手动做一次索引,以后使用每15分钟会自动索引。关于索引更多的内容可以看官方文档 https://docs.photoprism.org/user-guide/library/indexing/

PhotoPrism支持分辨率的自适应,也就是说不论在PC、平板还是手机,都可以访问使用。同时可以看到PhotoPrism丰富的菜单栏和照片分类方式,包括基于时间线的日历、基于AI的Tag分类、基于地理位置的分类。虽然目前还没有基于人脸识别的分类,但在RoadMap上已经安排上了,相信很快就会发布。
kumsyepf.png

  • 创建定时任务

手动拷贝文件PhotoPrism不会自动索引,那我们这里就可以创建一个定时任务

crontab -e
# 设置每天晚上1点自动导入
0 1 * * * /usr/bin/docker exec photoprism_photoprism_1 /photoprism/bin/photoprism import
0

评论

博主关闭了当前页面的评论