1801 字
6 分钟
Azure VM 部署 Memos
2026-07-17

前言#

在 Azure 云服务器上部署 Memos v0.29.1 并搭配 Mortis 实现 Moe Memos 兼容 API.

本文将记录在一台 Azure 虚拟机 Standard B2ats v2(2 vCPU / 1 GiB RAM, Ubuntu 22.04)上从头部署 Memos + Mortis + Nginx 的完整流程.


重要提醒: Memos 的破坏性更新#

Memos 是一个活跃开发中的项目, 版本迭代频繁且经常引入不兼容变更.以下是一些近期的破坏性更新实例:

版本破坏性变更
v0.30.0-rc.1未设置 --instance-url 的实例默认变为私有模式; 过滤器语法从 now() 改为 CEL 时间戳; MCP 端点重构
v0.28.0SSO 身份关联机制重做: 已有 SSO 用户需重新绑定身份, 否则无法登录
v0.27.0用户资源名从数字 ID 改为用户名; IdP 资源改用稳定 UID; 新安装默认存储改为本地文件系统; 移除 disallow_public_visibility 和公开 Activity API
v0.22.0 前后API 格式变更, 导致 Moe Memos 等第三方客户端失效; 这正是引入 Mortis 的原因

建议:

  1. 固定版本: 生产环境建议锁定一个经过验证的稳定版本(如本文使用的 v0.29.1), 不要盲目追新.
  2. 升级前备份: 每次升级前务必备份 memos_prod.dbassets/ 目录.
  3. 关注 Changelog: 升级前仔细阅读 Releases 页面 中的 Breaking Changes 部分.
  4. Mortis 兼容性: Mortis 的版本号通常与 Memos 对应; 如果你升级 Memos, 确保 Mortis 也有对应版本.

只要不频繁升级, 锁定稳定版本, Memos 跑起来后非常省心. 本文的所有配置均基于 v0.29.1, 经实际生产验证可用.


背景#

Memos 是一款轻量级, 自托管的备忘录(微博客)服务, 采用 Go 语言编写, SQLite 作为数据库, 资源占用极低. 它提供简洁的 Web 界面, 同时兼容 Moe Memos(第三方 Android/iOS 客户端)的 API.

问题在于: Memos 从某个版本起更改了 API 格式, 导致旧版 Moe Memos 客户端无法正常使用. 为此, 社区开发了 Mortis: 一个 API 兼容层, 将新版 Memos API 转译为 Moe Memos 所需的 v0.21.0 格式.


环境概览#

项目配置
云平台Microsoft Azure
操作系统Ubuntu 22.04.5 LTS (x86-64)
内核6.8.0-1062-azure
内存~894 MiB
磁盘62 GB
域名memo.example.com
用户memos

架构总览#

flowchart TD A[Internet] --> B[Nginx :443<br/>SSL 终端 / memo.example.com] B -->|"/api/v1/ , /o/r/"| C[Mortis :5231<br/>API 兼容层] B -->|"/ (Web UI)"| D[Memos :8081<br/>核心服务] C -->|"gRPC/HTTP"| D D --> E[(SQLite<br/>/var/opt/memos)]
  • Memos 默认监听 0.0.0.0:8081, 处理 Web 界面和内部 gRPC/HTTP API;
  • Mortis 默认监听 0.0.0.0:5231, 从 Memos 获取数据并转换为旧版 Moe Memos 兼容 API;
  • Nginx 作为反向代理和 SSL 终端, 根据路径将请求分发到不同后端(外部访问受 NSG 限制, 仅开放 80/443 可达).

第一步: 安装 Memos#

1.1 使用官方脚本安装#

Memos 提供了便捷的一键安装脚本:

bash
curl -fsSL https://raw.githubusercontent.com/usememos/memos/main/scripts/install.sh | bash

安装完成后, 二进制文件位于 /usr/local/bin/memos.

验证安装:

0.29.1
bash
/usr/local/bin/memos version

1.2 创建数据目录#

bash
sudo mkdir -p /var/opt/memos
sudo chown memos:memos /var/opt/memos

1.3 配置 systemd 服务#

创建 /etc/systemd/system/memos.service:

