分布式部署pomelo
安装前环境:
master 192.168.10.123
slave 192.168.10.172
node 版本相同 v0.10.26
python 2.7.3 默认是2.6.6。需要升级
OS :Red Hat Enterprise Linux Server release 6.2 (Santiago)
service iptables stop
setenforce 0/disabled
绝对统路径:/opt/
相同用户 useradd pomelo
1、通过如下命令下载源代码的方式安装:
$ git clone https://github.com/NetEase/pomelo.git
$
cd pomelo
$ npm install -g
2、下载chat源码在github上面 -在此步骤期间,不要修改任何配置文件
$ git clone https://github.com/NetEase/chatofpomelo-websocket.git --chat源码包
$ cd game-server
$ git checkout tutorial-starter
多服务器版本的聊天应用在分支tutorial-multi-server
上,你需要执行如下命令来切换到多服务器分支上:
$ git checkout tutorial-multi-server
首先,确保你已经成功安装了pomelo。执行命令安装依赖:
$ sh npm-install.sh
启动游戏服务器:
$ cd game-server
$ npm install
$ pomelo start
启动web服务器:
$ cd web-server
$ npm insatll
$ node app.js
如果启动过程中没有问题的话,下面我们就可以使用我们的聊天服务了,打开浏览器
接下来修改配置文件
在我的博客中,我扩充了connector服务器作为前端集群,其余都是一台,所以,之需要增加connector即可~
接下来我先配置master服务器的配置文件、(生产环境)
cd /chatofpomelo/game-server/config
vim server.json
"development":{
"connector":[
{"id":"connector-server-1", "host":"127.0.0.1", "port":4050, "clientPort": 3050, "frontend": true}
],
"chat":[
{"id":"chat-server-1", "host":"127.0.0.1", "port":6050,"args":"--debug=31311"}
],
"gate":[
{"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true,"args":"--debug=32312"}
]
},
"production":{
"connector":[
{"id":"connector-server-1", "host":"192.168.10.123", "port":4050,"sshport" : 22, "clientPort": 3050, "frontend": true},
{"id":"connector-server-2", "host":"192.168.10.172", "port":4052,"sshport" : 22, "clientPort": 3052, "frontend": true}
],
"chat":[
{"id":"chat-server-1", "host":"x.x.x.x", "port":6050}
],
"gate":[
{"id": "gate-server-1", "host": "x.x.x.x", "clientPort": 3014, "frontend": true}
]
}
}
master.json
{
"development":{
"id":"master-server-1",
"host":"127.0.0.1",
"port":3005,
"queryPort":3015,
"wsPort":2337
},
"production":{
"id":"master-server-1",
"host":"192.168.10.123", --master机器的IP
"port":3005,
"queryPort":3015,
"wsPort":2337
}
}
salve 服务器的配置
vim server.json
"development":{
"connector":[
{"id":"connector-server-1", "host":"127.0.0.1", "port":4050, "clientPort": 3050, "frontend": true}
],
"chat":[
{"id":"chat-server-1", "host":"127.0.0.1", "port":6050,"args":"--debug=31311"}
],
"gate":[
{"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true,"args":"--debug=32312"}
]
},
"production":{
"connector":[
{"id":"connector-server-1", "host":"192.168.10.123", "port":4050, "sshport" : 22 ,"clientPort": 3050, "frontend": true},
{"id":"connector-server-2", "host":"192.168.10.172", "port":4052,"sshport":22, "clientPort": 3052, "frontend": true}
],
"chat":[
{"id":"chat-server-1", "host":"192.168.10.123", "port":6050}
],
"gate":[
{"id": "gate-server-1", "host": "192.168.10.123", "clientPort": 3014, "frontend": true}
]
}
}
master.json
{
"development":{
"id":"master-server-1",
"host":"127.0.0.1",
"port":3005,
"queryPort":3015,
"wsPort":2337
},
"production":{
"id":"master-server-1",
"host":"192.168.10.123", --master机器的IP
"port":3005,
"queryPort":3015,
"wsPort":2337
}
}
接下来开始ssh 登录配置:(pomelo用户身份进行操作)
rpm -qa | grep rsync
yum insatll openssh rsync
vi /etc/ssh/sshd_config
启用以下选项
service sshd restart
su - pomelo
cd ~
ssh-keygen -t rsa -直接回车
cd .ssh 假如没有此项,进行mkdir .ssh chmod 700
cat id_rsa.pub >> authorized_keys 我比较懒,同时接copy id_rsa.pub 到从slave服务器的对应路径
ssh localhost 如果拒绝,chmod 600 authorized_keys
ssh pomelo@192.168.10.73 (slave主机)
继续到slave主机进行以上操作,即可。
接下来,做最后打开ssh forward 通道
我是在root和pomelo下同时操作下面配置的
cd ~
vim .bashrc
------------------------------------------------------
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn隆炉t work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
---------------------------------------
source .bashrc
echo $SSH_AUTH_SOCK
进行验证~
ssh -A slave.com
ssh -A master.com
然后以pomelo 用户登录启动master
cd /game-server
记得启动redis
修改redis配置文件,改为redis(pomelo)服务器内网ip
bind x.x.x.x.
同时修改pomelo /config
record.jason
host 对应pomeo 内网ip
pomelo start --env --production --daemon
netstart -tnlp | grep node
在slave检测,看是否connector已启动
netstart -tnlp | grep node
本次记录暂时完毕~
--------------------------------------------
为了方便启动,便写脚本来方便运行
sh start.sh
#!/bin/bash
su - pomelo -c "cd /opt/ksd_chat"
pomelo start --env production --daemon
sleep 1
su - root -c "cd /opt/ksd_chat"
nohup node crossdomain.js &
sleep 4
ssh -n -q } 'cd /opt/ksd_chat nohup sh start-1.sh > /dev/null < /dev/null 2>&1 &'
sleep 1
netstat -tnlp | grep node
pomelo list
[root@master ksd_chat]# more start.sh
#!/bin/bash
su - pomelo -c "cd /opt/ksd_chat"
pomelo start --env production --daemon
sleep 1
su - root -c "cd /opt/ksd_chat"
nohup node crossdomain.js &
sleep 4
ssh -n -q } 'cd /opt/ksd_chat nohup sh start-1.sh > /dev/null < /dev/null 2>&1 &'
sleep 1
#sh start-2.sh
netstat -tnlp | grep node
pomelo list
start-1.sh
#!/bin/bash
#str=$"\n"
ssh slave.com
cd /opt/ksd_chat
nohup node crossdomain.js &
#sstr=$(echo -e $str)
#echo "$sstr"
sleep 2
exit
转载于:https://blog.51cto.com/douya/1408856