---
document_type: "implementation_guide"
service: "MOMENTRY_CORE"
title: "Momentry 系統全新 Mac 安裝指南"
date: "2026-03-23"
version: "V1.0"
status: "active"
owner: "Warren"
created_by: "OpenCode"
tags:
  - "momentry"
  - "系統全新"
  - "安裝指南"
ai_query_hints:
  - "查詢 Momentry 系統全新 Mac 安裝指南 的內容"
  - "Momentry 系統全新 Mac 安裝指南 的主要目的是什麼？"
  - "如何操作或實施 Momentry 系統全新 Mac 安裝指南？"
---

# Momentry 系統全新 Mac 安裝指南

| 項目 | 內容 |
|------|------|
| 建立時間 | 2026-03-23 |
| 文件版本 | V1.0 |
| 適用對象 | 全新 Mac (Intel 或 Apple Silicon) |

---

## 版本歷史

| 版本 | 日期 | 目的 | 操作人 |
|------|------|------|--------|
| V1.0 | 2026-03-23 | 創建文件 | OpenCode |

---

## 快速概覽

### 安裝時間估算

| 項目 | 時間 |
|------|------|
| 系統準備 | 30 分鐘 |
| Homebrew 安裝 | 15 分鐘 |
| 資料庫服務 | 30 分鐘 |
| 應用服務 | 60 分鐘 |
| Momentry Core | 20 分鐘 |
| **總計** | **~2.5 小時** |

### 系統需求

| 項目 | 最低需求 | 推薦需求 |
|------|----------|----------|
| macOS | 13.0 Ventura | 14.0+ Sonoma |
| 記憶體 | 8GB | 16GB+ |
| 儲存空間 | 100GB | 500GB+ |
| CPU | Apple Silicon M1 或 Intel i5 | M2/M3 或 Intel i7+ |

---

## 第一部分：系統準備

### 1.1 macOS 初始設定

首次開機後，執行以下設定：

```bash
# 1. 設定電腦名稱
sudo scutil --set ComputerName "Momentry"
sudo scutil --set LocalHostName "momentry"

# 2. 啟用 SSH 遠端登入
sudo systemsetup -setremotelogin on

# 3. 關閉休眠 (防止遠端斷線)
sudo pmset -a sleep 0
sudo pmset -a hibernatemode 0

# 4. 允許任何來源 App (安裝開發工具用)
sudo spctl --master-disable

# 5. 設定時區
sudo systemsetup -settimezone "Asia/Taipei"
```

### 1.2 建立管理員帳戶

```bash
# 建立 Momentry 管理員帳戶 (可選)
sudo dscl . -create /Users/momentry
sudo dscl . -create /Users/momentry UserShell /bin/zsh
sudo dscl . -create /Users/momentry RealName "Momentry Admin"
sudo dscl . -create /Users/momentry PrimaryGroupID 80
sudo dscl . -create /Users/momentry UniqueID 1001
sudo dscl . -passwd /Users/momentry "momentry_password"
sudo dscl . -append /Groups/admin GroupMembership momentry
```

---

## 第二部分：Homebrew 安裝

### 2.1 安裝 Homebrew

```bash
# 安裝 Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Apple Silicon 設定
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

# Intel Mac 設定
# echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
# eval "$(/usr/local/bin/brew shellenv)"

# 驗證
brew --version
```

### 2.2 安裝基礎工具

```bash
# 開發工具
brew install \
  git \
  curl \
  wget \
  jq \
  yq \
  tree \
  htop \
  tmux \
  zsh \
  zsh-completions \
  ncdu \
  httpie \
  openssl \
  readline \
  sqlite \
  python@3.11 \
  rustup-init

# Rust 初始化
rustup-init -y
source "$HOME/.cargo/env"

# Python 虛擬環境
python3.11 -m venv ~/.venv
source ~/.venv/bin/activate
pip install --upgrade pip
```

---

## 第三部分：建立目錄結構

```bash
# 建立目錄結構
mkdir -p /Users/accusys/momentry/{var,etc,log,scripts,backup}
mkdir -p /Users/accusys/momentry/var/{postgresql,mongodb,mariadb,redis,qdrant,n8n,ollama,sftpgo}
mkdir -p /Users/accusys/momentry/etc/{sftpgo,caddy,gitea,php}
mkdir -p /Users/accusys/momentry/scripts
mkdir -p /Users/accusys/momentry/backup/{daily,weekly,monthly}
mkdir -p /Users/accusys/workspace/sftpgo
mkdir -p /Users/accusys/sftpgo_test/{demo,uploads}

# 設定權限
chown -R accusys:staff /Users/accusys/momentry
chown -R accusys:staff /Users/accusys/workspace
chown -R accusys:staff /Users/accusys/sftpgo_test
```