ini
[Unit]
Description=Memos - A lightweight, self-hosted memo hub
After=network.target
[Service]
Type=simple
User=memos
ExecStart=/usr/local/bin/memos --data /var/opt/memos
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

说明: Memos 默认监听 0.0.0.0:8081(所有网络接口). 由于 Azure VM 的 NSG 只放行了 80/443 端口, 外部无法直接访问 8081, 因此无需额外绑定.

启动服务:

bash
sudo systemctl daemon-reload
sudo systemctl enable memos
sudo systemctl start memos

验证服务运行状态:

bash
sudo systemctl status memos
curl -s -o /dev/null -w "%{http_code}" http://localhost:8081/
# 返回 200 表示正常

第二步: 安装与配置 Nginx#

2.1 安装 Nginx#

bash
sudo apt install -y nginx

2.2 创建初始配置(HTTP)#

先在 /etc/nginx/sites-available/memos.conf 编写一个基础的反代配置, 确保 HTTP 能通:

nginx
server {
listen 80;
server_name memo.example.com;
client_max_body_size 100m;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket 支持
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

启用站点并重载:

bash
sudo ln -sf /etc/nginx/sites-available/memos.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

此时在浏览器访问 http://memo.example.com 即可看到 Memos 的初始化界面. 完成首次登录设置后, Memos 即可正常使用.


第三步: 配置 SSL 证书#

3.1 准备证书文件#

将 SSL 证书和私钥上传到服务器:

bash
sudo mkdir -p /etc/nginx/ssl
# 假设证书文件已上传到用户主目录
sudo mv ~/memo.example.com.pem /etc/nginx/ssl/
sudo mv ~/memo.example.com.key /etc/nginx/ssl/
sudo chmod 600 /etc/nginx/ssl/memo.example.com.key
sudo chmod 644 /etc/nginx/ssl/memo.example.com.pem

3.2 更新 Nginx 启用 HTTPS#

将配置文件更新为 HTTPS + HTTP 自动跳转:

nginx
server {
listen 80;
server_name memo.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name memo.example.com;
ssl_certificate /etc/nginx/ssl/memo.example.com.pem;
ssl_certificate_key /etc/nginx/ssl/memo.example.com.key;
client_max_body_size 100m;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

重载 Nginx:

bash
sudo nginx -t && sudo systemctl reload nginx

第四步: 安装 Mortis(Moe Memos 兼容层)#

4.1 什么是 Mortis#

Mortis 是社区维护的 Memos API 兼容层, 它的作用是将 Memos 新版 API 转译为 Moe Memos(第三方客户端)所需的老版本 (v0.21.0) 格式.

这意味着你可以用 最新版 Memos 服务端, 同时继续使用 Moe Memos 移动客户端(它只支持旧 API), 两全其美.

4.2 下载二进制#

从 GitHub Releases 获取对应架构的预编译二进制:

bash
# 下载 mortis(版本号通常与 Memos 版本对应,此处为 v0.29.1)
wget -q https://github.com/mudkipme/mortis/releases/download/0.29.1/mortis-amd64.tar.gz \
-O /tmp/mortis.tar.gz
# 解压并安装
tar -xzf /tmp/mortis.tar.gz -C /tmp/
sudo mv /tmp/mortis-amd64 /usr/local/bin/mortis
sudo chmod +x /usr/local/bin/mortis
rm -f /tmp/mortis.tar.gz

如果直接下载的是二进制文件(如 mortis-amd64), 则无需解压, 直接 chmod +x 后移到 /usr/local/bin/ 即可.

4.3 配置 systemd 服务#

创建 /etc/systemd/system/mortis.service:

ini
[Unit]
Description=Mortis - Memos 0.21.0 API compatibility layer
After=memos.service
Requires=memos.service
[Service]
Type=simple
User=memos
ExecStart=/usr/local/bin/mortis -grpc-addr=127.0.0.1:8081 -port=5231
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target

参数说明:

参数含义
-grpc-addr127.0.0.1:8081Memos 后端地址
-port5231Mortis 监听端口

Mortis 默认监听 0.0.0.0:5231, 同样由 NSG 限制外部访问. -grpc-addr 指向 Memos 的 HTTP 地址即可(Memos 在 8081 端口同时提供 HTTP/gRPC).

启动服务:

bash
sudo systemctl daemon-reload
sudo systemctl enable --now mortis
sudo systemctl status mortis

验证 API 是否正常:

bash
curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:5231/api/v1/memo?openId=test
# 返回 200 表示 Mortis 正常工作

第五步: Nginx 分流配置(最终版)#

现在有了两个后端服务, 需要 Nginx 根据请求路径进行分发:

  • /api/v1//o/r/Mortis (端口 5231), 供 Moe Memos 客户端调用;
  • 其他所有请求 → Memos (端口 8081), 提供 Web 界面.
nginx
server {
listen 80;
server_name memo.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name memo.example.com;
ssl_certificate /etc/nginx/ssl/memo.example.com.pem;
ssl_certificate_key /etc/nginx/ssl/memo.example.com.key;
client_max_body_size 100m;
# Mortis - Moe Memos 兼容 API (v0.21.0)
location /api/v1/ {
proxy_pass http://127.0.0.1:5231;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /o/r/ {
proxy_pass http://127.0.0.1:5231;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Memos Web 界面
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

应用配置:

bash
sudo nginx -t && sudo systemctl reload nginx

验证与收尾#

检查所有服务#

bash
# 检查端口监听
ss -tlnp | grep -E '80|443|8081|5231'
# 检查 systemd 服务状态
sudo systemctl is-active memos nginx mortis
# 应该全部输出 active

功能验证#

测试项方法
Web 界面浏览器打开 https://memo.example.com
Moe Memos APIcurl https://memo.example.com/api/v1/memo?openId=你的openId
资源重定向curl -I https://memo.example.com/o/r/12345

资源占用#

部署完成后, 本机同时运行了四个常驻服务, 各进程的实际内存占用(RSS):

服务内存 (RSS)说明
Memos~64 MiBGo 编译的二进制, 含 SQLite 和内置 Web 前端
Mortis~24 MiBAPI 兼容层, 轻量级
Nginx~28 MiBmaster + 2 workers
MTProto (MTG)~29 MiBTelegram 代理(与本教程无关, 同机部署)
以上合计~145 MiB
系统开销~156 MiBsnapd, WALinuxAgent, systemd 等
总计~301 MiB / 894 MiB

磁盘总占用约 2.1 GB, CPU 负载 0.06. 一台 Standard B2ats v2(2 vCPU / 1 GiB RAM) 即可稳定运行.


踩坑记录#

  1. Mortis 的 release 文件名不统一: GitHub Release 中有时是 mortis-amd64.tar.gz, 里面直接就是 mortis-amd64 二进制(无 .tar.gz 内的目录结构), 需要手动解压到 /tmp 再移动到 /usr/local/bin/.

  2. Memos 用 SQLite 时数据库文件名: 初次安装后数据库文件可能是 memos.db, 完成首次登录设置后 Memos 会创建 memos_prod.db 作为正式生产库.

  3. Mortis 依赖 Memos 先启动: systemd 配置中用 Requires=memos.serviceAfter=memos.service 确保启动顺序正确.

  4. Memos 使用子命令查看版本: Memos 不支持 memos --version,需使用子命令 memos version 查看版本号.


总结#

通过 Memos + Mortis + Nginx 这一套组合, 我们在 Standard B2ats v2(2 vCPU / 1 GiB RAM) 上实现了一个完整的自托管备忘录系统:

  • Memos v0.29.1 作为核心服务, 提供 Web 界面和数据存储;
  • Mortis 作为 API 兼容层, 让 Moe Memos 移动客户端能继续使用;
  • Nginx 统一入口, 负责 SSL 终端和请求路由.

整个部署过程只需不到一小时, 日常维护成本几乎为零. 如果你也想拥有一个属于自己的轻量级备忘录服务, 不妨试一试这套方案.


部署日期: 2026年7月16日 服务器: Azure VM / Ubuntu 22.04 / 2 vCPU / 1 GiB RAM

分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Azure VM 部署 Memos
https://blog.cyanyuzu.work/posts/mm-dp/
作者
はなあさぎ / CyanYuzu
发布于
2026-07-17
许可协议
CC BY-NC-SA 4.0

评论

加载中…

部分信息可能已经过时

目录