您的位置:首页 - 文章 - 服务器, 默认 - 正文

zookeeper安装

从字义上解释就是“动物管理员”。ZooKeeper是一种集中式服务,用于维护配置信息,命名,提供分布式同步和提供组服务。

 

第一步:下载安装包

第二步:安装包上传到服务器解压

第三步:新建 data、logs 两个文件夹

第四步:进入conf文件夹复制 zoo_sample.cfg 文件 命名为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=/www/server/zookeeper/data
dataLogDir=/www/server/zookeeper/logs
# the port at which the clients will connect
clientPort=2181
admin.serverPort=8081
server.1=172.26.0.130:2881:3881
# 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
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

配置项 说明
tickTime 用于计算的时间单元,以毫秒为单位,比如session超时:N*tickTime
initLimit 用于集群,允许从节点链接并同步到master节点的初始化连接时间,以tickTime的倍数来表示
syncLimit 用于集群,master主节点与从节点之间发送消息,请求和应答时间长度(心跳机制)
clientPort 连接服务器的端口,默认是2181
dataDir 快照日志目录,存放内存数据库快照的位置,必须配置
dataLogDir 事务日志目录,不配置则和dataDir共用

这里有个和网络教程不一样的地方

# 启动的客户端端口有和自己的服务端口有冲突

admin.serverPort=8081

# 集群部署

server.1=172.26.0.130:2881:3881

第五步:进入data文件夹新建 myid文件

这里写的数字就是 server.1=172.26.0.130:2881:3881  server.1中的1

下面这个文件是自动生成的PID

 

zookeeper是建立在java基础的做所要先确定jdk的安装

echo $JAVA_HOME

然后把zookeeper的安装路径配置全局环境变量

vim /etc/profile

/etc/profile

#MQTT
export MQTT_HOME=/www/server/emqx
export PATH=$PATH:$MQTT_HOME/bin
#zookeeper
export ZOOKEEPER_HOME=/www/server/zookeeper
export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin
# jdk1.8环境变量 java_home 是安装jdk的目录和版本号
export JAVA_HOME=/usr/java/jdk1.8.0_121
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin

编辑完记得刷新一下配置

source /etc/profile

第六步:启动:

zkServer.sh start|stop|restart|status
启动:
zkServer.sh start
停止
zkServer.sh stop
重启
zkServer.sh restart
状态
zkServer.sh status

最后:验证zookeeper安装成功四字命令

telnet localhost 2181

输出结果:

Trying ::1...
Connected to localhost.
Escape character is '^]'.
直接向下输入
srvr

然后会显示zookeeper的信息:

Zookeeper version: 3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on 06/29/2018 00:39 GMT
Latency min/avg/max: 0/0/1656
Received: 123962
Sent: 123780
Connections: 1
Outstanding: 0
Zxid: 0x2fa
Mode: standalone
Node count: 164
Connection closed by foreign host.

 

本文原创,作者:西决,其版权均为品创网络所有。如需转载,请注明出处:https://www.sxpcwlkj.com/zookeeper-2/

发表评论