---

## 第四部分：資料庫服務安裝

### 4.1 PostgreSQL

```bash
# 安裝
brew install postgresql@18

# 啟動服務
brew services start postgresql@18

# 建立資料庫
createdb momentry
createdb video_register
createdb n8n
createdb sftpgo

# 建立用戶
psql -U accusys -d postgres << 'EOF'
CREATE USER sftpgo WITH PASSWORD 'sftpgo_pass_2026';
GRANT ALL PRIVILEGES ON DATABASE sftpgo TO sftpgo;
GRANT ALL PRIVILEGES ON DATABASE momentry TO accusys;
GRANT ALL PRIVILEGES ON DATABASE video_register TO accusys;
GRANT ALL PRIVILEGES ON DATABASE n8n TO accusys;
EOF

# 驗證
pg_isready -h 127.0.0.1 -p 5432
```

### 4.2 MongoDB

```bash
# 安裝
brew tap mongodb/brew
brew install mongodb-community

# 建立資料目錄
mkdir -p /Users/accusys/momentry/var/mongodb
chown -R accusys:staff /Users/accusys/momentry/var/mongodb

# 啟動服務
brew services start mongodb-community

# 建立用戶
mongosh admin --eval "
db.createUser({
  user: 'accusys',
  pwd: 'Test3200Test3200',
  roles: [
    { role: 'readWriteAnyDatabase', db: 'admin' },
    { role: 'dbAdminAnyDatabase', db: 'admin' }
  ]
});
"

# 驗證
mongosh --quiet --eval "db.adminCommand('ping')"
```

### 4.3 Redis

```bash
# 安裝
brew install redis

# 建立配置目錄
mkdir -p /Users/accusys/momentry/etc/redis

# 建立配置文件
cat > /Users/accusys/momentry/etc/redis/redis.conf << 'EOF'
requirepass accusys
dir /Users/accusys/momentry/var/redis
logfile /Users/accusys/momentry/log/redis.log
daemonize no
port 6379
bind 127.0.0.1
EOF

# 啟動服務
redis-server /Users/accusys/momentry/etc/redis/redis.conf &
sleep 2

# 驗證
redis-cli -a accusys ping
```

### 4.4 MariaDB (WordPress)

```bash
# 安裝
brew install mariadb

# 啟動服務
brew services start mariadb

# 安全設定
mysql_secure_installation

# 建立資料庫
mysql -u root << 'EOF'
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;
EOF

# 驗證
mysql -u root -e "SHOW DATABASES;"
```

---

## 第五部分：應用服務安裝

### 5.1 Ollama (LLM)

```bash
# 安裝
brew install ollama

# 建立資料目錄
mkdir -p /Users/accusys/momentry/var/ollama
mkdir -p ~/.ollama/models

# 啟動服務
brew services start ollama

# 下載模型
ollama pull llama3.2
ollama pull nomic-embed-text

# 驗證
curl -s http://localhost:11434/api/tags | jq '.models[].name'
```

### 5.2 Caddy (反向代理)

```bash
# 安裝
brew install caddy

# 建立配置目錄
mkdir -p /Users/accusys/momentry/etc/caddy

# 建立 Caddyfile
cat > /Users/accusys/momentry/etc/caddy/Caddyfile << 'EOF'
{
  admin off
  auto_https off
}

# 範例：本地開發
:8080 {
  respond "Momentry Server" 200
}
EOF

# 啟動服務
brew services start caddy

# 驗證
curl -s http://localhost:8080
```

### 5.3 Gitea (Git 服務)

```bash
# 安裝
brew install gitea

# 建立資料目錄
mkdir -p /Users/accusys/momentry/var/gitea
mkdir -p /Users/accusys/momentry/etc/gitea

# 複製設定檔
cp /opt/homebrew/etc/gitea/conf/app.ini /Users/accusys/momentry/etc/gitea/

# 啟動服務
brew services start gitea

# 驗證
curl -s http://localhost:3000
```

### 5.4 n8n (工作流程自動化)

