分布式中提供者實(shí)現(xiàn)輪詢--zookeeper集群

在消費(fèi)者端調(diào)用提供者時(shí),為了減輕服務(wù)器壓力,就要配多個(gè)提供者,這時(shí)就要將zookeeper集群,因?yàn)轫?xiàng)目第一期中準(zhǔn)備部署3個(gè)消費(fèi)者,所以本次測(cè)試使用了3個(gè)zookeeper。

  • 本次測(cè)試只關(guān)心集群的配置,所以略過(guò)了dataLogDir的配置,只配置了dataDir
  • zookeeper可以到apache官網(wǎng)下載,我也分享了一個(gè)在網(wǎng)盤中:
    zookeeper版本3.4.13,密碼5pxl
  • zookeeper下載好后,首先是將zoo_sample.cfg重命名為zoo.cfg,然后將zookeeper一共復(fù)制為3份,分別修改名字,我是將每個(gè)zookeeper進(jìn)行了編號(hào),方便管理,如圖


    重命名
  • 然后在每個(gè)zookeeper中新建一個(gè)data文件夾


    新建data文件夾
  • 在每個(gè)zookeeper的conf文件夾下的zoo.cfg文件夾中添加該zookeeper的data文件夾路徑和修改端口號(hào)




    配置data文件夾路徑和修改端口號(hào)
  • 在每個(gè)zookeeper的conf文件夾中的zoo.cfg中添加,具體配置的解釋,(附:2881-內(nèi)部通訊端口,3881-投票選舉端口)圖中注釋解釋得很詳盡了,文末會(huì)附上配置文件代碼

    配置信息

    其中tickTime、initLimit、syncLimit在默認(rèn)配置中有配置,可不配置;我是因?yàn)閷⒛J(rèn)的配置注釋掉了,所以重新配置了一遍

  • 在每個(gè)zookeeper的data文件夾下新建一個(gè)名為myid且沒(méi)有后綴名的文件,里面存放與zookeeper編號(hào)相同的數(shù)字,表示當(dāng)前zooleeper是第幾號(hào)服務(wù)。如名為zookeeper-1的服務(wù)下的data文件夾中的myid文件中存放,如圖

    配置myid

  • zookeeper的集群就配置完了,有一段時(shí)間了,這過(guò)程中的坑還是有那么幾個(gè)的,但是,我忘了

  • 最后就是將配置在tomcat中的項(xiàng)目中的dubbo+zookeeper的配置改改了,每個(gè)提供者服務(wù)器中的配置都要做相應(yīng)的改動(dòng)




    修改dubbo+zookeeper配置
  • 然后按照這個(gè)配置下來(lái),基本就能跑通了


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機(jī)器列表,server.order這里的Order依據(jù)集群的機(jī)器個(gè)數(shù)依次進(jìn)行遞增,這里的server1、server2、server3表示機(jī)器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

#發(fā)送心跳的間隔時(shí)間,單位:毫秒
tickTime=2000
#leader和follower初始化連接時(shí)最長(zhǎng)能忍受多少個(gè)心跳時(shí)間的間隔數(shù)
initLimit=5
#leader和follower之間發(fā)送消息,請(qǐng)求和英達(dá)時(shí)間長(zhǎng)度,最長(zhǎng)不能超過(guò)多少個(gè)tickTime的時(shí)間長(zhǎng)度
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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容