部署环境规划
部署环境:CentOS Linux release 7.3.1611 (Core)
zookeeper版本/地址:http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
JDK版本/地址:jdk-8u201-linux-x64.tar.gz
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html#usermenu
服务器名称 | IP地址 | 端口 |
---|---|---|
zk1.com | 192.168.154.128 | 2888/3888 |
zk2.com | 192.168.154.129 | 2888/3888 |
zk3.com | 192.168.154.130 | 2888/3888 |
下载JDK并配置环境变量
# 下载jdk tar包,此处下载仅作展示,请到官网下载
wget https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.tar.gz
tar -zxvf jdk-8u201-linux-x64.tar.gz
# 配置/etc/profile环境变量
export JAVA_HOME=/home/jdk/jdk1.8.0_201
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
下载zookeeper并配置环境变量
# 创建目录/下载zookeeper
mkdir /home/zookeeper/
cd /home/zookeeper/
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
tar -zxvf zookeeper-3.4.10.tar.gz
# 创建数据存放和日志存放路径
mkdir -p /home/zookeeper/zookeeper-3.4.10/data
mkdir -p /home/zookeeper/zookeeper-3.4.10/log
# 配置zookeeper的/etc/profile环境变量
export ZOOKEEPER_HOME=/home/zookeeper/zookeeper-3.4.10
export PATH=$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$PATH
修改zookeeper配置文件
cp zoo_sample.cfg zoo.cfg
需要注意:dataLogDir配置项在默认的zoo_sample.cfg中是没有的,需要自己添加,以指定的路径存放事务和snap日志~
# 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=/home/zookeeper/zookeeper-3.4.10/data
dataLogDir=/home/zookeeper/zookeeper-3.4.10/log
# 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.
#
# 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
server.0=192.168.154.128:2888:3888
server.1=192.168.154.129:2888:3888
server.2=192.168.154.130:2888:3888
启动及连接测试
zkServer.sh start
# 连接zookeeper集群
zkCli.sh -server 192.168.154.128:2181
# 创建znode
create /firstnode 'hello world'
# 获取刚刚创建的节点
get /firstnode
参考学习:
https://www.w3cschool.cn/zookeeper/
https://www.cnblogs.com/leocook/p/zk_0.html
https://www.cnblogs.com/jxwch/p/6526271.html