上文介绍了IceBox, 那么在IceBox上解决集群主备部署和接口负载均衡等问题,就需要使用到IceRegistry.,IceGrid以后再解释。
有啥好处呢?上图,对,都是通过注册代理服务来实现接口的调用,使用者不用关心是来自哪个集群机器提供的接口服务。
run cmd :
icegridregistry --Ice.Config=registry.properties
IceGrid.Registry.Client.Endpoints=tcp -p 4061
IceGrid.Registry.Server.Endpoints=tcp
IceGrid.Registry.Internal.Endpoints=tcp
#不需要权限认证
IceGrid.Registry.AdminPermissionsVerifier=IceGrid/NullPermissionsVerifier
#持久化数据存放路径
IceGrid.Registry.Data=/usr/local/registry
#允许动态注册
IceGrid.Registry.DynamicRegistration=1
在IceBox的配置文件example.properties中增加
ExampleService.AdapterId=ExampleServiceAdapter
ExampleServiceAdapter.Endpoints=tcp
#registryhost相当于reg所在机器地址,比如192.168.1.1
Ice.Default.Locator=IceGrid/Locator:tcp -h registryhost -p 4061
这样的话就可以完成通信了。
客户端的调用就得改一改:
//Ice.ObjectPrx base = ic.stringToProxy("ExampleService:default -p 10001");
Ice.ObjectPrx base = ic.stringToProxy("ExampleService@ExampleServiceAdapter:default -p 10001");
To promote a slave to become the new master, you must shut down the slave and change its IceGrid.Registry.ReplicaName
property to Master
(or remove the property altogether). On restart, the new master notifies the nodes and registries that were active before it was shut down. An inactive registry or node will eventually connect to the new master if its default locator proxy contains the endpoint of the new master registry or the endpoint of a slave that is connected to the new master. If you cannot afford any down-time of the registry and want to minimize the down-time of the master, you should run at least two slaves. That way, if the master becomes unavailable, there will always be one registry available while you promote one of the slaves.
我们可以这样做,在Registry.properties里面增加一个名字, 使IceRegistry支持主从模式, 默认是Master
IceGrid.Registry.ReplicaName=Master
#主机是Master,从机去replica1,一旦主机挂掉了,从机的名字需要改成Master,方便集群中的数据持久化
改变IceBox的配置文件,增加为多Ip,可以填多个,端口也是一样的可以多个
Ice.Default.Locator=IceGrid/Locator:tcp -h registryhost1 registryhost2 -p 4061
最后设计的集群可以是这个样子: