xingo集群服務器推薦目錄結構:
.
├── admin_server 管理服務,可以實現集群的GM管理操作,支持http方式訪問
│ ├── test_admin_http.go 對外管理的http接口
│ └── test_admin_rpc.go 對內提供給集群其他節(jié)點訪問的rpc接口
├── conf 集群服務器配置
│ ├── clusterconf.json 分布式架構定義
│ └── server.json 服務器配置
├── game_server 游戲服務器邏輯
├── gate_server gate服務器邏輯
│ ├── gateserver.go 這里可以綁定節(jié)點鏈接和斷開處理函數
│ └── test_gate_rpc.go 對內rpc接口
├── log 集群服務器日志文件/支持按服務器/日志大小/時間切割日志
│ ├── cluster.log
│ ├── gate1.log
│ ├── gate2.log
│ └── net.log
├── master.go 管理服務
├── net_server 對外的網關服務器負責于客戶端通信
│ ├── core
│ │ ├── player.go
│ │ └── playermgr.go
│ ├── netserver.go
│ ├── test_net_api.go
│ └── test_net_rpc.go
├── pb
│ └── msg.pb.go
├── README.md
└── server.go xingo server
master.go
package main import ( "path/filepath" "github.com/viphxin/xingo/sys_rpc" "github.com/viphxin/xingo/clusterserver" ) func main() { dir, err := filepath.Abs(filepath.Dir(".")) if err == nil{ s := clusterserver.NewMaster(filepath.Join(dir, "conf", "clusterconf.json"))//關聯集群配置 s.AddRpcRouter(&sys_rpc.MasterRpc{})//添加rpc接口 s.StartMaster()//開啟服務 } }server.go
package main import ( "github.com/viphxin/xingo/clusterserver" "github.com/viphxin/xingo/sys_rpc" "os" "path/filepath" "xingo_cluster/net_server" "xingo_cluster/gate_server" "xingo_cluster/admin_server" _ "net/http" _ "net/http/pprof" ) func main() { //pprof //go func() { // println(http.ListenAndServe("localhost:6060", nil)) //}() //server code args := os.Args dir, err := filepath.Abs(filepath.Dir(".")) if err == nil{ s := clusterserver.NewClusterServer(args[1], filepath.Join(dir, "conf", "clusterconf.json")) s.AddRpcRouter(&sys_rpc.ChildRpc{}) s.AddRpcRouter(&sys_rpc.RootRpc{}) /* 注冊分布式服務器 */ //net server s.AddModule("net", &net_server.TestNetApi{}, &net_server.TestNetRpc{}) //gate server s.AddModule("gate", nil, &gate_server.TestGateRpc{}) //admin server s.AddModule("admin", &admin_server.TestAdminHttp{}, nil) s.StartClusterServer() } }
啟動:
go run master.go go run server.go gate1 go run server.go gate2 go run server.go net1 go run server.go net2 go run server.go net3 go run server.go net4 go run server.go admin
更多建議: