needs to copy the my.cnf to each mysql service for it to use user=root instead of the default user=mysql. also for portainer, nodejs can now access different dbs. will need to create tbl for tbl_user inside the popcenauth schema and for the mysql-data, it needs to connect to my local db?? idk
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const { dataDb } = require("../../config/db");
|
||||
const { dataDb } = require("../../config/dataDb");
|
||||
const verifyToken = require("../../middlewares/authMiddleware");
|
||||
|
||||
router.get("/", verifyToken, (req, res) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const { dataDb } = require("../../config/db");
|
||||
const { dataDb } = require("../../config/dataDb");
|
||||
const verifyToken = require("../../middlewares/authMiddleware");
|
||||
|
||||
router.get("/", verifyToken, (req, res) => {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
const mysql = require("mysql2");
|
||||
const dotenv = require("dotenv");
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// Authentication DB connection
|
||||
const authDb = mysql.createConnection({
|
||||
host: process.env.AUTH_DB_HOST,
|
||||
user: process.env.AUTH_DB_USER,
|
||||
password: process.env.AUTH_DB_PASSWORD,
|
||||
database: process.env.AUTH_DB_NAME,
|
||||
});
|
||||
|
||||
authDb.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Auth DB connection failed:", err.stack);
|
||||
return;
|
||||
}
|
||||
console.log("Connected to the Authentication DB.");
|
||||
});
|
||||
|
||||
// Data DB connection
|
||||
const dataDb = mysql.createConnection({
|
||||
host: process.env.DATA_DB_HOST,
|
||||
user: process.env.DATA_DB_USER,
|
||||
password: process.env.DATA_DB_PASSWORD,
|
||||
database: process.env.DATA_DB_NAME,
|
||||
});
|
||||
|
||||
dataDb.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Data DB connection failed:", err.stack);
|
||||
return;
|
||||
}
|
||||
console.log("Connected to the Data DB.");
|
||||
});
|
||||
|
||||
module.exports = { authDb, dataDb };
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
# For advice on how to change settings please see
|
||||
# http://dev.mysql.com/doc/refman/9.0/en/server-configuration-defaults.html
|
||||
|
||||
[mysqld]
|
||||
#
|
||||
# Remove leading # and set to the amount of RAM for the most important data
|
||||
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
|
||||
# innodb_buffer_pool_size = 128M
|
||||
#
|
||||
# Remove leading # to turn on a very important data integrity option: logging
|
||||
# changes to the binary log between backups.
|
||||
# log_bin
|
||||
#
|
||||
# Remove leading # to set options mainly useful for reporting servers.
|
||||
# The server defaults are faster for transactions and fast SELECTs.
|
||||
# Adjust sizes as needed, experiment to find the optimal values.
|
||||
# join_buffer_size = 128M
|
||||
# sort_buffer_size = 2M
|
||||
# read_rnd_buffer_size = 2M
|
||||
|
||||
host-cache-size=0
|
||||
skip-name-resolve
|
||||
datadir=/var/lib/mysql
|
||||
socket=/var/run/mysqld/mysqld.sock
|
||||
secure-file-priv=/var/lib/mysql-files
|
||||
user=root
|
||||
|
||||
pid-file=/var/run/mysqld/mysqld.pid
|
||||
[client]
|
||||
socket=/var/run/mysqld/mysqld.sock
|
||||
|
||||
!includedir /etc/mysql/conf.d/
|
||||
+40
-13
@@ -1,19 +1,39 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
mysql:
|
||||
# Authentication Database
|
||||
mysql-auth:
|
||||
image: mysql:latest
|
||||
container_name: mysql
|
||||
container_name: mysql-auth
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 12345678
|
||||
MYSQL_DATABASE: popcen
|
||||
MYSQL_PASSWORD: 12345678
|
||||
MYSQL_DATABASE: popcenauth
|
||||
MYSQL_USER: admin
|
||||
ports:
|
||||
- "3307:3306"
|
||||
|
||||
- "3308:3306" # Different port for the auth DB
|
||||
volumes:
|
||||
- mysqldata:/var/lib/mysql
|
||||
#- D:/Projects/AuthenticatedAPIDocker/app/mysql/etc/mysql/mysqlauth/etc:/etc
|
||||
- D:/Projects/AuthenticatedAPIDocker/app/mysql/mysqldata_auth:/var/lib/mysql
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
|
||||
# Data Database
|
||||
mysql-data:
|
||||
image: mysql:latest
|
||||
container_name: mysql-data
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 12345678
|
||||
MYSQL_DATABASE: popcen
|
||||
MYSQL_USER: admin # Change to root
|
||||
ports:
|
||||
- "3309:3306" # Default port for the data DB
|
||||
volumes:
|
||||
# - D:/Projects/AuthenticatedAPIDocker/app/mysql/etc/mysql/mysqldata/etc:/etc
|
||||
- D:/Projects/AuthenticatedAPIDocker/app/mysql/mysqldata:/var/lib/mysql
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
|
||||
# Node.js Service
|
||||
nodejs:
|
||||
image: f04c/nodemysqlv2:latest
|
||||
container_name: nodejs
|
||||
@@ -23,14 +43,21 @@ services:
|
||||
ports:
|
||||
- "3001:3000"
|
||||
environment:
|
||||
DB_HOST: 192.168.23.20
|
||||
DB_USER: root
|
||||
DB_PASSWORD: 12345678
|
||||
DB_NAME: popcen
|
||||
# Auth DB connection
|
||||
AUTH_DB_HOST: mysql-auth
|
||||
AUTH_DB_USER: admin
|
||||
AUTH_DB_NAME: popcenauth
|
||||
|
||||
# Data DB connection
|
||||
DATA_DB_HOST: mysql-data
|
||||
DATA_DB_USER: admin
|
||||
DATA_DB_NAME: popcen
|
||||
|
||||
depends_on:
|
||||
- mysql
|
||||
- mysql-auth
|
||||
- mysql-data
|
||||
command: "node server.js"
|
||||
|
||||
volumes:
|
||||
API2:
|
||||
mysqldata_auth:
|
||||
mysqldata:
|
||||
|
||||
Reference in New Issue
Block a user