在消費(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









