收起左侧

飞牛NAS自部署Affine实现笔记同步

3
回复
624
查看
[ 复制链接 ]

0

主题

6

回帖

0

牛值

江湖小虾

2025-10-13 21:36:51 显示全部楼层 阅读模式

前言

飞牛应用市场自带的 affine安装了几次总是启动失败,而且版本也不是最新的,因此参照affine官方的文档,自己在Docker部署了affine,目前工作良好,同步功能也全部正常。这里把折腾的过程写下来,供大家参考。

具体部署过程

第一步部(step 1)

  • 在Docker文件夹下新建affine文件夹,并建立config、postgres、postgresql、storage四个 子文件夹 ,如图所示。
  • image1.png

第二步 (step 2)

  • 新建一个.env环境变量文件,具体内容如下,并上传至affine文件下。
#The folder for Postgres data, usually to be the one in step 1 with '/postgres' suffix
DB_DATA_LOCATION=./postgres
#The folder for uploaded blobs, usually to be the one in step 1 with '/storage' suffix
UPLOAD_LOCATION=./storage
#The folder for custom configurations, usually to be the one in step with '/config' suffix
CONFIG_LOCATION=./config

#DATABASE credentials and names to initialize Postgres
#数据库用户名,请自己填写,替换username
DB_USERNAME=username
#数据库密码,自己填写替换password
DB_PASSWORD=password
DB_DATABASE=affine

第三步(step 3)

  1. 打开Docker,compose,新增项目,起个项目名称,这里就用affine,目录就选刚刚建立的affine目录,创建docker-compose.yml,具体内容如下
name: affine
services:
  affine:
    image: ghcr.io/toeverything/affine:${AFFINE_REVISION:-stable}
    container_name: affine_server
    # 冒号前的端口替换为你要用的端口
    ports:
      - '3010:3010'
    depends_on:
      redis:
        condition: service_healthy
      postgres:
        condition: service_healthy
      affine_migration:
        condition: service_completed_successfully
    volumes:
      # 冒号前的地址替换为你第一步建立的文件夹的地址
      - /vol1/1000/Docker/affine/storage:/root/.affine/storage
      - /vol1/1000/Docker/affine/config:/root/.affine/config
    env_file:
      - .env
    environment:
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
      - AFFINE_INDEXER_ENABLED=false
    restart: unless-stopped

  affine_migration:
    image: ghcr.io/toeverything/affine:${AFFINE_REVISION:-stable}
    container_name: affine_migration_defualt
    volumes:
      # 冒号前的地址替换为你第一步建立的文件夹的地址
      - /vol1/1000/Docker/affine/storage:/root/.affine/storage
      - /vol1/1000/Docker/affine/config:/root/.affine/config
    command: ['sh', '-c', 'node ./scripts/self-host-predeploy.js']
    env_file:
      - .env
    environment:
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
      - AFFINE_INDEXER_ENABLED=false
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

  redis:
    image: redis
    container_name: affine_redis
    healthcheck:
      test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  postgres:
    image: pgvector/pgvector:pg16
    container_name: affine_postgres
    volumes:
    # 冒号前的地址替换为你第一步建立的文件夹的地址
      - /vol1/1000/Docker/affine/postgres:/var/lib/postgresql/data  
    environment:
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      POSTGRES_DB: ${DB_DATABASE:-affine}
      POSTGRES_INITDB_ARGS: '--data-checksums'
      # you better set a password for you database
      # or you may add 'POSTGRES_HOST_AUTH_METHOD=trust' to ignore postgres security policy
      POSTGRES_HOST_AUTH_METHOD: trust
    healthcheck:
      test:
        ['CMD', 'pg_isready', '-U', "${DB_USERNAME}", '-d', "${DB_DATABASE:-affine}"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped
  1. 完成后点击构建,构建完成后启动,共有四个容器,其中第二个会在运行完成后自动关闭,不会影响使用。

    image2.png

    1. 输入IP+端口号登陆网页,第一次会进入管理面板,在这里创建一个账号就可以使用了,可以创建多个账号多人使用,还有多人协作功能,还没怎么研究。

      QQ20251013-213321.png

    2. 创建账号后再次登录,就可以使用网页版本笔记了。

      QQ20251013-213601.png

Affine客户端的使用

  • 使用官方客户端,选择连接到自托管实例,即可多端同步,功能和网页版相同。目前官方支持windows,linux和Android客户端(目前安卓客户端需依赖谷歌框架)。内网直接IP+端口号,需要远程访问的,有公网+DDNS或者内网穿透均可,这里不详述。

    QQ20251013-212535.png

收藏
送赞 1
分享

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

0

主题

1

回帖

0

牛值

江湖小虾

运行下面的语句会报错:

 affine_migration:
    image: ghcr.io/toeverything/affine:${AFFINE_REVISION:-stable}
    container_name: affine_migration_**

解决:Docker 容器的名字只能包含字母、数字、下划线 (_)、点 (.) 和减号 (-)。
你这里的名字 affine_migration_** 里有两个星号 **,它们是不被允许。

把名字改了,我改成了 affine_migration_defualt运行成功

感谢作者大佬,还请官方快点适配。之前看确实说会统一更新,等到现在也没有

谢谢纠正,我原本的位置是“**”,复制上传后变成了**,  详情 回复
昨天 20:35

6

主题

15

回帖

0

牛值

fnOS系统内测组

按照楼主的步骤部署成功了,感谢!

0

主题

6

回帖

0

牛值

江湖小虾

昨天 20:35 楼主 显示全部楼层
wzt 发表于 2025-10-22 12:02
运行下面的语句会报错:
affine_migration:
    image: ghcr.io/toeverything/affine{AFFINE_REVISION:-st ...

谢谢纠正,我原本的位置是“j/o/b(去掉杠,工作)”,复制上传后变成了**,
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则