✨ feat(script): 增加大区时自动处理代码的脚本和模板
This commit is contained in:
27
scripts/easyMonitorTemplate.js
Normal file
27
scripts/easyMonitorTemplate.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// config
|
||||||
|
const fs = require('fs');
|
||||||
|
module.exports = {
|
||||||
|
// I. 必须的配置
|
||||||
|
server: 'MONITOR_SERVER_URL', // 填写前一节中部署的 xtransit-server 地址
|
||||||
|
appId: 'MONITOR_ID', // 创建应用得到的应用 ID
|
||||||
|
appSecret: 'MONITOR_SECRET', // 创建应用得到的应用 Secret
|
||||||
|
|
||||||
|
// II. 比较重要的可选配置
|
||||||
|
disks: [], // 数组,配置需要监控的 disk 全路径
|
||||||
|
errors: [], // 数组,配置需要监控的 error 日志全路径
|
||||||
|
packages: [], // 数组,配置需要监控的项目依赖文件全路径
|
||||||
|
|
||||||
|
// III. 不是很重要的可选的配置
|
||||||
|
logDir: '/zyz_logs/xprofiler', // xprofiler 插件生成性能日志文件的目录,默认两者均为 os.tmpdir()
|
||||||
|
docker: false, // 默认 false, 系统数据采集会依赖当前是否是 docker 环境而进行一些特殊处理,可以手动强制指定当前实例是否为 docker 环境
|
||||||
|
ipMode: false, // 默认 false,此时仅使用 hostname 作为 agentId;设置为 true 后 agentId 组装形式为 ${ip}_${hostname}
|
||||||
|
libMode: false, // 默认 false,此时采集如果收到 shutdown 事件会退出当前进程;如果是以第三方库的形式引用接入应用内,请将此属性设置为 true
|
||||||
|
errexp: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/i, // 匹配错误日志起始的正则,默认为匹配到 YYYY-MM-DD HH:mm:ss 时间戳即认为是一条错误日志的起始
|
||||||
|
logger: console, // 可以传入应用日志句柄方便日志统一管理,需要实现 error, info, warn 和 debug 四个方法
|
||||||
|
logLevel: 2, // 默认内置 logger 的日志级别,0 error,1 info,2 warning,3 debug,
|
||||||
|
titles: [], // 数组,如果应用使用了 process.title 自定义了名称,可以通过配置这里上报进程数据
|
||||||
|
customAgent: () => {
|
||||||
|
const hostname = fs.readFileSync('/etc/aliashost', 'utf8').trim();
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
};
|
||||||
51
scripts/gmServerTemplate.ts
Normal file
51
scripts/gmServerTemplate.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||||
|
import defaultConfig from './config.default';
|
||||||
|
|
||||||
|
export default (appInfo: EggAppInfo) => {
|
||||||
|
const config = {} as PowerPartial<EggAppConfig>;
|
||||||
|
|
||||||
|
// add your special config in here
|
||||||
|
|
||||||
|
config.mongoose = {
|
||||||
|
url: 'MONGO_URL', // 内网
|
||||||
|
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
config.gmmongoose = {
|
||||||
|
url: 'GM_MONGO_URL', // 内网
|
||||||
|
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
config.redis = {
|
||||||
|
url: 'REDIS_URL', // 内网
|
||||||
|
pw: 'REDIS_PASS'
|
||||||
|
};
|
||||||
|
|
||||||
|
config.xtransit = {
|
||||||
|
server: 'GM_MONITOR_SERVER_URL',
|
||||||
|
appId: 'GM_MONITOR_ID',
|
||||||
|
appSecret: 'GM_MONITOR_SECRET'
|
||||||
|
};
|
||||||
|
|
||||||
|
config.customLogger = {
|
||||||
|
linkLogger: {
|
||||||
|
file: '/zyz_logs/gm-server/link-log.log',
|
||||||
|
formatter(meta) {
|
||||||
|
return `[${meta.level}] [${meta.date}] ${meta.message}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
config.logrotator = {
|
||||||
|
filesRotateBySize: [
|
||||||
|
'/zyz_logs/gm-server/link-log.log',
|
||||||
|
],
|
||||||
|
maxFileSize: 1024,
|
||||||
|
};
|
||||||
|
|
||||||
|
// the return config will combines to EggAppConfig
|
||||||
|
return {
|
||||||
|
...defaultConfig(appInfo),
|
||||||
|
...config,
|
||||||
|
};
|
||||||
|
};
|
||||||
190
scripts/log4jsTemplate.ts
Normal file
190
scripts/log4jsTemplate.ts
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
module.exports = {
|
||||||
|
'appenders': {
|
||||||
|
'console': {
|
||||||
|
'type': 'console'
|
||||||
|
},
|
||||||
|
'con-log': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/con-log-${opts:serverId}.log',
|
||||||
|
'pattern': 'connector',
|
||||||
|
'maxLogSize': 104857600,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'rpc-log': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/rpc-log-${opts:serverId}.log',
|
||||||
|
'maxLogSize': 104857600,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'forward-log': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/forward-log-${opts:serverId}.log',
|
||||||
|
'maxLogSize': 104857600,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'rpc-debug': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/rpc-debug-${opts:serverId}.log',
|
||||||
|
'maxLogSize': 104857600,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'crash-log': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/crash.log',
|
||||||
|
'maxLogSize': 104857600,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'admin-log': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/admin.log',
|
||||||
|
'maxLogSize': 104857600,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'pinus': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/pinus-${opts:serverId}.log',
|
||||||
|
'maxLogSize': 1073741824,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 20
|
||||||
|
},
|
||||||
|
'pinus-admin': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/pinus-admin.log',
|
||||||
|
'maxLogSize': 104857600,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'pinus-rpc': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/log4js/pinus-rpc-${opts:serverId}.log',
|
||||||
|
'maxLogSize': 104857600,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'app': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/sls/app.log',
|
||||||
|
'maxLogSize': 1073741824,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 20
|
||||||
|
},
|
||||||
|
'error': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/sls/error.log',
|
||||||
|
'maxLogSize': 1073741824,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
},
|
||||||
|
'ta': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/ta/log',
|
||||||
|
'pattern': 'yyyy-MM-dd-hh',
|
||||||
|
'alwaysIncludePattern': true,
|
||||||
|
'layout': {
|
||||||
|
'type': 'pattern',
|
||||||
|
'pattern': '%m',
|
||||||
|
},
|
||||||
|
'backups': 240,
|
||||||
|
},
|
||||||
|
'item': {
|
||||||
|
'type': 'file',
|
||||||
|
'filename': '/zyz_logs/item/log',
|
||||||
|
'maxLogSize': 1073741824,
|
||||||
|
'layout': {
|
||||||
|
'type': 'basic'
|
||||||
|
},
|
||||||
|
'backups': 5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'categories': {
|
||||||
|
'default': {
|
||||||
|
'appenders': ['console', 'pinus'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'con-log': {
|
||||||
|
'appenders': ['con-log'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'rpc-log': {
|
||||||
|
'appenders': ['rpc-log'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'forward-log': {
|
||||||
|
'appenders': ['forward-log'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'rpc-debug': {
|
||||||
|
'appenders': ['rpc-debug'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'crash-log': {
|
||||||
|
'appenders': ['crash-log'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'admin-log': {
|
||||||
|
'appenders': ['admin-log'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'pinus-admin': {
|
||||||
|
'appenders': ['pinus-admin'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'pinus-rpc': {
|
||||||
|
'appenders': ['pinus-rpc'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'pinus': {
|
||||||
|
'appenders': ['pinus'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'info': {
|
||||||
|
'appenders': ['console', 'app'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'err': {
|
||||||
|
'appenders': ['console', 'error'],
|
||||||
|
'level': 'debug'
|
||||||
|
},
|
||||||
|
'ta': {
|
||||||
|
'appenders': ['console', 'ta'],
|
||||||
|
'level': 'info'
|
||||||
|
},
|
||||||
|
'item': {
|
||||||
|
'appenders': ['console', 'item'],
|
||||||
|
'level': 'info'
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
'replaceConsole': true,
|
||||||
|
'lineDebug': false,
|
||||||
|
'errorStack': true
|
||||||
|
};
|
||||||
148
scripts/newServerConfig.js
Normal file
148
scripts/newServerConfig.js
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
// 新建大区的部分配置脚本
|
||||||
|
// ! servers 和 master 使用单独脚本半自动配置,不在此文件配置范围内
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
// 新大区 env
|
||||||
|
var ENV = 'ch1';
|
||||||
|
// 新大区数据库配置
|
||||||
|
var MONGO_URL = 'mongodb://yjzDbOp:yjz2023ZyDB@dds-8vb6c08497bde7141.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb6c08497bde7142.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb6c08497bde7143.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb6c08497bde7144.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-516005505';
|
||||||
|
var SUB_MONGO_URL = 'mongodb://yjzDbOp:yjz2023ZyDB@dds-8vbc6a169e1dd6941.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6942.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6943.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6944.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-516005504';
|
||||||
|
var GM_MONGO_URL = 'mongodb://yjzGmDbOp:yjz2023ZyGmDB@dds-8vbdf8c89bbdbd241.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbdf8c89bbdbd242.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbdf8c89bbdbd243.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbdf8c89bbdbd244.mongodb.zhangbei.rds.aliyuncs.com:3717/zyzgm?replicaSet=mgset-515829436';
|
||||||
|
// 新大区redis配置
|
||||||
|
var REDIS_URL = 'r-8vbqgdc3h9ac77fdvi.redis.zhangbei.rds.aliyuncs.com';
|
||||||
|
var REDIS_PASS = 'hWCJ$HDajm9SN&&Z';
|
||||||
|
var REDLOCK_URL = 'r-8vbiuvng869tbuynxn.redis.zhangbei.rds.aliyuncs.com';
|
||||||
|
var REDLOCK_PASS = 'hWCJ$HDajm9SN&&Z';
|
||||||
|
// 新大区game监控配置
|
||||||
|
var MONITOR_ID = 4;
|
||||||
|
var MONITOR_SECRET = '20cdf62e8ab0f3a751e7a5f7a0abbd33';
|
||||||
|
var MONITOR_SERVER_URL = 'ws://172.16.4.147:9092';
|
||||||
|
// 新大区web监控配置
|
||||||
|
var WEB_MONITOR_ID = 5;
|
||||||
|
var WEB_MONITOR_SECRET = '1c85221722efa1daec1097cd802ac939';
|
||||||
|
var WEB_MONITOR_SERVER_URL = 'ws://172.16.4.147:9092';
|
||||||
|
// 新大区gm监控配置
|
||||||
|
var GM_MONITOR_ID = 3;
|
||||||
|
var GM_MONITOR_SECRET = 'bc33c837395b6dc272fd67f4cf38ef77';
|
||||||
|
var GM_MONITOR_SERVER_URL = 'ws://172.16.4.147:9092';
|
||||||
|
// game-server 数据库配置文件
|
||||||
|
var GAME_SERVER_DATABASE_FILE = '../game-server/config/database.ts';
|
||||||
|
// game-server master 配置文件
|
||||||
|
var GAME_SERVER_MASTER_FILE = '../game-server/config/master.ts';
|
||||||
|
// game-server app.ts
|
||||||
|
var GAME_SERVER_APP_FILE = '../game-server/app.ts';
|
||||||
|
// game-server pm2Config.js
|
||||||
|
var GAME_SERVER_PM2_FILE = '../game-server/pm2Config.js';
|
||||||
|
// game-server pm2DistributeConfig.js
|
||||||
|
var GAME_SERVER_PM2_DISTRIBUTE_FILE = '../game-server/pm2DistributeConfig.js';
|
||||||
|
// game-server log4js 配置文件
|
||||||
|
var GAME_SERVER_LOG4JS_PATH = '../game-server/config/';
|
||||||
|
// game-server log4js 模板文件
|
||||||
|
var GAME_SERVER_LOG4JS_TEMPLATE_FILE = './log4jsTemplate.ts';
|
||||||
|
// easy-monitor 配置文件
|
||||||
|
var EASY_MONITOR_PATH = '../game-server/xtransitConfig/';
|
||||||
|
// easy-monitor 配置文件模板
|
||||||
|
var EASY_MONITOR_TEMPLATE_FILE = './easyMonitorTemplate.js';
|
||||||
|
// web-server 配置路径
|
||||||
|
var WEB_SERVER_PATH = '../web-server/config/';
|
||||||
|
// web-server 配置模板
|
||||||
|
var WEB_SERVER_TEMPLATE_FILE = './webServerTemplate.ts';
|
||||||
|
// gm-server 配置路径
|
||||||
|
var GM_SERVER_PATH = '../gm-server/config/';
|
||||||
|
// gm-server 配置模板
|
||||||
|
var GM_SERVER_TEMPLATE_FILE = './gmServerTemplate.ts';
|
||||||
|
// const masterData = require(GAME_SERVER_MASTER_FILE);
|
||||||
|
var databaseData = require(GAME_SERVER_DATABASE_FILE);
|
||||||
|
function updateDatabase() {
|
||||||
|
databaseData[ENV] = {
|
||||||
|
'mongo': MONGO_URL,
|
||||||
|
'mongoSub': SUB_MONGO_URL,
|
||||||
|
'gmmongo': GM_MONGO_URL,
|
||||||
|
'redis': REDIS_URL,
|
||||||
|
'redispw': REDIS_PASS,
|
||||||
|
'redisLock': REDLOCK_URL,
|
||||||
|
'redisLockpw': REDLOCK_PASS
|
||||||
|
};
|
||||||
|
fs.writeFileSync(path.join(__dirname, GAME_SERVER_DATABASE_FILE), "module.exports = " + JSON.stringify(databaseData, null, 4));
|
||||||
|
}
|
||||||
|
function modFile(filePath, reg, content) {
|
||||||
|
var fileContent = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
fileContent = fileContent.replace(reg, content);
|
||||||
|
fs.writeFileSync(filePath, fileContent);
|
||||||
|
}
|
||||||
|
function setupGameApp() {
|
||||||
|
var reg = /(const ALL_ENVS = '.*)(?=';)/;
|
||||||
|
modFile(path.join(__dirname, GAME_SERVER_APP_FILE), reg, "$1|" + ENV);
|
||||||
|
}
|
||||||
|
function setupPm2Config() {
|
||||||
|
var reg = /(let onairEnvs = \[.*)(?=])/;
|
||||||
|
modFile(path.join(__dirname, GAME_SERVER_PM2_FILE), reg, "$1, '" + ENV + "'");
|
||||||
|
modFile(path.join(__dirname, GAME_SERVER_PM2_DISTRIBUTE_FILE), reg, "$1, '" + ENV + "'");
|
||||||
|
}
|
||||||
|
function setupLog4jsConfig() {
|
||||||
|
var envPath = path.join(__dirname, GAME_SERVER_LOG4JS_PATH, ENV);
|
||||||
|
// 创建目录
|
||||||
|
if (!fs.existsSync(envPath)) {
|
||||||
|
fs.mkdirSync(envPath);
|
||||||
|
}
|
||||||
|
// 直接将模板文件复制到目标文件
|
||||||
|
fs.copyFileSync(path.join(__dirname, GAME_SERVER_LOG4JS_TEMPLATE_FILE), envPath + "/log4js.ts");
|
||||||
|
}
|
||||||
|
function setupEasyMonitorConfig() {
|
||||||
|
var configPath = path.join(__dirname, EASY_MONITOR_PATH, ENV + ".js");
|
||||||
|
// 直接将模板文件复制到目标文件
|
||||||
|
fs.copyFileSync(path.join(__dirname, EASY_MONITOR_TEMPLATE_FILE), configPath);
|
||||||
|
// 修改配置文件
|
||||||
|
var serverUrlReg = /MONITOR_SERVER_URL/;
|
||||||
|
modFile(configPath, serverUrlReg, "" + MONITOR_SERVER_URL);
|
||||||
|
var secretReg = /MONITOR_SECRET/;
|
||||||
|
modFile(configPath, secretReg, "" + MONITOR_SECRET);
|
||||||
|
var idReg = /'MONITOR_ID'/;
|
||||||
|
modFile(configPath, idReg, "" + MONITOR_ID);
|
||||||
|
}
|
||||||
|
function setupWebConfig() {
|
||||||
|
var configPath = path.join(__dirname, WEB_SERVER_PATH, "config." + ENV + ".ts");
|
||||||
|
// 直接将模板文件复制到目标文件
|
||||||
|
fs.copyFileSync(path.join(__dirname, WEB_SERVER_TEMPLATE_FILE), configPath);
|
||||||
|
// 修改配置文件
|
||||||
|
var serverUrlReg = /WEB_MONITOR_SERVER_URL/;
|
||||||
|
modFile(configPath, serverUrlReg, "" + WEB_MONITOR_SERVER_URL);
|
||||||
|
var secretReg = /WEB_MONITOR_SECRET/;
|
||||||
|
modFile(configPath, secretReg, "" + WEB_MONITOR_SECRET);
|
||||||
|
var idReg = /'WEB_MONITOR_ID'/;
|
||||||
|
modFile(configPath, idReg, "" + WEB_MONITOR_ID);
|
||||||
|
var mongoReg = /MONGO_URL/;
|
||||||
|
modFile(configPath, mongoReg, "" + MONGO_URL);
|
||||||
|
var gmMongoReg = /GM_MONGO_URL/;
|
||||||
|
modFile(configPath, gmMongoReg, "" + GM_MONGO_URL);
|
||||||
|
var redisReg = /REDIS_URL/;
|
||||||
|
modFile(configPath, redisReg, "" + REDIS_URL);
|
||||||
|
var redisPassReg = /REDIS_PASS/;
|
||||||
|
modFile(configPath, redisPassReg, "" + REDIS_PASS);
|
||||||
|
}
|
||||||
|
function setupGmConfig() {
|
||||||
|
var configPath = path.join(__dirname, GM_SERVER_PATH, "config." + ENV + ".ts");
|
||||||
|
// 直接将模板文件复制到目标文件
|
||||||
|
fs.copyFileSync(path.join(__dirname, GM_SERVER_TEMPLATE_FILE), configPath);
|
||||||
|
// 修改配置文件
|
||||||
|
var serverUrlReg = /GM_MONITOR_SERVER_URL/;
|
||||||
|
modFile(configPath, serverUrlReg, "" + GM_MONITOR_SERVER_URL);
|
||||||
|
var secretReg = /GM_MONITOR_SECRET/;
|
||||||
|
modFile(configPath, secretReg, "" + GM_MONITOR_SECRET);
|
||||||
|
var idReg = /'GM_MONITOR_ID'/;
|
||||||
|
modFile(configPath, idReg, "" + GM_MONITOR_ID);
|
||||||
|
var mongoReg = /MONGO_URL/;
|
||||||
|
modFile(configPath, mongoReg, "" + MONGO_URL);
|
||||||
|
var gmMongoReg = /GM_MONGO_URL/;
|
||||||
|
modFile(configPath, gmMongoReg, "" + GM_MONGO_URL);
|
||||||
|
var redisReg = /REDIS_URL/;
|
||||||
|
modFile(configPath, redisReg, "" + REDIS_URL);
|
||||||
|
var redisPassReg = /REDIS_PASS/;
|
||||||
|
modFile(configPath, redisPassReg, "" + REDIS_PASS);
|
||||||
|
}
|
||||||
|
// setupGameApp();
|
||||||
|
// setupPm2Config();
|
||||||
|
// setupLog4jsConfig();
|
||||||
|
setupEasyMonitorConfig();
|
||||||
|
setupWebConfig();
|
||||||
|
setupGmConfig();
|
||||||
185
scripts/newServerConfig.ts
Normal file
185
scripts/newServerConfig.ts
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
// 新建大区的部分配置脚本
|
||||||
|
// ! servers 和 master 使用单独脚本半自动配置,不在此文件配置范围内
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// 新大区 env
|
||||||
|
const ENV = 'ch1';
|
||||||
|
// 新大区数据库配置
|
||||||
|
const MONGO_URL = 'mongodb://yjzDbOp:yjz2023ZyDB@dds-8vb6c08497bde7141.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb6c08497bde7142.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb6c08497bde7143.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb6c08497bde7144.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-516005505';
|
||||||
|
const SUB_MONGO_URL = 'mongodb://yjzDbOp:yjz2023ZyDB@dds-8vbc6a169e1dd6941.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6942.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6943.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbc6a169e1dd6944.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-516005504';
|
||||||
|
const GM_MONGO_URL = 'mongodb://yjzGmDbOp:yjz2023ZyGmDB@dds-8vbdf8c89bbdbd241.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbdf8c89bbdbd242.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbdf8c89bbdbd243.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vbdf8c89bbdbd244.mongodb.zhangbei.rds.aliyuncs.com:3717/zyzgm?replicaSet=mgset-515829436';
|
||||||
|
// 新大区redis配置
|
||||||
|
const REDIS_URL = 'r-8vbqgdc3h9ac77fdvi.redis.zhangbei.rds.aliyuncs.com';
|
||||||
|
const REDIS_PASS = 'hWCJ$HDajm9SN&&Z';
|
||||||
|
const REDLOCK_URL = 'r-8vbiuvng869tbuynxn.redis.zhangbei.rds.aliyuncs.com';
|
||||||
|
const REDLOCK_PASS = 'hWCJ$HDajm9SN&&Z';
|
||||||
|
// 新大区game监控配置
|
||||||
|
const MONITOR_ID = 4;
|
||||||
|
const MONITOR_SECRET = '20cdf62e8ab0f3a751e7a5f7a0abbd33';
|
||||||
|
const MONITOR_SERVER_URL = 'ws://172.16.4.147:9092';
|
||||||
|
// 新大区web监控配置
|
||||||
|
const WEB_MONITOR_ID = 5;
|
||||||
|
const WEB_MONITOR_SECRET = '1c85221722efa1daec1097cd802ac939';
|
||||||
|
const WEB_MONITOR_SERVER_URL = 'ws://172.16.4.147:9092';
|
||||||
|
// 新大区gm监控配置
|
||||||
|
const GM_MONITOR_ID = 3;
|
||||||
|
const GM_MONITOR_SECRET = 'bc33c837395b6dc272fd67f4cf38ef77';
|
||||||
|
const GM_MONITOR_SERVER_URL = 'ws://172.16.4.147:9092';
|
||||||
|
|
||||||
|
|
||||||
|
// game-server 数据库配置文件
|
||||||
|
const GAME_SERVER_DATABASE_FILE = '../game-server/config/database.ts';
|
||||||
|
// game-server master 配置文件
|
||||||
|
const GAME_SERVER_MASTER_FILE = '../game-server/config/master.ts';
|
||||||
|
// game-server app.ts
|
||||||
|
const GAME_SERVER_APP_FILE = '../game-server/app.ts';
|
||||||
|
// game-server pm2Config.js
|
||||||
|
const GAME_SERVER_PM2_FILE = '../game-server/pm2Config.js';
|
||||||
|
// game-server pm2DistributeConfig.js
|
||||||
|
const GAME_SERVER_PM2_DISTRIBUTE_FILE = '../game-server/pm2DistributeConfig.js';
|
||||||
|
|
||||||
|
// game-server log4js 配置文件
|
||||||
|
const GAME_SERVER_LOG4JS_PATH = '../game-server/config/';
|
||||||
|
// game-server log4js 模板文件
|
||||||
|
const GAME_SERVER_LOG4JS_TEMPLATE_FILE = './log4jsTemplate.ts';
|
||||||
|
|
||||||
|
// easy-monitor 配置文件
|
||||||
|
const EASY_MONITOR_PATH = '../game-server/xtransitConfig/';
|
||||||
|
// easy-monitor 配置文件模板
|
||||||
|
const EASY_MONITOR_TEMPLATE_FILE = './easyMonitorTemplate.js';
|
||||||
|
|
||||||
|
// web-server 配置路径
|
||||||
|
const WEB_SERVER_PATH = '../web-server/config/';
|
||||||
|
// web-server 配置模板
|
||||||
|
const WEB_SERVER_TEMPLATE_FILE = './webServerTemplate.ts';
|
||||||
|
|
||||||
|
// gm-server 配置路径
|
||||||
|
const GM_SERVER_PATH = '../gm-server/config/';
|
||||||
|
// gm-server 配置模板
|
||||||
|
const GM_SERVER_TEMPLATE_FILE = './gmServerTemplate.ts';
|
||||||
|
|
||||||
|
// const masterData = require(GAME_SERVER_MASTER_FILE);
|
||||||
|
const databaseData = require(GAME_SERVER_DATABASE_FILE);
|
||||||
|
|
||||||
|
function updateDatabase () {
|
||||||
|
databaseData[ENV] = {
|
||||||
|
'mongo': MONGO_URL,
|
||||||
|
'mongoSub': SUB_MONGO_URL,
|
||||||
|
'gmmongo': GM_MONGO_URL,
|
||||||
|
'redis': REDIS_URL,
|
||||||
|
'redispw': REDIS_PASS,
|
||||||
|
'redisLock': REDLOCK_URL,
|
||||||
|
'redisLockpw': REDLOCK_PASS,
|
||||||
|
};
|
||||||
|
fs.writeFileSync(path.join(__dirname, GAME_SERVER_DATABASE_FILE), `module.exports = ${JSON.stringify(databaseData, null, 4)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function modFile(filePath: string, reg: RegExp, content: string) {
|
||||||
|
let fileContent = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
fileContent = fileContent.replace(reg, content);
|
||||||
|
fs.writeFileSync(filePath, fileContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupGameApp() {
|
||||||
|
const reg: RegExp = /(const ALL_ENVS = '.*)(?=';)/;
|
||||||
|
modFile(path.join(__dirname, GAME_SERVER_APP_FILE), reg, `$1|${ENV}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupPm2Config() {
|
||||||
|
const reg: RegExp = /(let onairEnvs = \[.*)(?=])/;
|
||||||
|
modFile(path.join(__dirname, GAME_SERVER_PM2_FILE), reg, `$1, '${ENV}'`);
|
||||||
|
modFile(path.join(__dirname, GAME_SERVER_PM2_DISTRIBUTE_FILE), reg, `$1, '${ENV}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupLog4jsConfig() {
|
||||||
|
const envPath = path.join(__dirname, GAME_SERVER_LOG4JS_PATH, ENV);
|
||||||
|
// 创建目录
|
||||||
|
if (!fs.existsSync(envPath)) {
|
||||||
|
fs.mkdirSync(envPath);
|
||||||
|
}
|
||||||
|
// 直接将模板文件复制到目标文件
|
||||||
|
fs.copyFileSync(path.join(__dirname, GAME_SERVER_LOG4JS_TEMPLATE_FILE), `${envPath}/log4js.ts`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupEasyMonitorConfig() {
|
||||||
|
const configPath = path.join(__dirname, EASY_MONITOR_PATH, `${ENV}.js`);
|
||||||
|
// 直接将模板文件复制到目标文件
|
||||||
|
fs.copyFileSync(path.join(__dirname, EASY_MONITOR_TEMPLATE_FILE), configPath);
|
||||||
|
// 修改配置文件
|
||||||
|
let serverUrlReg: RegExp = /MONITOR_SERVER_URL/;
|
||||||
|
modFile(configPath, serverUrlReg, `${MONITOR_SERVER_URL}`);
|
||||||
|
|
||||||
|
let secretReg: RegExp = /MONITOR_SECRET/;
|
||||||
|
modFile(configPath, secretReg, `${MONITOR_SECRET}`);
|
||||||
|
|
||||||
|
let idReg: RegExp = /'MONITOR_ID'/;
|
||||||
|
modFile(configPath, idReg, `${MONITOR_ID}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupWebConfig() {
|
||||||
|
const configPath = path.join(__dirname, WEB_SERVER_PATH, `config.${ENV}.ts`);
|
||||||
|
// 直接将模板文件复制到目标文件
|
||||||
|
fs.copyFileSync(path.join(__dirname, WEB_SERVER_TEMPLATE_FILE), configPath);
|
||||||
|
|
||||||
|
// 修改配置文件
|
||||||
|
let serverUrlReg: RegExp = /WEB_MONITOR_SERVER_URL/;
|
||||||
|
modFile(configPath, serverUrlReg, `${WEB_MONITOR_SERVER_URL}`);
|
||||||
|
|
||||||
|
let secretReg: RegExp = /WEB_MONITOR_SECRET/;
|
||||||
|
modFile(configPath, secretReg, `${WEB_MONITOR_SECRET}`);
|
||||||
|
|
||||||
|
let idReg: RegExp = /'WEB_MONITOR_ID'/;
|
||||||
|
modFile(configPath, idReg, `${WEB_MONITOR_ID}`);
|
||||||
|
|
||||||
|
let mongoReg: RegExp = /MONGO_URL/;
|
||||||
|
modFile(configPath, mongoReg, `${MONGO_URL}`);
|
||||||
|
|
||||||
|
let gmMongoReg: RegExp = /GM_MONGO_URL/;
|
||||||
|
modFile(configPath, gmMongoReg, `${GM_MONGO_URL}`);
|
||||||
|
|
||||||
|
let redisReg: RegExp = /REDIS_URL/;
|
||||||
|
modFile(configPath, redisReg, `${REDIS_URL}`);
|
||||||
|
|
||||||
|
let redisPassReg: RegExp = /REDIS_PASS/;
|
||||||
|
modFile(configPath, redisPassReg, `${REDIS_PASS}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupGmConfig() {
|
||||||
|
const configPath = path.join(__dirname, GM_SERVER_PATH, `config.${ENV}.ts`);
|
||||||
|
// 直接将模板文件复制到目标文件
|
||||||
|
fs.copyFileSync(path.join(__dirname, GM_SERVER_TEMPLATE_FILE), configPath);
|
||||||
|
|
||||||
|
// 修改配置文件
|
||||||
|
let serverUrlReg: RegExp = /GM_MONITOR_SERVER_URL/;
|
||||||
|
modFile(configPath, serverUrlReg, `${GM_MONITOR_SERVER_URL}`);
|
||||||
|
|
||||||
|
let secretReg: RegExp = /GM_MONITOR_SECRET/;
|
||||||
|
modFile(configPath, secretReg, `${GM_MONITOR_SECRET}`);
|
||||||
|
|
||||||
|
let idReg: RegExp = /'GM_MONITOR_ID'/;
|
||||||
|
modFile(configPath, idReg, `${GM_MONITOR_ID}`);
|
||||||
|
|
||||||
|
let mongoReg: RegExp = /MONGO_URL/;
|
||||||
|
modFile(configPath, mongoReg, `${MONGO_URL}`);
|
||||||
|
|
||||||
|
let gmMongoReg: RegExp = /GM_MONGO_URL/;
|
||||||
|
modFile(configPath, gmMongoReg, `${GM_MONGO_URL}`);
|
||||||
|
|
||||||
|
let redisReg: RegExp = /REDIS_URL/;
|
||||||
|
modFile(configPath, redisReg, `${REDIS_URL}`);
|
||||||
|
|
||||||
|
let redisPassReg: RegExp = /REDIS_PASS/;
|
||||||
|
modFile(configPath, redisPassReg, `${REDIS_PASS}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// setupGameApp();
|
||||||
|
// setupPm2Config();
|
||||||
|
// setupLog4jsConfig();
|
||||||
|
// setupEasyMonitorConfig();
|
||||||
|
// setupWebConfig();
|
||||||
|
// setupGmConfig();
|
||||||
51
scripts/webServerTemplate.ts
Normal file
51
scripts/webServerTemplate.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
|
||||||
|
import defaultConfig from './config.default';
|
||||||
|
|
||||||
|
export default (appInfo: EggAppInfo) => {
|
||||||
|
const config = {} as PowerPartial<EggAppConfig>;
|
||||||
|
config.middleware = [ 'parmsDecode', 'getIp', 'proxy' ];
|
||||||
|
|
||||||
|
config.mongoose = {
|
||||||
|
url: 'MONGO_URL', // 内网
|
||||||
|
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
config.gmmongoose = {
|
||||||
|
url: 'GM_MONGO_URL', // 内网
|
||||||
|
options: { useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
|
};
|
||||||
|
|
||||||
|
config.redis = {
|
||||||
|
url: 'REDIS_URL', // 内网
|
||||||
|
pw: 'REDIS_PASS'
|
||||||
|
};
|
||||||
|
|
||||||
|
config.xtransit = {
|
||||||
|
server: 'WEB_MONITOR_SERVER_URL',
|
||||||
|
appId: 'WEB_MONITOR_ID',
|
||||||
|
appSecret: 'WEB_MONITOR_SECRET'
|
||||||
|
};
|
||||||
|
|
||||||
|
config.customLogger = {
|
||||||
|
linkLogger: {
|
||||||
|
file: '/zyz_logs/web-server/link-log.log',
|
||||||
|
formatter(meta) {
|
||||||
|
return `[${meta.level}] [${meta.date}] ${meta.message}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
config.logrotator = {
|
||||||
|
filesRotateBySize: [
|
||||||
|
'/zyz_logs/web-server/link-log.log',
|
||||||
|
],
|
||||||
|
maxFileSize: 1024 * 1024 * 1024,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// the return config will combines to EggAppConfig
|
||||||
|
return {
|
||||||
|
...defaultConfig(appInfo),
|
||||||
|
...config
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user