linux搭建zookeeper集群

目录

一、环境准备

二、安装zookeeper

三、启动集群

四、可能遇到的问题 


一、环境准备

1、准备两台linux服务器,用来搭建zookeeper集群,ip地址如下

节点ip
node1192.168.72.132
node2192.168.72.133
node3192.168.72.134

2、安装jdk,具体安装方法可看

jdk安装操作步骤

3、下载zookeeper安装包

下载地址:https://downloads.apache.org/zookeeper/

创建安装路径,示例是安装在local路径下

将zookeeper安装包传到该路径下

解压缩

二、安装zookeeper

1、进入安装目录的conf目录下,复制zoo_sample.cfg为zoo.cfg

2、打开zoo.cfg文件并修改配置信息

vim 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=/data/zookeeper
# the port at which the clients will connect
clientPort=2181
# 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.
#
# https://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

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

#设置集群信息,其中2888为follower和leader交换消息所使用的端口,3888为选举leader所使用的端口,这两个端口可自己设定
server.1=192.168.72.132:2888:3888
server.2=192.168.72.133:2888:3888
server.3=192.168.72.134:2888:3888

3、在数据文件目录dataDir下面创建文件myid ,并且写入服务器信息

此时我们zookeeper集群中的一台就配置好了

4、将该服务器的配置同步到另外两台上面,只需修改每台服务器的myid文件就行,我的分别为1.2.3

三、启动集群

1、依次启动每台zookeeper

启动成功

可以查看日志是否启动成功,日志在安装目录下的logs文件夹中的.out文件

2、查看当前服务器是leader还是follower

./zkServer.sh status

3、通过客户端连接zookeeper集群,集群是一个整体,所以连接一台即可

./zkCli.sh -server 192.168.72.132:2181

四、可能遇到的问题 

1、启动集群的时候可能会报java.net.NoRouteToHostException: NoRouteToHostException: 没有到主机的路由,解决方案可见

【Zookeeper集群启动失败】java.net.NoRouteToHostException: NoRouteToHostException: 没有到主机的路由_zookeeper no route to host怎么解决-CSDN博客

  • 23
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值