yiye

一叶轻舟

记录人生旅途的轻声细语

Mix Space ブログ構築ガイド

入門編:Docker デプロイ#

推奨指数:★★★★★

難易度指数:★

Docker を使用してデプロイし、フロントエンドとバックエンドを分離せず、デプロイ要件は以下の通りです:

  • 1 台のサーバー、メモリ > 1G
  • 1 つのドメイン名(国内サーバーは登録が必要)

注意:バックエンドはデフォルトでテーマを持たず、サービスを実行した後、管理画面にログインする必要があります https://www.blog.com/proxy/qaqdmin云関数 を参照してテーマを設定してください。

設定ファイル#

ファイルディレクトリ構造は以下の通りで、.envdocker-compose.yml はユーザーが作成する必要があります。data ディレクトリはコンテナが実行された後に自動生成されます。

📂 ~/mix-space

├── 📜 .env
├── 📜 docker-compose.yml
└── 📂 data
    ├── 📂 mongo
    ├── 📂 redis
    └── 📂 core

.env#

注意:API 関連の設定は一般的に変更する必要はありません。

# 💻 フロントエンド設定
# 🌐 API 関連設定
NEXT_PUBLIC_API_URL=http://core:2333/api/v2
NEXT_PUBLIC_GATEWAY_URL=http://core:2333/

# 🔑 認証 & API キー
TMDB_API_KEY=
GH_TOKEN=

# 🖥️ バックエンド設定
# 🔐 セキュリティ設定
JWT_SECRET=G7xJpQzW8mV4L2YfK9N6T1RbX3dMC0H(32桁)
ALLOWED_ORIGINS=
ENCRYPT_KEY=593f62860255feb0a914534a43814b9809cc7534da7f5485cd2e3d3c8609acab(64桁)
ENCRYPT_ENABLE=false

# 🚀 キャッシュ関連設定
CDN_CACHE_HEADER=true
FORCE_CACHE_HEADER=false

# 🛢 データベース設定
MONGO_CONNECTION=

# ⚡ リクエスト制限(Throttle)
THROTTLE_TTL=10
THROTTLE_LIMIT=20

dockers-compose.yml#

services:
  shiro:
    container_name: shiro
    image: innei/shiro:latest
    volumes:
      - ./.env:/app/.env
    restart: always
    environment:
      - NEXT_SHARP_PATH=/usr/local/lib/node_modules/sharp
    ports:
      - "127.0.0.1:2323:2323"
    depends_on:
      - core
    networks:
      - mix-space

  core:
    container_name: core
    image: innei/mx-server:latest
    environment:
      - TZ=Asia/Shanghai
      - NODE_ENV=production
      - DB_HOST=mongo
      - REDIS_HOST=redis
    volumes:
      - ./data/core:/root/.mx-space
    ports:
      - "127.0.0.1:2333:2333"
    depends_on:
      - mongo
      - redis
    networks:
      - mix-space
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:2333/api/v2/ping"]
      interval: 1m30s
      timeout: 30s
      retries: 5
      start_period: 30s

  mongo:
    container_name: mongo
    image: mongo
    volumes:
      - ./data/mongo:/data/db
    networks:
      - mix-space
    restart: unless-stopped

  redis:
    image: redis:alpine
    container_name: redis
    volumes:
      - ./data/redis:/data
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
      start_period: 20s
      interval: 30s
      retries: 5
      timeout: 3s
    networks:
      - mix-space
    restart: unless-stopped

networks:
  mix-space:
    driver: bridge

nginx リバースプロキシ#

ドメイン名(例:www.blog.com)に A レコードを追加してサーバー IP を指し示し、次に以下の server ブロックを追加してください。