```bash
# 安裝 Node.js (如果尚未安裝)
brew install node@22

# 全域安裝 n8n
npm install -g n8n

# 建立資料目錄
mkdir -p /Users/accusys/momentry/var/n8n

# 設定環境變數
export N8N_DATA_DIR=/Users/accusys/momentry/var/n8n
export DB_TYPE=postgresdb
export DB_POSTGRES_HOST=127.0.0.1
export DB_POSTGRES_PORT=5432
export DB_POSTGRES_DATABASE=n8n
export DB_POSTGRES_USER=accusys
export DB_POSTGRES_PASSWORD=accusys
export N8N_ENCRYPTION_KEY=Test3200Test3200Test3200

# 啟動服務
n8n start &

# 驗證
curl -s http://localhost:5678
```

### 5.5 SFTPGo (SFTP 服務)

```bash
# 安裝
brew install sftpgo

# 建立配置目錄
mkdir -p /Users/accusys/momentry/etc/sftpgo

# 建立配置文件
cat > /Users/accusys/momentry/etc/sftpgo/sftpgo.json << 'EOF'
{
  "data_provider": {
    "driver": "postgresql",
    "host": "127.0.0.1",
    "port": 5432,
    "username": "sftpgo",
    "password": "sftpgo_pass_2026",
    "name": "sftpgo",
    "create_default_admin": true
  },
  "httpd": {
    "bind_port": 8080,
    "bind_address": "127.0.0.1"
  },
  "sftpd": {
    "bindings": [
      {"port": 2022}
    ]
  },
  "ftpd": {
    "bindings": [
      {"port": 0}
    ]
  }
}
EOF

# 建立 launchd plist
cat > /Library/LaunchDaemons/com.momentry.sftpgo.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.momentry.sftpgo</string>
    <key>UserName</key>
    <string>accusys</string>
    <key>WorkingDirectory</key>
    <string>/Users/accusys/workspace/sftpgo</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/homebrew/bin/sftpgo</string>
        <string>serve</string>
        <string>--config-file</string>
        <string>/Users/accusys/momentry/etc/sftpgo/sftpgo.json</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin</string>
        <key>HOME</key>
        <string>/Users/accusys</string>
        <key>SFTPGO_DEFAULT_ADMIN_USERNAME</key>
        <string>admin</string>
        <key>SFTPGO_DEFAULT_ADMIN_PASSWORD</key>
        <string>Test3200Test3200</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Users/accusys/momentry/log/sftpgo.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/accusys/momentry/log/sftpgo.error.log</string>
</dict>
</plist>
EOF

# 載入服務
sudo launchctl load /Library/LaunchDaemons/com.momentry.sftpgo.plist

# 驗證
sleep 3
curl -s -X POST http://localhost:8080/api/v2/token -u "admin:Test3200Test3200"
```

### 5.6 Qdrant (向量資料庫)

```bash
# 安裝 Rust (如果尚未安裝)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

# 安裝 Qdrant
cargo install qdrant

# 建立資料目錄
mkdir -p /Users/accusys/momentry/var/qdrant/storage

# 啟動服務
qdrant --data-path /Users/accusys/momentry/var/qdrant/storage --api-key Test3200Test3200Test3200 &

# 驗證
sleep 3
curl -s http://localhost:6333/collections -H "api-key: Test3200Test3200Test3200"
```

---

## 第六部分：Momentry Core 安裝

### 6.1 安裝依賴

```bash
# 安裝 Python 依賴
pip install \
  openai-whisper \
  ultralytics \
  opencv-python \
  pillow \
  python-dotenv \
  requests \
  httpx

# 安裝 FFmpeg
brew install ffmpeg
```

### 6.2 安裝 Momentry Core

```bash
# 克隆或進入專案目錄
cd /Users/accusys/momentry_core_0.1

# 編譯專案
cargo build --release

# 複製執行檔
cp target/release/momentry /usr/local/bin/

# 建立 launchd plist
cat > /Library/LaunchDaemons/com.momentry.api.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.momentry.api</string>
    <key>UserName</key>
    <string>accusys</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/momentry</string>
        <string>server</string>
        <string>--host</string>
        <string>0.0.0.0</string>
        <string>--port</string>
        <string>3002</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
        <key>DATABASE_URL</key>
        <string>postgres://accusys:accusys@127.0.0.1:5432/momentry</string>
        <key>RUST_LOG</key>
        <string>info</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/Users/accusys/momentry/log/momentry.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/accusys/momentry/log/momentry.error.log</string>
</dict>
</plist>
EOF

# 載入服務
sudo launchctl load /Library/LaunchDaemons/com.momentry.api.plist

# 驗證
sleep 3
curl -s http://localhost:3002/health
```

---

## 第七部分：服務驗證

### 7.1 健康檢查腳本

