# 一站式开源知识库 AFFiNE 自托管教程

**URL:** <https://meta.appinn.net/t/topic/54500>\
**Category:** 青蛙的应用\
**Tags:** 教程, affine\
**Created:** [2024 年3 月 29 日 06:58 UTC](https://meta.appinn.net/t/topic/54500 "2024-03-29T06:58:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

作者： ![Qingwa](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/qingwa/32/58632_2.png) [@Qingwa](https://meta.appinn.net/u/Qingwa)\
发布日期： [2024 年3 月 29 日 06:58 UTC](https://meta.appinn.net/t/topic/54500/1 "2024-03-29T06:58:02Z")

</div>

昨天有大佬发过来一个教程链接，是他自己部署 AFFiNE 的笔记，虽然放在了 Notion :joy:

我就整理（Copy）一下发在这里了：

## Docker - AFFiNE 部署步骤

### 1. 准备安装

```bash
# create folders
mkdir -p ~/docker/affine/data/{postgres,config,storage,redis}
cd ~/docker/affine/

# create docker network (optional), network "proxy" is used in docker-compose.yml

docker network create --subnet="172.19.0.0/16" --gateway="172.19.0.1" proxy

```

### 2. 修改预设环境 .env (Environment)

```bash
nano .env

```

> :light_bulb: 确保设置了以下参数  
> 要生成随机字符串，请使用此命令 `openssl rand -base64 32

```bash
# 按需修改

AFFINE_ADMIN_EMAIL=aaa@bbb.com
AFFINE_ADMIN_PASSWORD=A_very_strong_paSsw0rd
AFFINE_SERVER_HOST=affine.mydomain.com

```

### 3. 准备文件 docker-compose.yml

```bash
nano docker-compose.yml

```

### 以下是使用 traefik 反向代理的示例

如果你使用 Nginx，去掉这部分即可。

```yaml
services:
  affine:
    image: ghcr.io/toeverything/affine-graphql:stable
    container_name: affine
    env_file:
      - .env
    command:
      ['sh', '-c', 'node ./scripts/self-host-predeploy && node ./dist/index.js']
    ports:
      - '3010:3010'
      - '5555:5555'
    depends_on:
      redis:
        condition: service_healthy
      postgres:
        condition: service_healthy
    volumes:
      # custom configurations
      - ~/docker/affine/data/config:/root/.affine/config
      # blob storage
      - ~/docker/affine/data/storage:/root/.affine/storage
    logging:
      driver: 'json-file'
      options:
        max-size: '1000m'
    restart: unless-stopped
    environment:
      - NODE_OPTIONS="--import=./scripts/register.js"
      - AFFINE_CONFIG_PATH=/root/.affine/config
      - REDIS_SERVER_HOST=redis
      - DATABASE_URL=postgres://affine:affine@postgres:5432/affine
      - NODE_ENV=production
      - AFFINE_ADMIN_EMAIL=${AFFINE_ADMIN_EMAIL}
      - AFFINE_ADMIN_PASSWORD=${AFFINE_ADMIN_PASSWORD}
      - AFFINE_SERVER_HOST=${AFFINE_SERVER_HOST}
    labels:
          - "traefik.enable=true"
          - "traefik.http.routers.affine.entrypoints=http"
          - "traefik.http.routers.affine.rule=Host(`affine.mydomain.com`)"
          - "traefik.http.middlewares.affine-https-redirect.redirectscheme.scheme=https"
          - "traefik.http.routers.affine.middlewares=affine-https-redirect"
          - "traefik.http.routers.affine-secure.entrypoints=https"
          - "traefik.http.routers.affine-secure.rule=Host(`affine.mydomain.com`)"
          - "traefik.http.routers.affine-secure.tls=true"
          - "traefik.http.routers.affine-secure.service=affine"
          - "traefik.http.services.affine.loadbalancer.server.port=3010"
          - "traefik.docker.network=proxy"
    networks:
      - proxy

  redis:
    image: redis
    container_name: affine_redis
    restart: unless-stopped
    volumes:
      - ~/docker/affine/data/redis:/data
    healthcheck:
      test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - proxy

  postgres:
    image: postgres
    container_name: affine_postgres
    restart: unless-stopped
    volumes:
      - ~/docker/affine/data/postgres:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U affine']
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_USER: affine
      POSTGRES_PASSWORD: affine
      POSTGRES_DB: affine
      PGDATA: /var/lib/postgresql/data/pgdata
    networks:
      - proxy

networks:
  proxy:
    external: true

```

### 4. 开启 docker 容器

```bash
docker compose up -d

```

### 5. 访问站点并设置

使用 `.env` 文件中的用户名、密码登录

> :light_bulb: 暂不支持使用 AFFiNE 客户端连接到自托管 AFFiNE（开发中）。可以使用网页版。

## 附录： 官方网站和参考资料

[https://docs.affine.pro/docs/self-host-affine](https://docs.affine.pro/docs/self-host-affine)

[https://docs.affine.pro/docs/self-host-affine/run-affine-with-custom-options](https://docs.affine.pro/docs/self-host-affine/run-affine-with-custom-options)

---

<div class="post-metadata">

作者： ![Kaiyuan](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/kaiyuan/32/18103_2.png) [@Kaiyuan](https://meta.appinn.net/u/Kaiyuan)\
发布日期： [2024 年3 月 29 日 12:12 UTC](https://meta.appinn.net/t/topic/54500/2 "2024-03-29T12:12:29Z")

</div>

不同设备就算登录了，保存数据是不同的…

---

<div class="post-metadata">

作者： ![Qingwa](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/qingwa/32/58632_2.png) [@Qingwa](https://meta.appinn.net/u/Qingwa)\
发布日期： [2024 年3 月 29 日 12:13 UTC](https://meta.appinn.net/t/topic/54500/3 "2024-03-29T12:13:58Z")

</div>

我有点没看懂你说的是什么意思

---

<div class="post-metadata">

作者： ![Kaiyuan](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/kaiyuan/32/18103_2.png) [@Kaiyuan](https://meta.appinn.net/u/Kaiyuan)\
发布日期： [2024 年3 月 29 日 12:26 UTC](https://meta.appinn.net/t/topic/54500/4 "2024-03-29T12:26:06Z")

</div>

就是，电脑 EDGE 打开网页，登录账户后，编辑新建页面，保存。但是在手机或者其他浏览器登录同一样账户看到的内容都是分别独立的…不是同一个工作空间。

---

<div class="post-metadata">

作者： ![Qingwa](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/qingwa/32/58632_2.png) [@Qingwa](https://meta.appinn.net/u/Qingwa)\
发布日期： [2024 年3 月 29 日 12:27 UTC](https://meta.appinn.net/t/topic/54500/5 "2024-03-29T12:27:43Z")

</div>

开云同步了？

需要单独开的。

---

<div class="post-metadata">

作者： ![Kaiyuan](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/kaiyuan/32/18103_2.png) [@Kaiyuan](https://meta.appinn.net/u/Kaiyuan)\
发布日期： [2024 年3 月 29 日 12:28 UTC](https://meta.appinn.net/t/topic/54500/6 "2024-03-29T12:28:03Z")

</div>

没有开云同步

---

<div class="post-metadata">

作者： ![NINEIX](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/n/3da27b/32.png) [@NINEIX](https://meta.appinn.net/u/NINEIX)\
发布日期： [2024 年4 月 8 日 13:35 UTC](https://meta.appinn.net/t/topic/54500/7 "2024-04-08T13:35:36Z")

</div>

大佬你好，我搭建好了自托管服务后，发现自己的 cloud 空间只有 10G，能否修改配置文件改变这一点呢？可能官方直接移植的是商用版本，但是自建服务也限制空间实在没必要？

---

<div class="post-metadata">

作者： ![Qingwa](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/qingwa/32/58632_2.png) [@Qingwa](https://meta.appinn.net/u/Qingwa)\
发布日期： [2024 年4 月 8 日 13:59 UTC](https://meta.appinn.net/t/topic/54500/8 "2024-04-08T13:59:39Z")

</div>

我觉得，用它不如直接用 notion

---

<div class="post-metadata">

作者： ![NINEIX](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/n/3da27b/32.png) [@NINEIX](https://meta.appinn.net/u/NINEIX)\
发布日期： [2024 年4 月 8 日 14:51 UTC](https://meta.appinn.net/t/topic/54500/9 "2024-04-08T14:51:28Z")

</div>

不过看中了它可以白板和文档相结合，可以一边写实验日志，另一边绘制技术路线 :face_with_peeking_eye:

---

<div class="post-metadata">

作者： ![Qingwa](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/qingwa/32/58632_2.png) [@Qingwa](https://meta.appinn.net/u/Qingwa)\
发布日期： [2024 年4 月 8 日 14:52 UTC](https://meta.appinn.net/t/topic/54500/10 "2024-04-08T14:52:54Z")

</div>

你翻翻文档看看如果解除限制？又或者就是强制限制:joy:

---

<div class="post-metadata">

作者： ![Niceb](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/niceb/32/4721_2.png) [@Niceb](https://meta.appinn.net/u/Niceb)\
发布日期： [2024 年4 月 9 日 06:30 UTC](https://meta.appinn.net/t/topic/54500/11 "2024-04-09T06:30:51Z")

</div>

有无demo啊， 正在找可以自己部署的网页笔记

已经决定是思源笔记了

---

<div class="post-metadata">

作者： ![antior](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@antior](https://meta.appinn.net/u/antior)\
发布日期： [2024 年4 月 26 日 05:24 UTC](https://meta.appinn.net/t/topic/54500/12 "2024-04-26T05:24:31Z")

</div>

搭建好了但是总感觉不安全所以不敢用。  
不知道有没有研究outline的搭建手册呀？感觉outline应该是不错的选择，但是太难搭建了。  
目前在用开心版的confluence，感觉还是大厂的笔记做得好呀。之前用的思源还交了点钱用了快一年但是总是会同步有点小问题，以及使用过程中总是有种违和感，向开发者提出了需求但是他们局的不是问题，就用不下去了。