server {
    listen 80;
    listen 443 ssl http2 ; 
   
    server_name www.blog.com; 
    index index.html; 
    proxy_set_header Host $host; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-Forwarded-Host $server_name; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    error_log /www/sites/www.example.com/log/error.log;
    access_log /www/sites/www.example.com/log/access.log; 
    location /socket.io {
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "Upgrade"; 
        proxy_set_header Host $host; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-Forwarded-Proto $scheme; 
        proxy_pass http://127.0.0.1:2333/socket.io; 
    }
    location /api/v2 {
        proxy_pass http://127.0.0.1:2333/api/v2; 
    }
    location /render {
        proxy_pass http://127.0.0.1:2333/render; 
    }
    location / {
        proxy_pass http://127.0.0.1:2323; 
    }
    location /qaqdmin {
        proxy_pass http://127.0.0.1:2333/proxy/qaqdmin;
    }
    location /proxy {
        proxy_pass http://127.0.0.1:2333/proxy;
    }
 
    location ~* \/(feed|sitemap|atom.xml) {
        proxy_pass http://127.0.0.1:2333/$1; 
    }
    ssl_certificate /www/sites/www.example.com/ssl/fullchain.pem; 
    ssl_certificate_key /www/sites/www.example.com/ssl/privkey.pem; 
    ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1; 
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK'; 
    ssl_prefer_server_ciphers on; 
    ssl_session_cache shared:SSL:10m; 
    ssl_session_timeout 10m; 
    error_page 497 https://$host$request_uri; 
    limit_conn perserver 300; 
    limit_conn perip 25; 
    limit_rate 512k; 
}

上級編:従来の方法でのデプロイ#

推奨指数:★★★

難易度指数:★★★

構築デプロイ、フロントエンドとバックエンドを分離し、デプロイ要件は以下の通りです:

  • 簡単デプロイ / 自動デプロイ

    • 1 台のサーバー、メモリ > 1G

    • 2 つのドメイン名、サブドメインでも可

  • 手動デプロイ

    • 1 台のサーバー、メモリ > 2G
    • 2 つのドメイン名、サブドメインでも可

注意:バックエンドはデフォルトでテーマを持たず、サービスを実行した後、管理画面にログインする必要があります https://backend.blog.com/proxy/qaqdmin云関数 を参照してテーマを設定してください。

バックエンドの構築#

環境の準備#

  • nodejs をインストールします。バージョン 20.12.2 を推奨します。

    sudo apt-get install curl
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
    nvm install 20.12.2
    
  • redis をインストールします。

    sudo apt-get install redis-server
    
  • mongodb をインストールします。ここでは Ubuntu 24.04 を例にします。

    sudo apt-get install gnupg
    
    curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
       sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg \
       --dearmor
    echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
    
    sudo apt-get update
    sudo apt-get install -y mongodb-org
    sudo systemctl start mongod
    sudo systemctl enable mongod
    sudo systemctl status mongod
    

    その他のシステムインストールについては、MongoDB 公式ドキュメント を参照してください。

簡単デプロイ#

バックエンドリポジトリ:Mix Space/core

  • 直接ダウンロードした Linux 版を構築します。

    mkdir ~/mix-space/core && cd $_
    curl -L -O https://github.com/mx-space/core/releases/latest/download/release-linux.zip
    unzip release-linux.zip
    rm release-linux.zip
    
  • 32 桁と 64 桁の文字を生成します。

    openssl rand -base64 24 | cut -c1-32 # jwt_secret 用
    openssl rand -base64 48 | cut -c1-64 # encrypt key 用
    
  • ecosystem.config.js を編集します。

    const { cpus } = require('os');
    const { execSync } = require('child_process');
    const nodePath = execSync(`npm root --quiet -g`, { encoding: 'utf-8' }).trim();
    const cpuLen = cpus().length;
    
    module.exports = {
      apps: [
        {
          name: 'mix-space',
          script: 'index.js',
          autorestart: true,
          exec_mode: 'cluster',
          watch: false,
          instances: cpuLen,
          max_memory_restart: '500M',
          args: [
            '--color',
            '--encrypt_enable',
            '--encrypt_key ********************************(64桁)',
            '--port 2333',
            '--allowed_origins example1.com,example2.com,localhost',
            '--jwt_secret ********************(16~32桁)',
          ].join(' '),
          env: {
            NODE_ENV: 'production',
            NODE_PATH: nodePath,
          },
        },
      ],
    };
    
  • バックエンドサービスを起動します。

    npm install -g pm2
    pm2 start ecosystem.config.js
    

手動デプロイ#

  • バックエンドサービスをインストールします。

    mkdir ~/mix-space && cd $_
    git clone https://github.com/mx-space/core.git --depth=1
    cd core
    npm install -g pnpm
    pnpm i
    
  • バックエンドサービスを構築します。

    pnpm build
    pnpm bundle
    
  • シンボリックリンクを作成し、簡単デプロイ を参照して ecosystem.config.js を修正します。

    ln -s ./app/core/ecosystem.config.js ecosystem.config.js
    
  • バックエンドサービスを起動します。

    npm install -g pm2
    pm2 start ecosystem.config.js
    

