-
clientPort端⼝
如果在1台机器上部署多个server,那么每台机器都要不同的 clientPort,⽐如 server1是2181,server2 是2182,server3是2183 -
dataDir和dataLogDir
dataDir和dataLogDir也需要区分下,将数据⽂件和⽇志⽂件分开存放,同时每个server的这两变量所对应的路径都是不同的 -
server.X和myid
server.X 这个数字就是对应,data/myid中的数字。在3个server的myid⽂件中分别写⼊了1,2,3,那 么每个server中的zoo.cfg都配 server.1 server.2,server.3就⾏了。因为在同⼀台机器上,后⾯连着的2 个端⼝,3个server都不要⼀样,否则端⼝冲突 -
创建⽬录zkcluster
mkdir zkcluster
-
解压 zookeeper-x.x.xx.tar.gz到zkcluster⽬录下
tar -zxvf zookeeper-3.6.2.tar.gz
-
改变名称
mv zookeeper-3.6.2 zookeeper01
-
复制并改名
cp -r zookeeper01/ zookeeper02 cp -r zookeeper01/ zookeeper03
-
分别在zookeeper01、zookeeper02、zookeeper03⽬录下创建data及logs⽬录
mkdir data cd data mkdir logs
-
修改配置⽂件名称
cd conf mv zoo_sample.cfg zoo.cfg
-
配置每⼀个Zookeeper 的dataDir(zoo.cfg) clientPort 分别为2181 2182 2183
clientPort=2181 dataDir=/usr/local/zkcluster/zookeeper01/data dataLogDir=/usr/local/zkcluster/zookeeper01/data/logs
clientPort=2182 dataDir=/usr/local/zkcluster/zookeeper02/data dataLogDir=/usr/local/zkcluster/zookeeper02/data/logs
clientPort=2183 dataDir=/usr/local/zkcluster/zookeeper03/data dataLogDir=/usr/local/zkcluster/zookeeper03/data/logs
-
配置集群
(1)在每个zookeeper的 data ⽬录下创建⼀个 myid ⽂件,内容分别是1、2、3 。这个⽂件就是记录每个服务器的IDtouch myid
(2)在每⼀个zookeeper 的 zoo.cfg配置客户端访问端⼝(clientPort)和集群服务器IP列表。
server.1=121.4.55.123:2881:3881 server.2=121.4.55.123:2882:3882 server.3=121.4.55.123:2883:3883 quorumListenOnAllIPs=true
- server.服务器ID=服务器IP地址:服务器之间通信端⼝:服务器之间投票选举端⼝。
- quorumListenOnAllIPs=true: 在云服务器(阿里云、腾讯云)上部署Zookeeper集群模式时要加,否则会报错:Error contacting service. It is probably not running.
- quorumListenOnAllIPs=true这个参数潜在的问题:主要是会影响ZAB协议和FastLeaderElection协议。
官网原文如下
quorumListenOnAllIPs
When set to true the ZooKeeper server will listen for connections from its peers on all available IP addresses, and not only the address configured in the server list of the configuration file. It affects the connections handling the ZAB protocol and the Fast Leader Election protocol. Default value is false -
启动成功
zookeeper01:
zookeeper02:
zookeeper03:
笔记6:zookeeper伪集群模式云服务器搭建
最新推荐文章于 2022-10-10 23:33:13 发布