分享一下我觉得好用的自建服务们(续)

前言

之前写过一篇博客 介绍了一些我平时在用的自建服务。最近几天,把部分服务迁移到了一台闲置服务器上, 提升了之前部分服务的体验,又搭建了一些新的服务。

记录一下这次的成果,作为上次的后续。

HTTPS

这次还是把所有服务用 docker-compose 管理,一个最主要的区别是这次加上了域名和 HTTPS, 方式是所有服务暴露 HTTP 端口到 localhost,前面加一个 nginx 手动配置反向代理,每个服务一个子域名。

域名解析到私网 IP 地址,用 DNS challenge 的方式申请证书。 目前是手动申请,将来也可以参考 vaultwarden 的文档 自动申请。

上次服务的改进

Seafile 与 OnlyOffice 的集成

version: '2.0'
services:
  db:
    image: mariadb:10.5
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=secret   # Requested, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
    volumes:
      - ./db:/var/lib/mysql  # Requested, specifies the path to MySQL data persistent store.
    restart: always
    networks:
      - seafile-net

  memcached:
    image: memcached:1.5.6
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    restart: always
    networks:
      - seafile-net

  seafile:
    image: seafileltd/seafile-mc:latest
    container_name: seafile
    ports:
      - "127.0.0.1:9000:80"
#     - "443:443"  # If https is enabled, cancel the comment.
    volumes:
      - ./data:/shared   # Requested, specifies the path to Seafile data persistent store.
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=secret  # Requested, the value shuold be root's password of MySQL service.
      - TIME_ZONE=Asia/Shanghai  # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=secret # Specifies Seafile admin user, default is '[email protected]'.
      - SEAFILE_ADMIN_PASSWORD=secret # Specifies Seafile admin password, default is 'asecret'.
      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether to use https or not.
      - SEAFILE_SERVER_HOSTNAME=seafile.example.com # Specifies your host name if https is enabled.
    depends_on:
      - db
      - memcached
      - oods
    restart: always
    networks:
      - seafile-net

  oods:
    image: onlyoffice/documentserver:latest
    container_name: seafile-oods
    volumes:
      - ./DocumentServer/logs:/var/log/onlyoffice
      - ./DocumentServer/data:/var/www/onlyoffice/Data
      - ./DocumentServer/lib:/var/lib/onlyoffice
      - ./DocumentServer/local-production-linux.json:/etc/onlyoffice/documentserver/local-production-linux.json
      - ./DocumentServer/fonts:/usr/share/fonts/truetype
    networks:
      - seafile-net
    environment:
      - JWT_ENABLED=true
      - JWT_SECRET=secret

networks:
  seafile-net:

集成方式是首先像上面那样加一个 oods 的容器,然后按照官方文档 说的 修改一些配置文件。

主要问题在于中文字体。我的方式是把需要的字体放进一个目录,映射进容器完全替换掉自带的字体。 之后刷新浏览器缓存。看到网上很多人做法是粗暴地把字体 docker cp 进去,使得迁移和升级变麻烦, 感觉他们对 docker 不是很熟悉。

虽然还是有些兼容性问题,不过修改和查看一些简单文档还是没问题的,更多用法有待后续检验。

新搭建的自建服务

GitLab

上来就是重量级。GitLab 用的人很多,功能超复杂,文档也很齐全。

主要遇到的问题是配置里面的 external_url 在保持 HTTPS 的同时禁掉容器里面的 HTTPS 。 既不能直接写 http (会遇到很多怪问题),也不能直接写 https (容器会直接不绑定 http 端口), 而是要通过配置修改里面的 nginx 的行为。

GITLAB_OMNIBUS_CONFIG: |
    ...blabla
    external_url 'https://gitlab.example.com'
    nginx['listen_port'] = 80
    nginx['listen_https'] = false

VaultWarden

也是很常用的密码管理工具了。之前也想搭,这次搞了 HTTPS 终于给用上了, 同步完之后赶紧把浏览器的密码全删了。

官方文档给了一堆例子, 可能遇到的问题就是容器别忘了映射 websocket 端口。

虽然用的 Bitwarden 客户端是 Electron 写的,看在好看好用的份上就忍了。

Send

Firefox Send 被废弃了,于是搭建了一个比较流行的 Fork https://github.com/timvisee/send。 遇到的问题也是官方给的 docker-compose.yml 自带了 nginx 和 HTTPS

下面这是我修改的版本,只保留了本体和 redis

version: "3"

services:
  send:
    image: '${DOCKER_SEND_IMAGE}'
    restart: always
    ports:
      - '127.0.0.1:1443:1443'
    volumes:
      - ./uploads:/uploads
    environment:
      - VIRTUAL_HOST=${HOST}
      - VIRTUAL_PORT=1234
      - DHPARAM_GENERATION=false
      - NODE_ENV=production
      - BASE_URL=${SEND_BASE_URL}
      - REDIS_HOST=redis

  redis:
    image: 'redis:alpine'
    restart: always
    volumes:
      - ./send-redis:/data

然后关键的是外面的 nginx 配置一定不要忘了 websocket

location / {
    ...blablabla

    # set headers to support websocket
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
}

Homer

一个自建服务的导航主页。有很多流行的同类项目是 PHP 写的,还有账号和后台,感觉太怪了, 这不应该就是个静态页面吗?

这个项目比较符合我的想法,只要写写配置文件就可以了,尽管功能会少一些。

一个经验是可以搭配 homer-icons 这个项目来用,提升体验。

备份(TODO)

一个重大的尚未解决的问题。解决方案比较多,不知道应该用哪个。

在整这次的服务器时,我给数据盘格成了 btrfs, 然后每个服务的目录都是一个 subvolume, 为做快照做了准备,但我发现我根本不懂 btrfs, 所以就留在以后解决吧。

还好这些服务多数都是本地也需要一份文件在才能用,所以服务器硬盘坏了的损失应该不算严重。

总结

  1. 最大的感受是虽然有了 docker ,但由于各种应用的水平参差不齐,标准不一,搭建服务依然是一个很折腾的问题。
  2. 这次的方案肯定不是最佳实践,还有很多可以继续折腾的地方。
  3. P.S. 这篇博客全部是用我之前写的 rime-ls 输入的,感觉用着已经比较稳定了。