mx-space (Old Version) Deployment Guide

This post was last updated 2 年前. Some content may be outdated. Contact the author if in doubt.

mx-space (Old Version) Deployment Guide

Preface

Timo-chan switched to a new blog system. I wonder if anyone has thought about deploying one to play with? Today I'll explain my deployment process in detail. ## Disclaimer This program was not written by me. If you encounter problems during deployment you can ask me, but asking the author innei will be more efficient. This tutorial is a secondary modification based on Mx-space, a newly created open-source personal space. ## Deployment Requirements - Server environment: Centos 7. Do not use Centos8 — it has stopped receiving updates; Centos7 is still supported until 2024 - Required software: vim, Node.js 14, MongoDB, Redis, Yarn, BT Panel (BaoTa). - Server memory requirement: greater than 1G, otherwise you may encounter out-of-memory errors. - A brain that thinks critically and can ask the right questions. ## Deployment Preparation ### Install Required Software - Install Nginx, pm2 manager, MongoDB, Redis in the BT Panel. - Install Yarn ```bash npm install -g yarn

After installation, check the version numbers
```bash
node -v
yarn -v
Copy

Clone the repo

Please note! You must stay in the same directory! In the original tutorial it was written like this But because some projects have changed, it should be like this ```bash cd mkdir mx cd mx #源仓库 git clone --branch v1.18.0 https://github.com/mx-space/kami.git #速度太慢可选
git clone --branch v1.18.0 https://gitee.com/a1435241/kami.git #源仓库
git clone --branch v2.5.0 https://github.com/mx-space/admin-next.git #速度太慢可选
git clone --branch v2.5.0 https://gitee.com/a1435241/admin-next.git #源仓库
git clone https://github.com/mx-space/server.git #速度太慢可选
git clone https://gitee.com/a1435241/server.git

###     Prepare domain names
It is recommended to point three domains directly to the server.

Assuming the domains are:

Frontend: kami.test.cn

Admin: admin.test.cn

