banner
jiuyue

jiuyue

JiuYue

Mix-Space backend Core uses a remote database

This article is applicable to: Your Mix-Space backend Core using a remote MongoDb / Redis database, or if you need to configure a password for MongoDB / Redis, you can refer to this article.

|| If there is no special need, don't mess around. ||

My Environment#

  • Server A: Deploy MongoDB and Redis
  • Server B: Deploy Mix Space Core

MongoDB Configuration#

I installed it using the 1Panel store, which creates a root user by default; mx-space needs to connect to the mx-space database, and the root user cannot be used directly, so I chose to create a new user for the mx-space database.

  1. Connect to MongoDB using the root user
mongosh --host <host> --port <port> -u <admin_user> -p <admin_password> --authenticationDatabase admin
# I am executing this inside the MongoDB container, so --host and --port are not needed.
  1. Switch to the mx-space database
use mx-space
  1. Create a user for the mx-space database
db.createUser({
  user: "UserName",           // Username
  pwd: "UserPassword",      // User password
  roles: [
    { role: "readWrite", db: "mx-space" },  // Grant user readWrite permission
    { role: "dbAdmin", db: "mx-space" }     // Grant user dbAdmin permission
  ]
})
  1. Verify and test
show users 
# Verify if the user was created successfully
mongo --username UserName --password UserPassword --authenticationDatabase mx-space
# Connection test

MongoDB has an authentication database and a connection database. At first, I kept using the root user, which caused mx-space to be unable to connect; I don't really understand these two databases, but they are quite important, so it's good to learn about them (.

Redis Configuration#

There isn't anything particularly special about the configuration; I installed it on the same server as MongoDB, and it should be separable from MongoDB, but I encountered a problem: the frontend auth had issues, which caused it to fail to load correctly, so I simply deployed it together with MongoDB.
image
It is important to note: This RDB persistence inserts one piece of data every N seconds; it is recommended to set it to the default of 3600 seconds or higher, otherwise the frontend may not be able to correctly retrieve the data being viewed by XX people.

I don't know any other advanced Redis configurations; just modify as needed if you understand. 😢

Core YAML File Configuration#

The official documentation has more detailed parameter descriptions, please use it in conjunction:
https://mx-space.js.org/docs/core/extra

Below is an example of the docker-compose.yml configuration I am currently using.

services:
  app:
    container_name: mx-server
    image: innei/mx-server:latest
    environment:
      - TZ=Asia/Shanghai
      - NODE_ENV=production
      - DB_HOST=127.0.0.1 # Database address
      - DB_USER=username # Database username
      - DB_PASSWORD=userpassword # Database password
      - REDIS_HOST=127.0.0.1 # Redis address
      - REDIS_PASSWORD=redispwd # Redis password
      - ALLOWED_ORIGINS=www.example.com # Allowed frontend domain
      - JWT_SECRET=xxxxxxxxx # JWT secret
      - ENCRYPT_ENABLE=true # Database encryption (enable as needed)
      - ENCRYPT_KEY=xxxxxxxxxxxxxxxx # Database encryption password, if lost, recovery from backup files will not be possible, and then you can run away (x
    volumes:
      - ./data/mx-space:/root/.mx-space
    ports:
      - '2333:2333'

    networks:
      - mx-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
networks:
  mx-space:
    driver: bridge

This article is synchronized and updated to xLog by Mix Space. The original link is https://www.vlo.cc/posts/jc/MixSpace_backend_Core_uses_remote_database

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.