フロントエンドの構築#

環境の準備#

  • 依存関係をインストールします。

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
    nvm install 20.12.2
    npm install -g pnpm pm2 
    npm i -g sharp
    

簡単デプロイ#

  • フロントエンドリポジトリ:Innie/Shiro

  • 直接ダウンロードした Linux 版を構築します。

    mkdir ~/mix-space/shiro && cd $_
    curl -L -O https://github.com/Innei/Shiro/releases/latest/download/release.zip
    unzip release.zip
    rm release.zip
    
  • ecosystem.config.js を編集します。

    module.exports = {
      apps: [
        {
          name: 'shiro',
          script: 'server.js',
          autorestart: true,
          watch: false,
          max_memory_restart: '500M',
          env: {
            PORT: 2323,
            NODE_ENV: 'production',
            NEXT_SHARP_PATH: process.env.NEXT_SHARP_PATH,
    	    NEXT_PUBLIC_API_URL: 'http://127.0.0.1:2323/api/v2',
    	    NEXT_PUBLIC_GATEWAY_URL: 'http://127.0.0.1:2323'
          },
          log_date_format: 'YYYY-MM-DD HH:mm:ss',
        },
      ],
    }
    
  • フロントエンドサービスを起動します。

    pm2 start ecosystem.config.js
    

自動デプロイ#

  • フロントエンドディレクトリを作成します。

    mkdir -p ~/mix-space/shiro && cd $_
    

    環境変数 .env を編集します。

    NEXT_PUBLIC_API_URL=https://example.net/api/v2
    NEXT_PUBLIC_GATEWAY_URL=https://example.net
    TMDB_API_KEY=
    GH_TOKEN=
    
  • フロントエンドリポジトリをフォークし、完了後に Actions タブに移動して Workflow を有効にし、次に Settings タブに移動して左側の [Secrets and variables] - [Actions] - [New repository secret] をクリックし、以下の変数を追加します。

NameSecretDescription
HOSTexample.comSSH ログインアドレス
PORT22SSH ログインポート
USERadminSSH ログインユーザー
PASSWORDP@ssw0rdSSH ログインパスワード、KEY と二者択一
KEYssh-rsa*****SSH プライベートキー、PASSWORD と二者択一
  • Code タブに切り替え、新しい .github/workflows/deploy.yml を作成します。

    name: Deploy
    
    on:
      push:
        branches: [main]
    
    permissions:
      contents: write
    
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
      cancel-in-progress: true
    
    jobs:
      build:
        name: Build artifact
        runs-on: ubuntu-latest
        strategy:
          matrix:
            node-version: [20.x]
        steps:
          - uses: actions/checkout@v4
            with:
              fetch-depth: 0
              lfs: true
    
          - name: Checkout LFS
            run: git lfs checkout
    
          - uses: pnpm/action-setup@v2
            with:
              version: 9.x.x
    
          - name: Setup Node.js
            uses: actions/setup-node@v4
            with:
              node-version: ${{ matrix.node-version }}
              cache: 'pnpm'
    
          - uses: jongwooo/next-cache@v1
    
          - name: Install & Build
            run: |
              pnpm install
              sh ./ci-release-build.sh
    
          - uses: actions/upload-artifact@v4
            with:
              name: release.zip
              path: assets/release.zip
    
      deploy:
        name: Deploy artifact
        runs-on: ubuntu-latest
        needs: build
        steps:
          - uses: actions/download-artifact@v4
            with:
              name: release.zip
    
          - name: SCP Transfer
            uses: appleboy/[email protected]
            with:
              host: ${{ secrets.HOST }}
              username: ${{ secrets.USER }}
              key: ${{ secrets.KEY }}
              password: ${{ secrets.PASSWORD }}
              port: ${{ secrets.PORT }}
              source: release.zip
              target: /tmp/shiro
    
          - name: Remote Deployment
            uses: appleboy/[email protected]
            with:
              host: ${{ secrets.HOST }}
              username: ${{ secrets.USER }}
              key: ${{ secrets.KEY }}
              password: ${{ secrets.PASSWORD }}
              port: ${{ secrets.PORT }}
              script: |
                set -ex
                source $HOME/.bashrc
                basedir=$HOME/mix-space/shiro
                workdir=$basedir/${{ github.sha }}
                mkdir -p $workdir
                mkdir -p $basedir/.cache
                mv /tmp/shiro/release.zip $workdir/release.zip
                rm -r /tmp/shiro
                cd $workdir
                unzip -qq -o $workdir/release.zip
                rm -rf $workdir/standalone/.env
                ln -s $HOME/shiro/.env $workdir/standalone/.env
                export NEXT_SHARP_PATH=$(npm root -g)/sharp
                # copy workdir ecosystem.config.js to basedir if not exists
                if [ ! -f $basedir/ecosystem.config.js ]; then
                  cp $workdir/standalone/ecosystem.config.js $basedir/ecosystem.config.js
                fi
                # https://github.com/Unitech/pm2/issues/3054
                # symlink workdir node entry file to basedir
                ln -sf $workdir/standalone/server.js $basedir/server.js
                mkdir -p $workdir/standalone/.next
                rm -rf $workdir/standalone/.next/cache
                ln -sf $basedir/.cache $workdir/standalone/.next/cache
                cd $basedir
                pm2 reload ecosystem.config.js --update-env
                rm $workdir/release.zip
                pm2 save
                echo "Deployed successfully"
    
  • Sync fork をクリックすると公式リポジトリの更新を同期できます。同期後、自動デプロイがトリガーされます。

  • さらに、こちらをクリックして作成 で vercel にワンクリックデプロイできます。環境変数を追加することを忘れずに、リポジトリを同期すると自動的に更新されます。

