cat > /application/zookeeper/conf/zoo.cfg <<'EOF' # The number of milliseconds of each tick # 这个时间是作为 Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔 tickTime=2000 # The number of ticks that the initial # synchronization phase can take # 配置 Zookeeper接受客户端初始化连接时最长能忍受多少个心跳时间间隔数。 initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement # Leader与Follower之间发送消息,请求和应答时间长度 syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. # 数据目录 dataDir=/data/zookeeper/zkdata # 日志目录 dataLogDir=/data/zookeeper/zklog # the port at which the clients will connect # 侦听端口 clientPort=2181 # # 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,每个节点服务编号=服务器ip地址:集群通信端口:选举端口(Leader宕机后) server.1=zoo-01:2888:3888 EOF
cat >> /application/hadoop/zookeeper/conf/zoo.cfg <<'EOF' # The number of milliseconds of each tick # 这个时间是作为 Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔 tickTime=2000 # The number of ticks that the initial # synchronization phase can take # 配置 Zookeeper接受客户端初始化连接时最长能忍受多少个心跳时间间隔数。 initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement # Leader与Follower之间发送消息,请求和应答时间长度 syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. # 数据目录 dataDir=/data/zookeeper/zkdata # 日志目录 dataLogDir=/data/zookeeper/zklog # the port at which the clients will connect # 侦听端口 clientPort=2181 # # 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,每个节点服务编号=服务器ip地址:集群通信端口:选举端口 server.1=cdh001:2888:3888 server.2=cdh002:2888:3888 server.3=cdh003:2888:3888 EOF
zkServer.sh restart 重启服务 zkServer.sh status 查看服务运行状态 zkServer.sh stop 关闭服务
集群验证
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[hadoop@cdh001 ~]$ /application/hadoop/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /application/hadoop/zookeeper/bin/../conf/zoo.cfg Mode: follower
[hadoop@cdh002 ~]$ /application/hadoop/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /application/hadoop/zookeeper/bin/../conf/zoo.cfg Mode: follower
[hadoop@cdh003 ~]$ /application/hadoop/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /application/hadoop/zookeeper/bin/../conf/zoo.cfg Mode: leader