今天通过搭建教程搭建了一个zookeeper的集群,由于条件限制,所以就利用本机中的三台虚拟机来进行搭建的。
首先三台机器分别为CenterOS 7,IP分别为192.168.0.88/192.168.0.89/192.168.0.90;三台机器配备的JDK均为JDK8。
第一步、配置JDK,由于是本机的虚拟机的环境,直官网下载JDK通过rz命令(文件弹窗按钮,选择本地文件上传)分别上传至各个虚拟机中解压,然后修改/etc下的profile文件并重启即可安装完成。
export JAVA_HOME=/usr/local/jvm/jdk1.8.0_60
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
配置好配置文件,利用source profile命令进行保存并生效。
第二步、编写zookeeper解压过后的conf下zoo.cfg文件。
server.3=zookeeper-yum003:2188:3888
server.2=zookeeper-yum002:2188:3888
server.1=zookeeper-yum001:2188:3888
#autopurge.purgeInterval=1
# Set to "0" to disable auto purge feature
# Purge task interval in hours
#autopurge.snapRetainCount=3
# The number of snapshots to retain in dataDir
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
# administrator guide before turning on autopurge.
# Be sure to read the maintenance section of the
#maxClientCnxns=60
# increase this if you need to handle more clients
# the maximum number of client connections.
clientPort=2181
# the port at which the clients will connect
dataDir=/tmp/zookeeper
# example sakes.
# do not use /tmp for storage, /tmp here is just
# the directory where the snapshot is stored.
syncLimit=5
# sending a request and getting an acknowledgement
# The number of ticks that can pass between
initLimit=10
# synchronization phase can take
# The number of ticks that the initial
tickTime=2000
# The number of milliseconds of each tick
其中zookeeper-yum001、zookeeper-yum002、zookeeper-yum003分别对应的就是三台虚拟的IP地址,只是我在/etc下的hosts文件配置了相应的映射。
192.168.0.90 zookeeper-yum003
192.168.0.89 zookeeper-yum002
192.168.0.88 zookeeper-yum001
注意:对应的dataDir=/tmp/zookeeper 文件夹下面需要对应相应的myid文件,myid文件中只有对应的zookeeper的server.后面的ID
server.3=zookeeper-yum003:2188:3888
server.2=zookeeper-yum002:2188:3888
server.1=zookeeper-yum001:2188:3888
最后确定相应的防火墙是否关闭,可以利用iptables -F进行清除相应的规则。
一切准备就绪,到zookeeper文件夹下的bin文件中使用 ./zkServer.sh start进行启动zookeeper。