欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Centos7.5搭建单机版zookeeper

程序员文章站 2024-03-08 16:12:04
...

1、下载zookeeper安装包

下载地址:http://mirror.bit.edu.cn/apache/zookeeper/

Centos7.5搭建单机版zookeeper2、liunx安装zookeeper

2.1、/opt目录下创建zookeeper文件夹

# mkdir zookeeper

2.2、上传下载的安装包,然后解压

# tar -zvxf zookeeper-3.4.14.tar.gz

2.3、进入zookeeper-3.4.14,然后创建两个目录,一个数据存储目录data,一个日志存储目录logs

# cd zookeeper-3.4.14
# mkdir data
# mkdir logs

2.4、进入zookeeper目录下的conf子目录,使用以下命令,将配置文件模板拷贝一份,命名为zoo.cfg

# cp zoo_sample.cfg zoo.cfg

2.5、修改zoo.cfg配置文件

# vi 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=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
dataDir=/opt/zookeeper/zookeeper-3.4.14/data
dataLogDir=/opt/zookeeper/zookeeper-3.4.14/log



配置说明:
tickTime
时长单位为毫秒,为zk使用的基本时间度量单位。例如,1 * tickTime是客户端与zk服务端的心跳时间,2 * tickTime是客户端会话的超时时间。 tickTime的默认值为2000毫秒,更低的tickTime值可以更快地发现超时问题,但也会导致更高的网络流量(心跳消息)和更高的CPU使用率(会话的跟踪处理)。
 
clientPort
zk服务进程监听的TCP端口,默认情况下,服务端会监听2181端口。
 
dataDir
无默认配置,必须配置,用于配置存储快照文件的目录。
 
dataLogDir
log目录, 可以是任意目录. 如果没有设置该参数, 将使用和dataDir相同的设置。
 
clientPort
监听client连接的端口号

2.6、zookeeper 配置全局环境变量

# vi /etc/profile

添加如下:

export ZOOKEEPER_HOME=/opt/zookeeper/zookeeper-3.4.14
export PATH=$PATH:${JAVA_PATH}/bin:$ZOOKEEPER_HOME/bin

注意PATH的值有java环境变量

执行source /etc/profile,使配置的全局环境变量生效

# source /etc/profile

2.7、zookeeper 服务启动相关指令

[aaa@qq.com bin]# ./zkServer.sh start  #zookeeper 服务启动
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[aaa@qq.com bin]# ./zkServer.sh status  #zookeeper 服务状态
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Mode: standalone
[aaa@qq.com bin]# ./zkServer.sh stop    #zookeeper 服务停止
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED