AS应用服务器
硬件环境:
CPU:四核 3.2GHz X 2
内存:DDR3 1600 8G
磁盘空间:1TB
网卡:千兆口双网卡
系统环境:
Centos6.5
JDK
Nodjs
Pomelo
IP: AS-1:10.0.0.1/16
AS-2:10.0.0.2/16
AS-3:10.0.0.3/16
Redis DB:10.0.0.5/16
Mysql DB:10.0.0.6/16
一、架构图
二、部署步骤
注意事项:
<!--[if !supportLists]-->1、 <!--[endif]-->必须为同类操作系统(建议为完全相同的操作系统, 本文所示例的3台机器的操作系统均为"Centos6.5").
<!--[if !supportLists]-->2、 <!--[endif]-->必须都有一个同名的用户(如:"pomelo"等, 本文所示例的3台机器均有一个名为"pomelo"的用户).
<!--[if !supportLists]-->3、 <!--[endif]-->Node.js的安装版本必须完全相同, 安装的绝对路径也必须完全相同
<!--[if !supportLists]-->4、 <!--[endif]-->项目所放置的绝对路径也必须完全相同(本文所示例的绝对路径为"/home/pomelo_ij100_as").
步骤:
1、在AS-1、AS-2、AS-3配置SSH
在AS-1、AS-2、AS-新增用户pomelo
Useradd pomelo Passwd pomelo |
在AS-1、AS-2、AS-3配置用户ssh权限
vim /home/pomelo/.ssh/config |
|
打开AS-1、AS-2、AS-3 的SSH-RSA认证、公钥认证,指定认证文件地址
Vim /etc/ssh/sshd_config |
RSAAuthentication yes |
在AS-1、AS-2、AS-3上生成秘钥对
su pomelo ssh-keygen |
将AS-1的公钥添加到AS-2、AS-3 Authorized 文件中
ssh-copy-id –i /home/pomelo/.ssh/id_rsa.pub [email protected] ssh-copy-id –i /home/pomelo/.ssh/id_rsa.pub [email protected] |
将AS-2公钥添加到AS-1、AS-3
将AS-3公钥添加到AS-1、AS-2
将AS-1、AS-2、AS-3 /home/pomelo/.ssh文件权限修改为700
su root cd /home/pomelo chmod 700 .ssh |
重启sshd服务
service sshd restart |
2、在AS-1、AS-2、AS-3上安装python(2.5<version<3.0)、gcc、gcc-c++ 、nodejs、pomelo
yum install gcc gcc-c++ wget http://www.npmjs.org/install.sh chmod +x ./install.sh ./install.sh #安装pomelo git clone https://github.com/NetEase/pomelo.git cd pomelo npm install -g |
3、修改master.json
{
"development":{ "id":"master-server-1","host":"10.0.0.1","port":3005 },
"production": {
"id":"master-server-1","host":"10.0.0.1","port":3005 }
}
|
4、修改servers.json
vim /opt/pomelo_ij100_as/game-server/config/servers.json
{ "development":{ "connector": [ {"id": "connector-server-1", "host": "10.0.0.1", "port": 3140, "clientPort": 3010, "frontend": true}, {"id": "connector-server-2", "host": "10.0.0.1", "port": 3141, "clientPort": 3011, "frontend": true}, {"id": "connector-server-3", "host": "10.0.0.1", "port": 3142, "clientPort": 3012, "frontend": true}, {"id": "connector-server-4", "host": "10.0.0.1", "port": 3143, "clientPort": 3013, "frontend": true}, {"id": "connector-server-5", "host": "10.0.0.2", "port": 3140, "clientPort": 3010, "frontend": true}, {"id": "connector-server-6", "host": "10.0.0.2", "port": 3141, "clientPort": 3011, "frontend": true}, {"id": "connector-server-7", "host": "10.0.0.2", "port": 3142, "clientPort": 3012, "frontend": true}, {"id": "connector-server-8", "host": "10.0.0.2", "port": 3143, "clientPort": 3013, "frontend": true}, {"id": "connector-server-9", "host": "10.0.0.3", "port": 3140, "clientPort": 3010, "frontend": true}, {"id": "connector-server-10", "host": "10.0.0.3", "port": 3141, "clientPort": 3011, "frontend": true}, {"id": "connector-server-11", "host": "10.0.0.3", "port": 3142, "clientPort": 3012, "frontend": true}, {"id": "connector-server-12", "host": "10.0.0.3", "port": 3143, "clientPort": 3013, "frontend": true} ], "termApi": [ {"id": "termApi-server-1", "host": "10.0.0.1", "port": 3150 ,"args" : " --debug=12345"}, {"id": "termApi-server-2", "host": "10.0.0.1", "port": 3151}, {"id": "termApi-server-3", "host": "10.0.0.2", "port": 3150 ,"args" : " --debug=12345"}, {"id": "termApi-server-4", "host": "10.0.0.2", "port": 3151}, {"id": "termApi-server-5", "host": "10.0.0.3", "port": 3150 ,"args" : " --debug=12345"}, {"id": "termApi-server-6", "host": "10.0.0.3", "port": 3151} ], "userApi": [ {"id": "userApi-server-1", "host": "10.0.0.1", "port": 3160}, {"id": "userApi-server-2", "host": "10.0.0.1", "port": 3161}, {"id": "userApi-server-3", "host": "10.0.0.2", "port": 3160}, {"id": "userApi-server-4", "host": "10.0.0.2", "port": 3161}, {"id": "userApi-server-5", "host": "10.0.0.3", "port": 3160}, {"id": "userApi-server-6", "host": "10.0.0.3", "port": 3161} ], "baseDataApi": [ {"id": "baseDataApi-server-1", "host": "10.0.0.1", "port": 3170}, {"id": "baseDataApi-server-2", "host": "10.0.0.1", "port": 3171}, {"id": "baseDataApi-server-3", "host": "10.0.0.2", "port": 3170}, {"id": "baseDataApi-server-4", "host": "10.0.0.2", "port": 3171}, {"id": "baseDataApi-server-5", "host": "10.0.0.3", "port": 3170}, {"id": "baseDataApi-server-6", "host": "10.0.0.3", "port": 3171} ], "paymentApi": [ {"id": "paymentApi-server-1", "host": "10.0.0.1", "port": 3180}, {"id": "paymentApi-server-2", "host": "10.0.0.1", "port": 3181}, {"id": "paymentApi-server-3", "host": "10.0.0.2", "port": 3180}, {"id": "paymentApi-server-4", "host": "10.0.0.2", "port": 3181}, {"id": "paymentApi-server-5", "host": "10.0.0.3", "port": 3180}, {"id": "paymentApi-server-6", "host": "10.0.0.3", "port": 3181} ], "appApi": [ {"id": "appApi-server-1", "host": "10.0.0.1", "port": 3190}, {"id": "appApi-server-2", "host": "10.0.0.1", "port": 3191}, {"id": "appApi-server-3", "host": "10.0.0.2", "port": 3190}, {"id": "appApi-server-4", "host": "10.0.0.2", "port": 3191}, {"id": "appApi-server-5", "host": "10.0.0.3", "port": 3190}, {"id": "appApi-server-6", "host": "10.0.0.3", "port": 3191} ], "scheduler": [ {"id": "scheduler-server-1", "host": "10.0.0.1", "port": 3200}, {"id": "messagePush-server-1", "host": "10.0.0.1", "port": 3201}, {"id": "scheduler-server-2", "host": "10.0.0.2", "port": 3200}, {"id": "messagePush-server-2", "host": "10.0.0.2", "port": 3201}, {"id": "scheduler-server-3", "host": "10.0.0.3", "port": 3200}, {"id": "messagePush-server-3", "host": "10.0.0.3", "port": 3201} ], "appMarketApi": [ {"id": "appMarketApi-server-1", "host": "10.0.0.1", "port": 3210}, {"id": "appMarketApi-server-2", "host": "10.0.0.1", "port": 3211}, {"id": "appMarketApi-server-3", "host": "10.0.0.2", "port": 3210}, {"id": "appMarketApi-server-4", "host": "10.0.0.2", "port": 3211}, {"id": "appMarketApi-server-5", "host": "10.0.0.3", "port": 3210}, {"id": "appMarketApi-server-6", "host": "10.0.0.3", "port": 3211} ] }, "production":{ "connector": [ {"id": "connector-server-1", "host": "10.0.0.1", "port": 3140, "clientPort": 3010, "frontend": true}, {"id": "connector-server-2", "host": "10.0.0.1", "port": 3141, "clientPort": 3011, "frontend": true}, {"id": "connector-server-3", "host": "10.0.0.1", "port": 3142, "clientPort": 3012, "frontend": true}, {"id": "connector-server-4", "host": "10.0.0.1", "port": 3143, "clientPort": 3013, "frontend": true}, {"id": "connector-server-5", "host": "10.0.0.2", "port": 3140, "clientPort": 3010, "frontend": true}, {"id": "connector-server-6", "host": "10.0.0.2", "port": 3141, "clientPort": 3011, "frontend": true}, {"id": "connector-server-7", "host": "10.0.0.2", "port": 3142, "clientPort": 3012, "frontend": true}, {"id": "connector-server-8", "host": "10.0.0.2", "port": 3143, "clientPort": 3013, "frontend": true}, {"id": "connector-server-9", "host": "10.0.0.3", "port": 3140, "clientPort": 3010, "frontend": true}, {"id": "connector-server-10", "host": "10.0.0.3", "port": 3141, "clientPort": 3011, "frontend": true}, {"id": "connector-server-11", "host": "10.0.0.3", "port": 3142, "clientPort": 3012, "frontend": true}, {"id": "connector-server-12", "host": "10.0.0.3", "port": 3143, "clientPort": 3013, "frontend": true} ], "termApi": [ {"id": "termApi-server-1", "host": "10.0.0.1", "port": 3150 ,"args" : " --debug=12345"}, {"id": "termApi-server-2", "host": "10.0.0.1", "port": 3151}, {"id": "termApi-server-3", "host": "10.0.0.2", "port": 3150 ,"args" : " --debug=12345"}, {"id": "termApi-server-4", "host": "10.0.0.2", "port": 3151}, {"id": "termApi-server-5", "host": "10.0.0.3", "port": 3150 ,"args" : " --debug=12345"}, {"id": "termApi-server-6", "host": "10.0.0.3", "port": 3151} ], "userApi": [ {"id": "userApi-server-1", "host": "10.0.0.1", "port": 3160}, {"id": "userApi-server-2", "host": "10.0.0.1", "port": 3161}, {"id": "userApi-server-3", "host": "10.0.0.2", "port": 3160}, {"id": "userApi-server-4", "host": "10.0.0.2", "port": 3161}, {"id": "userApi-server-5", "host": "10.0.0.3", "port": 3160}, {"id": "userApi-server-6", "host": "10.0.0.3", "port": 3161} ], "baseDataApi": [ {"id": "baseDataApi-server-1", "host": "10.0.0.1", "port": 3170}, {"id": "baseDataApi-server-2", "host": "10.0.0.1", "port": 3171}, {"id": "baseDataApi-server-3", "host": "10.0.0.2", "port": 3170}, {"id": "baseDataApi-server-4", "host": "10.0.0.2", "port": 3171}, {"id": "baseDataApi-server-5", "host": "10.0.0.3", "port": 3170}, {"id": "baseDataApi-server-6", "host": "10.0.0.3", "port": 3171} ], "paymentApi": [ {"id": "paymentApi-server-1", "host": "10.0.0.1", "port": 3180}, {"id": "paymentApi-server-2", "host": "10.0.0.1", "port": 3181}, {"id": "paymentApi-server-3", "host": "10.0.0.2", "port": 3180}, {"id": "paymentApi-server-4", "host": "10.0.0.2", "port": 3181}, {"id": "paymentApi-server-5", "host": "10.0.0.3", "port": 3180}, {"id": "paymentApi-server-6", "host": "10.0.0.3", "port": 3181} ], "appApi": [ {"id": "appApi-server-1", "host": "10.0.0.1", "port": 3190}, {"id": "appApi-server-2", "host": "10.0.0.1", "port": 3191}, {"id": "appApi-server-3", "host": "10.0.0.2", "port": 3190}, {"id": "appApi-server-4", "host": "10.0.0.2", "port": 3191}, {"id": "appApi-server-5", "host": "10.0.0.3", "port": 3190}, {"id": "appApi-server-6", "host": "10.0.0.3", "port": 3191} ], "scheduler": [ {"id": "scheduler-server-1", "host": "10.0.0.1", "port": 3200}, {"id": "messagePush-server-1", "host": "10.0.0.1", "port": 3201}, {"id": "scheduler-server-2", "host": "10.0.0.2", "port": 3200}, {"id": "messagePush-server-2", "host": "10.0.0.2", "port": 3201}, {"id": "scheduler-server-3", "host": "10.0.0.3", "port": 3200}, {"id": "messagePush-server-3", "host": "10.0.0.3", "port": 3201} ], "appMarketApi": [ {"id": "appMarketApi-server-1", "host": "10.0.0.1", "port": 3210}, {"id": "appMarketApi-server-2", "host": "10.0.0.1", "port": 3211}, {"id": "appMarketApi-server-3", "host": "10.0.0.2", "port": 3210}, {"id": "appMarketApi-server-4", "host": "10.0.0.2", "port": 3211}, {"id": "appMarketApi-server-5", "host": "10.0.0.3", "port": 3210}, {"id": "appMarketApi-server-6", "host": "10.0.0.3", "port": 3211} ] } } |
5、修改redis地址
vim /opt/pomelo_ij100_as/game-server/config/redis.json |
{ "development": { "host" : "10.0.0.6", "port" : "6379", "password" : 321 },
"production": { "host" : "10.0.0.6", "port" : "6379", "password" : 321 } } |
vim /opt/pomelo_ij100_as/game-server/config/app.js |
var pomelo = require('pomelo'); var pomeloLog = require('pomelo-logger') var globalChannel = require('pomelo-globalchannel-plugin'); var user= require('pomelo-user-plugin'); var machine= require('pomelo-machine-plugin'); var appInfo= require('pomelo-appinfo-plugin'); var mysqlCreator = require('./app/dao/database/mysql'); var redisCreator = require('./app/dao/database/redis'); var httpCreator = require('./app/dao/database/http'); var routeUtils = require('./app/util/routeUtils'); var SystemConfig = require('./config/systemConfig');
/** * Init app for client. */ var app = pomelo.createApp(); app.set('name', 'pomelo_ij100_as'); app.loadConfig('mysql', app.getBase() + '/config/mysql.json'); app.loadConfig('redis', app.getBase() + '/config/redis.json');
//配置日志 pomeloLog.configure(app.getBase() + '/config/log4js.json',{base: app.getBase()});
var encryptObjFilter = require('./app/filter/encryptObjFilter'); var connAuthFilter = require('./app/filter/connAuthFilter'); var timerFilter = require('./app/filter/timerFilter'); // app configuration app.configure('production|development', function(){ //数据库连接客户端 var dbclient = mysqlCreator.init(app); var cacheClient = redisCreator.init(app); var httpClient = httpCreator.init(app); app.set('dbclient', dbclient); app.set('cacheClient', cacheClient); app.set('httpClient', httpClient); app.set('pomeloLog', pomeloLog); app.route('userApi', routeUtils.userApi); app.route('termApi', routeUtils.termApi); app.route('baseDataApi', routeUtils.baseDataApi); app.route('paymentApi', routeUtils.paymentApi); app.route('scheduler', routeUtils.scheduler); app.before(connAuthFilter()); //app.before(encryptObjFilter()); app.filter(timerFilter()); app.set('proxyConfig', { timeout: 20 * 1000 //rpc超时时间 }); });
app.configure('production|development', 'connector', function(){ app.set('connectorConfig', { connector: pomelo.connectors.hybridconnector, disconnectOnTimeout: true, heartbeat: 30 //websocket心跳配置 //connector: pomelo.connectors.sioconnector, /* //socket.io心跳配置 transports: { 'close timeout': 30, 'heartbeat interval': 20, 'heartbeat timeout': 30 } */ }); }); app.configure('production|development', function() { app.enable('systemMonitor'); var userModule = require('./app/modules/userModule'); var machineModule = require('./app/modules/machineModule'); var appInfoModule = require('./app/modules/appInfoModule'); if(typeof app.registerAdmin === 'function'){ app.registerAdmin(userModule, {app: app}); app.registerAdmin(machineModule, {app: app}); app.registerAdmin(appInfoModule, {app: app}); } app.use(user, { user: { host: '10.0.0.5', port: 6379, password: 321 } }); app.use(machine, { machine: { host: '10.0.0.6', port: 6379, password: 321
} });
app.use(appInfo, { appInfo: { host: '10.0.0.6', port: 6379, password: 321 } }); app.use(globalChannel, {globalChannel: { host: '10.0.0.6', port: 6379, password: 321 }}); });
var logUtils = null; var log = null; var commonCache = null; // start app app.start(function() { if(!log || !logUtils) { logUtils = require('./app/util/logUtils'); log = logUtils.getLogger(__filename); }
var currentServerType = app.serverType; if(currentServerType == 'master') {//master启动完成 var machineService = app.get('machineService'); var userService = app.get('userService'); var globalChannelService = app.get('globalChannelService'); //清空在线设备 machineService.deleteMachineOnlineCount(); //清空在线用户 userService.deleteUserOnlineCount(); //清空globalChannel数据 /*if(commonCache == null) { commonCache = require('./app/dao/cache/commonCache'); } if(!!commonCache) { commonCache.deleteByPrefix('POMELO:CHANNEL:', function(err) { if(err) { if(!!log) { log.error('clear global channel error '); } else { console.error('clear global channel error '); } } else { if(!!log) { log.info('clear global channel success '); } else { console.info('clear global channel success '); } } }); }*/ } //初始化日志 mysqlCreator.initLog(); redisCreator.initLog(); httpCreator.initLog(); if(!log || !logUtils) { logUtils = require('./app/util/logUtils'); log = logUtils.getLogger(__filename); } //初始化即时拦截器 timerFilter().init(); }); process.on('uncaughtException', function (err) { if(!!log) { log.error(' uncaughtException exception: ' + err.stack); } else { console.error(' uncaughtException exception: ' + err.stack); } }); |
6、将项目所有人、属组改成pomelo并拷贝到AS-2、AS-3(路径必须一致)
cd /opt chown –R pomelo pomelo_ij100_as chgrp –R pomelo pomelo_ij100_as scp –r pomelo_ij100_as root@10.0.0.2:/opt scp –r pomelo_ij100_as root@10.0.0.3:/opt |
7、AS-1上安装Nginx(步骤略)
8、修改nginx负载均衡配置
upstream nodejs { #ip_hash; server 10.0.0.1:3010; server 10.0.0.1:3011; server 10.0.0.1:3012; server 10.0.0.1:3013; server 10.0.0.2:3010; server 10.0.0.2:3011; server 10.0.0.2:3012; server 10.0.0.2:3013; server 10.0.0.3:3010; server 10.0.0.3:3011; server 10.0.0.3:3012; server 10.0.0.3:3013; } |
9、启动pomelo