zookeeper集群搭建
-
环境信息
系统: centos6.8 IP: 192.168.57.201、192.168.57.202、192.168.57.203 软件版本: zookeeper-3.4.10.tar.gz 、jdk-8u191-linux-x64.tar.gz 软件存放路径: /opt/yidian/zookeeper-3.4.10.tar.gz /opt/yidian/jdk-8u191-linux-x64.tar.gz
-
安装JDK
解压JDK tar -xzvf jdk-8u191-linux-x64.tar.gz /opt/yidian/jdk1.8.0_191 -- 当前jdk解压路径 配置JDK环境变量(/etc/profile) JAVA_HOME=/opt/yidian/jdk1.8.0_191 PATH=$JAVA_HOME/bin:$PATH CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAME_HOME/lib/tools.jar export JAVA_HOME export PATH export CLASSPATH 刷新环境变量 source /etc/profile
-
安装zookeeper
解压zookeeper tar xzvf zookeeper-3.4.10.tar.gz 修改zookeeper的配置文件 mv zoo_sample.cfg zoo.cfg 创建zookeeper的数据目录和日志目录 /opt/zk/data /opt/zk/logs 修改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=/opt/zk/data dataLogDir=/opt/zk/logs # 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 #2888 选举端口 #3888 心跳端口 server.1=test201:2888:3888 server.2=test202:2888:3888 server.3=test203:2888:3888 myid文件内容如下: 201 /opt/zk/data/myid -- 1 202 /opt/zk/data/myid -- 2 203 /opt/zk/data/myid -- 3 修改本地hosts 192.168.57.201 test201 192.168.57.202 test202 192.168.57.203 test203
-
集群启动测试
启动目录 /opt/yidian/zookeeper-3.4.10/bin 分别启动3台机器的zookeeper ./zkServer.sh start 查看集群的状态 ./zkServer.sh status #显示如下信息,代表集群环境搭建成功! [root@test201 bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/yidian/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: follower [root@test202 bin]# ./zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/yidian/zookeeper-3.4.10/bin/../conf/zoo.cfg Mode: leader