美文网首页
分布式中提供者实现轮询--zookeeper集群

分布式中提供者实现轮询--zookeeper集群

作者: 09c72470861c | 来源:发表于2018-09-24 22:34 被阅读0次

    在消费者端调用提供者时,为了减轻服务器压力,就要配多个提供者,这时就要将zookeeper集群,因为项目第一期中准备部署3个消费者,所以本次测试使用了3个zookeeper。

    • 本次测试只关心集群的配置,所以略过了dataLogDir的配置,只配置了dataDir
    • zookeeper可以到apache官网下载,我也分享了一个在网盘中:
      zookeeper版本3.4.13,密码5pxl
    • zookeeper下载好后,首先是将zoo_sample.cfg重命名为zoo.cfg,然后将zookeeper一共复制为3份,分别修改名字,我是将每个zookeeper进行了编号,方便管理,如图


      重命名
    • 然后在每个zookeeper中新建一个data文件夹


      新建data文件夹
    • 在每个zookeeper的conf文件夹下的zoo.cfg文件夹中添加该zookeeper的data文件夹路径和修改端口号




      配置data文件夹路径和修改端口号
    • 在每个zookeeper的conf文件夹中的zoo.cfg中添加,具体配置的解释,(附:2881-内部通讯端口,3881-投票选举端口)图中注释解释得很详尽了,文末会附上配置文件代码

      配置信息
      其中tickTime、initLimit、syncLimit在默认配置中有配置,可不配置;我是因为将默认的配置注释掉了,所以重新配置了一遍
    • 在每个zookeeper的data文件夹下新建一个名为myid且没有后缀名的文件,里面存放与zookeeper编号相同的数字,表示当前zooleeper是第几号服务。如名为zookeeper-1的服务下的data文件夹中的myid文件中存放,如图

      配置myid
    • zookeeper的集群就配置完了,有一段时间了,这过程中的坑还是有那么几个的,但是,我忘了

    • 最后就是将配置在tomcat中的项目中的dubbo+zookeeper的配置改改了,每个提供者服务器中的配置都要做相应的改动




      修改dubbo+zookeeper配置
    • 然后按照这个配置下来,基本就能跑通了


    zoo.cfg:

    # The number of milliseconds of each tick
    #tickTime=2000
    # The number of ticks that the initial 
    # synchronization phase can take
    #initLimit=10
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    #syncLimit=5
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    
    dataDir=F:\\bfy-test\\zookeeper\\zookeeper-1\\data
    # the port at which the clients will connect
    clientPort=2181
    
    #zookeeper机器列表,server.order这里的Order依据集群的机器个数依次进行递增,这里的server1、server2、server3表示机器IP地址
    server.1=127.0.0.1:2881:3881
    server.2=127.0.0.1:2882:3882
    server.3=127.0.0.1:2883:3883
    
    #发送心跳的间隔时间,单位:毫秒
    tickTime=2000
    #leader和follower初始化连接时最长能忍受多少个心跳时间的间隔数
    initLimit=5
    #leader和follower之间发送消息,请求和英达时间长度,最长不能超过多少个tickTime的时间长度
    syncLimit=2
    
    
    # the maximum number of client connections.
    # increase this if you need to handle more clients
    #maxClientCnxns=60
    #
    # Be sure to read the maintenance section of the 
    # administrator guide before turning on autopurge.
    #
    # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    #
    # The number of snapshots to retain in dataDir
    #autopurge.snapRetainCount=3
    # Purge task interval in hours
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1
    
    

    相关文章

      网友评论

          本文标题:分布式中提供者实现轮询--zookeeper集群

          本文链接:https://www.haomeiwen.com/subject/euwhoftx.html