nginx の設定#

  • フロントエンド設定

    location ~* \.(gif|png|jpg|css|js|woff|woff2|svg|webp)$ {
      proxy_pass http://127.0.0.1:2323;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header REMOTE-HOST $remote_addr;
      expires 30d;
    }
    location ~* \/(feed|sitemap|atom.xml) {
      proxy_pass http://127.0.0.1:2333/$1;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header REMOTE-HOST $remote_addr;
      add_header X-Cache $upstream_cache_status;
      add_header Cache-Control max-age=60;
    }
    location / {
      proxy_pass http://127.0.0.1:2323;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header REMOTE-HOST $remote_addr;
      add_header X-Cache $upstream_cache_status;
      add_header Cache-Control no-cache;
      proxy_intercept_errors on;
    }
    
  • バックエンド設定

    location /socket.io {
      proxy_pass http://127.0.0.1:2333/socket.io; 
      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 REMOTE-HOST $remote_addr; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection "upgrade"; 
      proxy_buffering off;
      proxy_http_version 1.1; 
      add_header Cache-Control no-cache; 
    }
    
    location / {
      proxy_pass http://127.0.0.1:2333; 
      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 REMOTE-HOST $remote_addr; 
      add_header X-Cache $upstream_cache_status; 
    }    
    

特別編一:render デプロイ#

推奨指数:★★★★

難易度指数:★★★★

準備作業#

  1. MongoDB に登録
  2. GitHub に登録
  3. Render に登録
  4. Vercel に登録

フレームワークの構築#

  • MongoDB データベース
  • Render にデプロイされた Redis キャッシュ
  • Vercel にホスティングされたフロントエンドテーマ Shiro
  • Render にデプロイされたバックエンド Mix Space
📦 プロジェクト構造
├── 🗄️ データベース (MongoDB)
│   ├── 📂 ユーザーデータ
│   ├── 📂 記事データ
│   ├── 📂 その他のビジネスデータ

├── 🔥 キャッシュ層 (Redis - Render にデプロイ)
│   ├── ⚡ セッション情報を保存
│   ├── ⚡ ホットデータを保存
│   ├── ⚡ データベースのクエリ負荷を軽減

├── 🎨 フロントエンド (Shiro テーマ - Vercel にホスティング)
│   ├── 📦 依存関係: Next.js / React
│   ├── 🎨 UI コンポーネント
│   ├── 🔗 バックエンド API を呼び出す
│   ├── ⚙️ 状態管理

├── 🚀 バックエンド (Mix Space - Render にデプロイ)
│   ├── 📦 依存関係: Nest.js
│   ├── 🔗 MongoDB に接続
│   ├── 🔗 Redis キャッシュに接続
│   ├── 🔒 認証 & 認可
│   ├── 📡 API 処理

