Skip to content

Create databases

i0gan edited this page Apr 10, 2024 · 2 revisions

Intro

The database involves four types of databases, and the responsibilities of these three databases, mysql, mongodb, redis, and clickhouse, are also different. To build a database, it is recommended to use docker to create a database instance. This is example use docker to quickly create databases, If the docker is not installed, please install it in your system.

Windows or Mac: https://www.docker.com/products/docker-desktop/

Linux:

# sudo apt install docker # for ubuntu, debian
# sudo pacman -S docker # for arch linux

Create Mysql player account database

Responsible for login and player account data. This database uses the latest version of mysql8.

docker run -d --restart always --name squick_db_mysql_1 -p 10400:33060 -e MYSQL_ROOT_PASSWORD=pwnsky_squick  mysql:8.0

The pwnsky_squick is the password, import basic sql, in the {project_path}/resource/mysql directory

docker exec -it squick_db_mysql_1 bash
mysql -uroot -ppwnsky_squick

Copy and paste the sql code to execute

Create Mongo game database

Responsible for stores player data in the game.

Pull the mongo image and create a running mongo container

docker run -d --restart always --name squick_db_mongo_1 -p 10410:27017 -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=pwnsky_squick mongo:6.0.5 mongod --auth

Create Redis cache database

Responsible for caching data between Squick servers

docker run -d --restart always --name squick_db_redis_1 -p 10420:6379 redis:7.0 --requirepass pwnsky_squick

Create Clickhouse log database

Responsible for recording server logs, game logs, buried point data, etc.

docker run -d --restart always --name squick_db_clickhouse_1 -p 10430:8123 -p 10431:9000 -p 10432:9009 clickhouse/clickhouse-server:23.1.3.5-alpine

Enter the container after creation

docker exec -it squick_db_clickhouse_1 bash
vi /etc/clickhouse-server/users.xml

# Find <password></password>
# Add pwnsky_squick in the middle

Modify squick db configuration file

Open {project_path}/config/node/db.json file, modify the each database's ip and port.

Default file as follows:

{
    "Mysql" : {
        "Account" : { "ip":"127.0.0.1", "port":10400, "user":"root", "password":"pwnsky_squick", "database":"player"}
    },
    "Mongo" : {
        "Player" : { "ip":"127.0.0.1", "port":10410, "user":"admin", "password":"pwnsky_squick", "database":"game"}
    },
    "Redis" : {
        "Cache" : { "ip":"127.0.0.1", "port":10420, "user":"root", "password":"pwnsky_squick", "database":""}
    },
    "Clickhouse" : {
        "Log" : { "ip":"127.0.0.1", "port":10431, "user":"default", "password":"pwnsky_squick", "database":"squick"}
    }
}
Clone this wiki locally