Liunx 安装

2025-09-25
-
-
这本质上是 Trilium 源 + 节点模块 + 打包成一个 7z 文件的node.js运行时。
 

一、安装步骤

1.  通过 SSH 连接到您的服务器

2. 使用 (或 ) 在您的服务器上下载最新(从发布页面复制链接,注意后缀)。wgetcurlTriliumNotes-Server-[VERSION]-linux-x64.tar.xz-Server

3. 解压缩存档,例如tar -xf -d TriliumNotes-Server-[VERSION]-linux-x64.tar.xz

4. cd trilium-linux-x64-server

5. ./trilium.sh

6. 您可以打开浏览器并打开 http://[your-server-hostname]:8080,您应该会看到 Trilium 初始化页面

上述步骤的问题在于,一旦关闭 SSH 连接,Trilium 进程就会终止。为避免这种情况,您有两种选择:

1.  杀死它(例如使用 + ) 并像这样再次运行: 。(nohup 使进程在后台运行,在后台运行)CtrlCnohup ./trilium.sh &&

2. 配置 systemd 以在每次启动时自动在后台运行 Trilium

二、将 Trilium 配置为在启动时使用 systemd 自动运行

下载后,解压并移动 Trilium:

tar -xvf TriliumNotes-Server-[VERSION]-linux-x64.tar.xz
sudo mv trilium-linux-x64-server /opt/trilium

创建服务:

sudo nano /etc/systemd/system/trilium.service

将其粘贴到文件中(根据需要替换用户和组):

[Unit]
Description=Trilium Daemon
After=syslog.target network.target

[Service]
User=xxx
Group=xxx
Type=simple
ExecStart=/opt/trilium/trilium.sh
WorkingDirectory=/opt/trilium/

TimeoutStopSec=20
# KillMode=process leads to error, according to https://www.freedesktop.org/software/systemd/man/systemd.kill.html
Restart=always

[Install]
WantedBy=multi-user.target

保存文件 (CTRL-S) 并退出 (CTRL-X)
启用并启动服务:

sudo systemctl enable --now -q trilium

 

您现在可以打开浏览器 http://[your-server-hostname]:8080,您应该会看到 Trilium 初始化页面。

2.1 服务器的简单自动更新

以 Trilium 运行的同一用户身份运行

如果您以 root 身份运行,请从命令中删除“sudo”

需要“jq”apt install jq

它将停止上面的服务,覆盖所有内容(我预计不会config.ini),然后启动服务它还在 Trilium 目录中创建一个版本文件,因此它仅更新为较新的版本

#!/bin/bash

# Configuration
REPO="TriliumNext/Trilium"
PATTERN="TriliumNotes-Server-.*-linux-x64.tar.xz"
DOWNLOAD_DIR="/var/tmp/trilium_download"
OUTPUT_DIR="/opt/trilium"
SERVICE_NAME="trilium"
VERSION_FILE="$OUTPUT_DIR/version.txt"

# Ensure dependencies are installed
command -v curl >/dev/null 2>&1 || { echo "Error: curl is required"; exit 1; }
command -v jq >/dev/null 2>&1 || { echo "Error: jq is required"; exit 1; }
command -v tar >/dev/null 2>&1 || { echo "Error: tar is required"; exit 1; }

# Create download directory
mkdir -p "$DOWNLOAD_DIR" || { echo "Error: Cannot create $DOWNLOAD_DIR"; exit 1; }

# Get the latest release version
LATEST_VERSION=$(curl -sL https://api.github.com/repos/$REPO/releases/latest | jq -r '.tag_name')
if [ -z "$LATEST_VERSION" ]; then
  echo "Error: Could not fetch latest release version"
  exit 1
fi

# Check current installed version (from version.txt or existing tarball)
CURRENT_VERSION=""
if [ -f "$VERSION_FILE" ]; then
  CURRENT_VERSION=$(cat "$VERSION_FILE")
elif [ -f "$DOWNLOAD_DIR/TriliumNotes-Server-$LATEST_VERSION-linux-x64.tar.xz" ]; then
  CURRENT_VERSION="$LATEST_VERSION"
fi

# Compare versions
if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
  echo "Latest version ($LATEST_VERSION) is already installed"
  exit 0
fi

# Download the latest release
LATEST_URL=$(curl -sL https://api.github.com/repos/$REPO/releases/latest | jq -r ".assets[] | select(.name | test(\"$PATTERN\")) | .browser_download_url")
if [ -z "$LATEST_URL" ]; then
  echo "Error: No asset found matching pattern '$PATTERN'"
  exit 1
fi

FILE_NAME=$(basename "$LATEST_URL")
FILE_PATH="$DOWNLOAD_DIR/$FILE_NAME"

# Download if not already present
if [ -f "$FILE_PATH" ]; then
  echo "Latest release $FILE_NAME already downloaded"
else
  curl -LO --output-dir "$DOWNLOAD_DIR" "$LATEST_URL" || { echo "Error: Download failed"; exit 1; }
  echo "Downloaded $FILE_NAME to $DOWNLOAD_DIR"
fi

# Extract the tarball
EXTRACT_DIR="$DOWNLOAD_DIR/extracted"
mkdir -p "$EXTRACT_DIR"
tar -xJf "$FILE_PATH" -C "$EXTRACT_DIR" || { echo "Error: Extraction failed"; exit 1; }

# Find the extracted directory (e.g., TriliumNotes-Server-0.97.2-linux-x64)
INNER_DIR=$(find "$EXTRACT_DIR" -maxdepth 1 -type d -name "TriliumNotes-Server-*-linux-x64" | head -n 1)
if [ -z "$INNER_DIR" ]; then
  echo "Error: Could not find extracted directory matching TriliumNotes-Server-*-linux-x64"
  exit 1
fi

# Stop the trilium-server service
if systemctl is-active --quiet "$SERVICE_NAME"; then
  echo "Stopping $SERVICE_NAME service..."
  sudo systemctl stop "$SERVICE_NAME" || { echo "Error: Failed to stop $SERVICE_NAME"; exit 1; }
fi

# Copy contents to /opt/trilium, overwriting existing files
echo "Copying contents from $INNER_DIR to $OUTPUT_DIR..."
sudo mkdir -p "$OUTPUT_DIR"
sudo cp -r "$INNER_DIR"/* "$OUTPUT_DIR"/ || { echo "Error: Copy failed"; exit 1; }
echo "$LATEST_VERSION" | sudo tee "$VERSION_FILE" >/dev/null
echo "Files copied to $OUTPUT_DIR"

# Start the trilium-server service
echo "Starting $SERVICE_NAME service..."
sudo systemctl start "$SERVICE_NAME" || { echo "Error: Failed to start $SERVICE_NAME"; exit 1; }

# Clean up
rm -rf "$EXTRACT_DIR"
echo "Cleanup complete. Trilium updated to $LATEST_VERSION."

三、常见问题

3.1 过时的 glibc

Error: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /var/www/virtual/.../node_modules/@mlink/scrypt/build/Release/scrypt.node)
    at Object.Module._extensions..node (module.js:681:18)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)

如果您收到这样的错误,您需要升级您的 glibc(通常通过升级到最新的发行版版本)或使用其他一些服务器安装方法。

四、TLS的

不要忘记配置安全使用所需的 TLS!

“您的支持是我持续分享的动力”

微信收款码
微信
支付宝收款码
支付宝

目录关闭