└── 🌐 デプロイ
    ├── 📤 フロントエンドを Vercel にデプロイ
    ├── 📤 バックエンド & Redis を Render にデプロイ
    ├── 🛠️ CI/CD 自動化

注意:バックエンドはデフォルトでテーマを持たず、サービスを実行した後、管理画面にログインする必要があります https://www.blog.com/proxy/qaqdmin でチュートリアルの最後に 云関数 を参照してテーマを設定してください。

構築を開始する#

  1. データベース:MongoDB

    作成手順は 抱脸部署 LibreChat チュートリアル を参照してください。ここでは詳細は省略します。

  2. キャッシュ:Redis

    • Render にログインし、右上の + をクリックして Key Value を選択します。
    • Nameredis を入力します。
    • ProjectProduction を選択します。
    • RegionSingapore を選択します。
    • Instance TypeFree を選択します。
    • Create Key Value Instance をクリックして作成します。
    • Connections の下で Internal Key Value URL をコピーし、形式は redis://red-cvdd4eofnakc738i3f00:6379 のようになります。クリップボードに貼り付けた後、中間部分 red-cvdd4eofnakc738i3f00REDIS_HOST として保持します。
  3. フロントエンド:Shiro

    • こちらをクリックして作成 し、名前を shiro と入力し、環境変数を変更した後、Deploy をクリックしてデプロイします。

      NameValueDescription
      NEXT_PUBLIC_API_URLhttps://backend.blog.com/api/v2バックエンド API インターフェースアドレス
      NEXT_PUBLIC_GATEWAY_URLhttps://backend.blog.com/バックエンドドメイン
    • Settings - Functions - Function RegionAsia - Hong Kong を選択して地域を変更します。選択する前にチェックを外すことを忘れないでください。

    • カスタムドメインを設定します。Vercel が割り当てたドメインは国内から直接接続できないため、カスタムドメインを追加する必要があります:

      1. Cloudflare でバインドするドメインに A レコードを追加して 76.223.126.88 を指し示します。
      2. Vercel の Shiro プロジェクトに移動し、Settings - Domains - Add をクリックします。
      3. バインドするドメインを入力し、Add Domain をクリックします。3 番目の項目にチェックを入れてから Add をクリックしてドメインのカスタマイズを完了します。

      ここでは追加したカスタムドメインを frontend.blog.com と仮定します。

  4. バックエンド:Mix Space

    • Render にログインし、右上の + をクリックして Web Service を選択します。

    • Existing image を選択し、Image URLinnei/mx-server:latest を入力します。

    • 数秒待ってから Connect をクリックします。

    • Namecore に変更します。

    • ProjectProduction を選択します。

    • RegionSingapore を選択します。

    • Instance TypeFree を選択します。

    • Environment Variables の下で Add from .env をクリックし、以下の環境変数を変更して入力ボックスに貼り付けます。

      ALLOWED_ORIGINS=frontend.blog.com
      REDIS_HOST=red-cvdd4eofnakc738i3f00
      DB_CONNECTION_STRING=mongodb+srv://<DB_USER>:<DB_PASSWORD>@<DB_USER>
      JWT_SECRET=************************
      

      ここで JWT_SECRET は以下のコマンドで迅速に生成できます。

      openssl rand -base64 24 | cut -c1-32
      
    • Deploy Web Service をクリックしてデプロイします。

    • 下にスクロールして Custom Domains の下で + Add Custom Domain をクリックし、カスタムドメインを入力します。形式は backend.blog.com です。

    • 指示に従ってドメインホスティングプロバイダー(Cloudflare など)に移動し、CNAME レコードを追加してから戻って verify をクリックして検証します。

特別編二:serv00 デプロイ#

推奨指数:★★★

難易度指数:★★★★★

環境の準備#

mkdir -p ~/.npm-global && npm config set prefix "$HOME/.npm-global" && echo 'export PATH=$HOME/.npm-global/bin:$PATH' >> ~/.profile && source ~/.profile && npm install -g pm2 && pm2

mkdir ~/.mx-space
npm install [email protected] --prefix ~/.mx-space

ストレージの準備#

devil mongo db add core

devil port add tcp 5555
cd ~/domains/***.serv00.net

fetch https://raw.githubusercontent.com/redis/redis/7.4/redis.conf

sed -i '' "s/^port .*/port 5555/" redis.conf
sed -i '' -E "s/^# requirepass .*/requirepass secure_pass/" redis.conf
sed -i '' 's/^appendonly no$/appendonly yes/' redis.conf