Backend: server.test.cn
##  Start Deployment
###   Prepare Sites
Add the sites one by one under the BT Panel - `网站`.
Then click `设置` to deploy the SSL certificate.
###    Deploy the Server
1. Go to the BT Panel site settings, click the configuration file, and add the following code before the access_log line:
![](https://cdn.timochan.cn/img/QQ截图20210910153827.png)
```nginx
location /socket.io {
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass http://127.0.0.1:2333/socket.io;
    }
Copy
  1. In the home directory enter cd ~/mx/server to navigate to the server folder

Then run yarn to install

Input cp .env.example .env to copy .env.example to .env

  1. Enter the command: vim .env, press i to enter edit mode, and modify the content. Configuration reference is below.

Note: The vim steps can be completed in the BT Panel and will not be repeated here.

Server .env Configuration Reference

TEXT
SECRET=ahsdljasdasdhaisASHLDasdassdasdasrwedwqe #参考值,不用管
PORT=2333
CORS=1
APP_MAX_MEMORY=150M
ORIGIN=kami.test.cn,admin.test.cn #修改此项为你前端,admin的访问地址,用,分割
Copy
  1. Find ecosystem.config.js and replace all of its contents with the code below: ```text /*
    • @Author: Innei
    • @Date: 2020-04-30 18:14:55
    • @LastEditTime: 2020-05-25 21:05:26
    • @LastEditors: Innei
    • @FilePath: /mx-server/ecosystem.config.js
    • @Copyright*/

const env = require('dotenv').config().parsed module.exports = { apps: [ { name: 'mx-space-server', script: 'dist/apps/server/main.js', autorestart: true, instances: 'max', exec_mode: 'cluster', watch: false, // instances: 1, // max_memory_restart: env.APP_MAX_MEMORY || '150M', env: { NODE_ENV: 'production', ...env, }, }, ], } 5. Then enter `:wq` to exit, and run the following commandsbash yarn yarn build yarn prod:pm2 ``` 6. Go to the BT Panel site settings, click the Reverse Proxy tab, click Add Reverse Proxy. Give the proxy any name, set the Target URL to http://127.0.0.1:2333, leave other settings unchanged, and save.

Note: If you encounter errors, you can first revert the site's configuration file, set the reverse proxy, and then change it back.

Deploy Admin

  1. In the home directory run cd mx/admin-next and then run yarn to install

  2. Enter the command vim .env.production, press i, and modify the content #### Admin .env Configuration Reference text VITE_APP_BASE_API=https://server.test.cn/api/v1 VITE_APP_WEB_URL=https://test.cn VITE_APP_GATEWAY=https://server.test.cn VITE_APP_PUBLIC_URL= VITE_APP_IPV6_LOOKUP_API_URL= VITE_APP_GAODEMAP_KEY= VITE_APP_LOGIN_BG=https://gitee.com/xun7788/my-imagination/raw/master/images/88426823_p0.jpg Then enter :wq to exit

  3. Run yarn build to build

Then run cp -rf dist/* /www/wwwroot/admin.test.cn/ to move the built package to the site directory (please change admin.test.cn to your admin domain). After that Admin will be deployed — visit admin; the initial password is master.

Please delete the original admin site root directory files.

Deploy Kami

  1. In the home directory run cd mx/kami/ then run yarn to install

Run cp .env.example .env to copy the example

  1. Enter the command: vim .env, press i to enter edit mode, and modify the contents #### Kami .env Configuration Reference text BASEURL=https://kami.test.cn APIURL=https://server.test.cn/api/v1 TRACKING_ID=G-X4PVVRB6TF ASSETPREFIX= REDIS=1 GATEWAY_URL=https://server.test.cn ALWAYS_HTTPS=1 NEXT_PUBLIC_SENTRY_DSN= SENTRY_ORG= SENTRY_PROJECT= SENTRY_AUTH_TOKEN= NETEASE_PHONE= NETEASE_PASSWORD= BASEURL change to the frontend

APIURL change the server.test.cn in front to your server

GATEWAY_URL change this to your backend (Server)

NETEASE_PHONE Netease Music account phone (used to fetch music)

NETEASE_PASSWORD Netease Music account password (used to fetch music) #### Modify Kami Configuration 1. Edit mx/kami/public/manifest.json and update the JSON inside with your own content

  1. Enter mx/kami and edit configs.ts, following the examples to change to your own content

  2. Then run yarn build to build

  3. After the build completes, run pm2 start ecosystem.config.js. You may need to run pm2 save

  4. Go to the BT Panel site settings, click the Reverse Proxy tab, click Add Reverse Proxy. Give the 代理名称 any name, set the 目标URL to http://127.0.0.1:2323, leave other settings unchanged, and save.

If you find runtime anomalies, switch the Node version in the pm2 manager.

Additional Notes

If admin configuration changes do not take effect

Enter redis-cli to open the Redis client

Enter FLUSHALL; if it returns OK then it's done~

You can install htop to observe overall resource usage bash yum install htop -y htop And after running, run pm2 ps to check whether it started successfully ┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐ │ id │ name │ mode │ │ status │ cpu │ memory │ ├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤ │ 1 │ mx-space-graphql │ cluster │ 0 │ online │ 0% │ 54.6mb │ │ 3 │ mx-space-graphql │ cluster │ 0 │ online │ 0% │ 55.9mb │ │ 0 │ mx-space-server │ cluster │ 1 │ online │ 0% │ 112.0mb │ │ 2 │ mx-space-server │ cluster │ 4 │ online │ 0% │ 109.9mb │ │ 4 │ mx-web │ fork │ 5631 │ online │ 0% │ 40.7mb │ │ 5 │ mx-web │ fork │ 8828 │ online │ 0% │ 1.4mb │ └────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘ ## Documentation ### Admin: Edit Information First go to admin; the initial password is master

After entering, click Settings - Users

Edit nickname, alias, etc.

Remember to save!

Click the Security option and enter a new password to change the admin login password. ### Necessary Configuration Changes Click 设定 - 系统-网站设置

Change the website settings to your corresponding address (accessible from the Internet unless you are running locally on localhost). The Gateway address does not need to be changed; leave it as default and click Save!

There are also some SEO settings later; modify them as needed ### Add Pages The homepage has two page entries: Message and About

Go to Admin - Pages - Create New Page

Choose the title and subtitle as you like, but make sure the path name below is correct

About path is: about

Message path is: message ### Apply Changes After Modifying Kami Enter the kami directory and run the following commands: bash yarn build pm2 start ecosystem.config.js

Frontend Login

The URL is: frontend-domain/login