```bash
#!/bin/bash
# health_check.sh

echo "=========================================="
echo "Momentry System Health Check"
echo "=========================================="
echo ""

# PostgreSQL
pg_isready -h 127.0.0.1 -p 5432 > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ PostgreSQL" || echo "❌ PostgreSQL"

# MongoDB
mongosh --quiet --eval "db.adminCommand('ping')" > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ MongoDB" || echo "❌ MongoDB"

# Redis
redis-cli -a accusys ping > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ Redis" || echo "❌ Redis"

# Ollama
curl -s http://localhost:11434/api/tags > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ Ollama" || echo "❌ Ollama"

# n8n
curl -s http://localhost:5678 > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ n8n" || echo "❌ n8n"

# SFTPGo
curl -s http://localhost:8080 > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ SFTPGo" || echo "❌ SFTPGo"

# Qdrant
curl -s http://localhost:6333/ > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ Qdrant" || echo "❌ Qdrant"

# Momentry API
curl -s http://localhost:3002/health > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ Momentry API" || echo "❌ Momentry API"

# Caddy
curl -sI http://localhost:8080 > /dev/null 2>&1
[ $? -eq 0 ] && echo "✅ Caddy" || echo "❌ Caddy"

echo ""
echo "=========================================="
```

### 7.2 執行驗證

```bash
# 儲存並執行
chmod +x health_check.sh
./health_check.sh
```

---

## 第八部分：重要憑證總覽

### 8.1 服務密碼

| 服務 | 用戶名 | 密碼 | 用途 |
|------|--------|------|------|
| **PostgreSQL** | accusys | `accusys` | 主要資料庫 |
| **PostgreSQL** | sftpgo | `sftpgo_pass_2026` | SFTPGo 資料庫 |
| **MongoDB** | accusys | `Test3200Test3200` | 文件資料庫 |
| **Redis** | - | `accusys` | 快取服務 |
| **n8n** | - | `Test3200Test3200Test3200` | n8n 加密金鑰 |
| **SFTPGo** | admin | `Test3200Test3200` | SFTPGo 管理員 |
| **Qdrant** | - | `Test3200Test3200Test3200` | Qdrant API Key |
| **MariaDB** | root | (設定時指定) | WordPress 資料庫 |
| **MariaDB** | wordpress | `wordpress_password` | WordPress 資料庫用戶 |

### 8.2 服務連接埠

| 服務 | 連接埠 | 協定 |
|------|--------|------|
| PostgreSQL | 5432 | TCP |
| MongoDB | 27017 | TCP |
| Redis | 6379 | TCP |
| Ollama | 11434 | HTTP |
| n8n | 5678 | HTTP |
| SFTPGo | 8080 | HTTP |
| SFTPGo | 2022 | SFTP |
| Qdrant | 6333 | HTTP |
| Momentry API | 3002 | HTTP |
| Caddy | 80/443 | HTTP/HTTPS |
| Gitea | 3000 | HTTP |
| PHP-FPM | 9000 | TCP |

---

## 第九部分：相關文檔

| 文檔 | 說明 |
|------|------|
| `SERVICES.md` | 服務詳細說明 |
| `INSTALL_POSTGRESQL.md` | PostgreSQL 安裝指南 |
| `INSTALL_MONGODB.md` | MongoDB 安裝指南 |
| `INSTALL_REDIS.md` | Redis 安裝指南 |
| `INSTALL_QDRANT.md` | Qdrant 安裝指南 |
| `INSTALL_N8N.md` | n8n 安裝指南 |
| `INSTALL_SFTPGO.md` | SFTPGo 安裝指南 |
| `SFTPGO_DEMO_USER.md` | SFTPGo Demo 用戶指南 |
| `MOMENTRY_CORE_MONITORING.md` | 監控規範 |
| `API_INDEX.md` | API 文件索引 |

---

## 附錄：常見問題

### Q1: n8n 無法連接 PostgreSQL

確保資料庫用戶有登入權限：
```bash
psql -U accusys -d postgres -c "ALTER USER accusys WITH LOGIN;"
```

### Q2: SFTPGo 無法啟動

檢查 PostgreSQL 是否運行：
```bash
pg_isready -h 127.0.0.1 -p 5432
```

### Q3: Qdrant API Key 無效

使用正確的 API Key：
```bash
curl -H "api-key: Test3200Test3200Test3200" http://localhost:6333/collections
```

### Q4: Momentry API 無法啟動

檢查環境變數：
```bash
export DATABASE_URL="postgres://accusys:accusys@127.0.0.1:5432/momentry"
export RUST_LOG=debug
momentry server --host 0.0.0.0 --port 3002
```