screen redis-server redis.conf

同時に CTRL+A+D を押して screen から退出し、redis をテストします。

redis-cli -h 127.0.0.1 -p 5555 -a secure_pass ping

成功すると PONG が返されます。

バックエンドのインストール#

注意:バックエンドはデフォルトでテーマを持たず、サービスを実行した後、管理画面にログインする必要があります https://www.blog.com/proxy/qaqdmin でチュートリアルの最後に 云関数 を参照してテーマを設定してください。

mkdir -p ~/domains/***.serv00.net/mix-space/core && cd $_
wget https://github.com/mx-space/core/releases/latest/download/release-linux.zip
unzip release-linux.zip
rm release-linux.zip

cat > ecosystem.config.js <<EOF
const { execSync } = require('node:child_process');
const nodePath = execSync(`npm root --quiet -g`, { encoding: 'utf-8' }).trim();
module.exports = {
  apps: [
    {
      name: 'core',
      script: 'index.js',
      autorestart: true,
      watch: false,
      max_memory_restart: '500M',
      args: [
        '--color',
        '--encrypt_enable',
        '--encrypt_key ********************(64桁)',
        '--redis_host 127.0.0.1',
        '--redis_port 5555',
        '--redis_password ********',
        '--db_host mongo15.serv00.com',
        '--collection_name mix-space',
        '--db_user mix-space',
        '--db_password ********',
        '--port 2333',
        '--allowed_origins example1.com,example2.com,localhost',
        '--jwt_secret *************(32桁)',
      ].join(' '),
      env: {
        NODE_ENV: 'production',
        NODE_PATH: nodePath,
      },
    },
  ],
};
EOF

pm2 start ecosystem.config.js

フロントエンドのインストール#

mkdir -p ~/domains/***.serv00.net/mix-space/shiro && cd $_
curl -L -O https://github.com/Innei/Shiro/releases/latest/download/release.zip
unzip release.zip
rm release.zip

cat > ecosystem.config.js <<EOF 
module.exports = {
  apps: [
    {
      name: 'shiro',
      script: 'server.js',
      autorestart: true,
      watch: false,
      max_memory_restart: '500M',
      env: {
        PORT: 2323,
        NODE_ENV: 'production',
        NEXT_SHARP_PATH: process.env.NEXT_SHARP_PATH,
	    NEXT_PUBLIC_API_URL: 'http://127.0.0.1:2323/api/v2',
	    NEXT_PUBLIC_GATEWAY_URL: 'http://127.0.0.1:2323'
      },
      log_date_format: 'YYYY-MM-DD HH:mm:ss',
    },
  ],
}
EOF

pm2 start ecosystem.config.js

云関数#

Shiro テーマ#

  • 管理画面にログインし、左下の 追加機能 - 設定と云関数 をクリックし、+ 新規作成 をクリックします。

  • 名前shiro を入力し、引用theme を入力し、右側のコードエリアに以下のコードを貼り付けて、適宜修正してください。

    {
      "footer": {
        "otherInfo": {
          "date": "2020-{{now}}",
          "icp": {
            "text": "萌 ICP 备 20236136 号",
            "link": "https://icp.gov.moe/?keyword=20236136"
          }
        },
        "linkSections": [
          {
            "name": "关于",
            "links": [
              {
                "name": "关于本站",
                "href": "/about-site"
              },
              {
                "name": "关于我",
                "href": "/about"
              },
              {
                "name": "关于此项目",
                "href": "https://github.com/innei/Shiro",
                "external": true
              }
            ]
          },
          {
            "name": "更多",
            "links": [
              {
                "name": "时间线",
                "href": "/timeline"
              },
              {
                "name": "友链",
                "href": "/friends"
              },
              {
                "name": "监控",
                "href": "https://status.innei.in/status/main",
                "external": true
              }
            ]
          },
          {
            "name": "联系",
            "links": [
              {
                "name": "写留言",
                "href": "/message"
              },
              {
                "name": "发邮件",
                "href": "mailto:[email protected]",
                "external": true
              },
              {
                "name": "GitHub",
                "href": "https://github.com/innei",
                "external": true
              }
            ]
          }
        ]
      },
      "config": {
        "color": {
          "light": [
            "#33A6B8",
            "#FF6666",
            "#26A69A",
            "#fb7287",
            "#69a6cc",
            "#F11A7B",
            "#78C1F3",
            "#FF6666",
            "#7ACDF6"
          ],
          "dark": [
            "#F596AA",
            "#A0A7D4",
            "#ff7b7b",
            "#99D8CF",
            "#838BC6",
            "#FFE5AD",
            "#9BE8D8",
            "#A1CCD1",
            "#EAAEBA"
          ]
        },
     
        "bg": [
          "https://github.com/Innei/static/blob/master/images/F0q8mwwaIAEtird.jpeg?raw=true",
          "https://github.com/Innei/static/blob/master/images/IMG_2111.jpeg.webp.jpg?raw=true"
        ],
        "custom": {
          "css": [],
          "styles": [],
          "js": [],
          "scripts": []
        },
        "site": {
          "favicon": "/innei.svg",
          "faviconDark": "/innei-dark.svg"
        },
        "hero": {
          "title": {
            "template": [
              {
                "type": "h1",
                "text": "Hi, I'm ",
                "class": "font-light text-4xl"
              },
              {
                "type": "h1",
                "text": "Innei",
                "class": "font-medium mx-2 text-4xl"
              },
              {
                "type": "h1",
                "text": "👋。",
                "class": "font-light text-4xl"
              },
              {
                "type": "br"
              },
              {
                "type": "h1",
                "text": "A NodeJS Full Stack ",
                "class": "font-light text-4xl"
              },
              {
                "type": "code",
                "text": "<Developer />",
                "class": "font-medium mx-2 text-3xl rounded p-1 bg-gray-200 dark:bg-gray-800/0 hover:dark:bg-gray-800/100 bg-opacity-0 hover:bg-opacity-100 transition-background duration-200"
              },
              {
                "type": "span",
                "class": "inline-block w-[1px] h-8 -bottom-2 relative bg-gray-800/80 dark:bg-gray-200/80 opacity-0 group-hover:opacity-100 transition-opacity duration-200 group-hover:animation-blink"
              }
            ]
          },
          "description": "An independent developer coding with love."
        },
        "module": {
          "activity": {
            "enable": true,
            "endpoint": "/fn/ps/update"
          },
          "donate": {
            "enable": true,
            "link": "https://afdian.net/@Innei",
            "qrcode": [
              "https://cdn.jsdelivr.net/gh/Innei/img-bed@master/20191211132347.png",
              "https://cdn.innei.ren/bed/2023/0424213144.png"
            ]
          },
          "bilibili": {
            "liveId": 1434499
          }
        }
      }
    }
    

PS ステータスプラグイン#

  • 管理画面にログインし、左下の 追加機能 - 設定と云関数 をクリックし、+ 新規作成 をクリックします。
  • 名前update を入力し、引用ps を入力し、データタイプFunction に選択し、リクエスト方法POST に選択し、Secret の左側の入力ボックスに key を入力し、右側にキーの値を入力します。次に こちらをクリック してすべての内容をコピーし、右側のコードエリアに貼り付け、最後に緑のボタンをクリックして保存します。
  • Kizuna をダウンロードしてインストールし、Windows システムではショートカットキー WIN + R を押して notepad %USERPROFILE%\AppData\Local\kizuna\config.yml を編集します。
server_config:
  endpoint: "https://backend.example.com/api/v2/fn/ps/update" # https://api.example.com/api/v2/fn/ps/update
  token: "YOUR-KEY-HERE" # 設定したキー
  report_time: 5 # 上報時間間隔、単位は秒
rules: # ソフトウェア名の置換ルール
  - match_application: WeChat
    replace:
      application: 微信
      description: 一个小而美的办公软件
  - match_application: QQ
    replace:
      application: QQ
      description: 一个多功能的通讯软件
  - match_application: Netease Cloud Music
    replace:
      application: 网易云音乐
      description: 一个音乐播放和分享的平台          

編集が完了したら CTRL + S で保存し、閉じてから Kizuna を実行すると、定期的に定義されたエンドポイントにアクティビティデータがアップロードされます。

参考リンク#

Mix Space 公式ドキュメント

Mix-Space デプロイ最新フロントエンド Shiro

Mix-Space 構築入門から入土まで

この記事は Mix Space によって xLog に同期更新されました。原始リンクは https://reno.zone.id/posts/default/mix-space-blog-guide

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。