socketcluster-SCC 負載均衡集羣搭建

SCC簡介:SCC是一組服務,可以輕鬆地將SocketCluster部署和擴展到任意數量的機器
SCC由以下服務組成:
socketcluster https://github.com/SocketCluster/socketcluster
scc-broker https://github.com/SocketCluster/scc-broker
scc-state https://github.com/SocketCluster/scc-state

1.下載代碼
git clone https://github.com/SocketCluster/scc-state
git clone https://github.com/SocketCluster/scc-broker
git clone https://github.com/SocketCluster/socketcluster

2.切換到每個代碼中執行 npm install

3.啓動狀態服務器scc-state

cd scc-state
node server

4.啓動代理服務器

1.cd scc-broker
2.SCC_INSTANCE_IP='127.0.0.1' 3.SCC_STATE_SERVER_HOST='127.00.1' 4.SOCKETCLUSTER_SERVER_PORT='8888' node server

注意:2、3、4放在一行執行
SCC_INSTANCE_IP 運行是sockercluster服務的ip(官網的大坑,並沒有要求),不然會提示
Server xxxxxx at address undefinedon port 8888 joined the cluster
SCC_STATE_SERVER_HOST 運行scc-state服務的ip

5.啓動sockercluster

cd socketcluster 
npm install -g socketcluster
socketcluster create myapp 
cd myapp
SCC_STATE_SERVER_HOST='127.0.0.1'SOCKETCLUSTER_PORT='8000' node server
SCC_STATE_SERVER_HOST='127.0.0.1'SOCKETCLUSTER_PORT='8001' node server

這是啓動兩個sockercluster實例 這時的這兩個實例會共享通道

6.搭建負載均衡

git clone  https://github.com/SocketCluster/loadbalancer

npm install -g loadbalancer

修改config文件

vi config.json
{
  "sourcePort": 80,
  "balancerCount": 1,
  "targetDeactivationDuration": 60000,
  "sessionExpiry": 30000,
  "downgradeToUser": "someuser", 
  "stickiness": true,
  "targets": [
    {
      "host": "localhost",
      "port": 8000
    },
    {
      "host": "localhost",
      "port": 8001
    }
  ]
}

啓動loadblancer

loadbalancer start --config my/path/config.json
loadbalancer stop  停止

當然服務在均衡也可以使用第三方的負載均衡軟件,nginx,haproxy都可以實現。

此時訪問http://localhost:80 就可以實現soketclusterde 負載均衡,共享通道了,如果需要增加機器只需要在新的機器上開啓sockercluster個進程,注意開啓時要指定scc-state的ip。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章