friefly gfirefly 分布式聊天 分布式部署遇到的问题 源码
####################################################################安装遇到的问题
gfirefly 0.1.9alpha 配套 gevent1.0.1 高了会出错
安装不上pyzmp的解决办法
wget http://download.zeromq.org/zeromq-4.0.3.zip
unzip zeromq-4.0.3.zip 如果不行换2.0.8试试
cd zeromq
./configure --prefix=/usr/local/
make && make install
/usr/local/python-2.7/bin/python2.7 setup.py install
####################################################################分布式文档
这个文档适用于firefly和gfirefly----这里用一个分布式聊天来举例,代码见附件
,
1.修改源码bug(如果用我自己的安装包就是已经修改过的了)
关于分布式------------------------------------------
修改源码bug
gfirefly 分布式bug 修改---docker总是获取内网IP
修改master/rootapp.py 15行
child_host_old = transport.transport.address[0]
child_host = server_config.get('yxhost', child_host_old) #yxhost请在config.json自己添加
25行
GlobalObject().root.callChild(servername,"remote_connect",name,remote_host)
改为
GlobalObject().root.callChild(servername,"remote_connect",name,child_host)
------------------------------------------------------
1. 假设我们有两台主机
一台ip为101.200.188.125 ,作为master的主机
一台ip为123.57.192.180, 作为分布式机器
必须保证所有主机的config.json都是一样的
2. 先写配置config.json可以参考源码中的config_dis.json
{
"master":{"roothost":"101.200.188.125","rootport":8005,"webport":8006},
"servers":{
"net":{"netport":8100,"name":"net","remoteport":[{"rootport":8105,"rootname":"gate"},{"rootport":8106,"rootname":"gate1"}],"app":"app.net.server","yxhost":"101.200.188.125"},
"net1":{"netport":8101,"name":"net1","remoteport":[{"rootport":8105,"rootname":"gate"},{"rootport":8106,"rootname":"gate1"}],"app":"app.net.server","yxhost":"123.57.192.180"},
"gate":{"rootport":8105,"name":"gate","app":"app.gate.server","yxhost":"101.200.188.125"},
"gate1":{"rootport":8106,"name":"gate1","app":"app.gate.server","yxhost":"123.57.192.180"}
}
}
其中"master"的roothost比较重要-----master管理所有的分布式连接,所以这个ip要写主机的
其中yxhost是原来没有的字段,作者的思想是根据主机的master来获取到各个子节点的host和端口去连接各个需要的子节点,但是如果我用docker虚拟机,是获取不到外网静态IP的。所以分布式会失败
我这里修改源码后就可以使用了
这个配置的意思是---master,net和gate放在101.200.188.125的主机上, net1和gate1放在123.57.192.180主机上
3.如何启动整个分布式服务器呢
这里必须用single模式来启动
a.首先启动主机101.200.188.125的服务
python startmaster single master ---------第一步启动master,最重要的,因为master管理所有节点,其他的节点没有顺序
python startmaster single net
python startmaster single gate
b.然后启动123.57.192.180的服务
python startmaster single net1
python startmaster single gate1
这样整个分布式服务器就启动成功了, 下面介绍如何使用supervisord来管理进程,3和4是不能并存的
停止服务器 http://101.200.188.125:8006/stop
4. 如何用supervisord来管理整个分布式呢
3和4是不能并存的
101.200.188.125主机配置
python appmain.py master config.json -------优先级最高
python appmain.py net config.json
python appmain.py gate config.json
123.57.192.180主机配置
python appmain.py net1 config.json
python appmain.py gate1 config.json
5. 测试
修改client.py的ip和端口,分别配置到不同的net
python client.py即可