首页 > 代码库 > CentOS中配置CDH版本的ZooKeeper

CentOS中配置CDH版本的ZooKeeper

三台CentOS:Host0,Host1,Host2

在三台中分别安装zookeeper-server

yum install zookeeper-server -y

修改zookeeper的配置文件(/etc/zookeeper/conf/zoo.cfg)

因为zookeeper集群共有3个节点,所以在配置文件中添加server.0,server.1,server.2

# Licensed to the Apache Software Foundation (ASF) under one or more# contributor license agreements.  See the NOTICE file distributed with# this work for additional information regarding copyright ownership.# The ASF licenses this file to You under the Apache License, Version 2.0# (the "License"); you may not use this file except in compliance with# the License.  You may obtain a copy of the License at##     http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.maxClientCnxns=50# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.dataDir=/var/lib/zookeeper# the port at which the clients will connectclientPort=2181# the directory where the transaction logs are stored.dataLogDir=/var/lib/zookeeper#serverserver.0 = Host0:2888:3888server.1 = Host1:2888:3888server.2 = Host2:2888:3888

在各个Host中添加myid文件,并修改文件所属用户。

echo "0" > /var/lib/zookeeper/myid
chown zookeeper:zookeeper /var/lib/zookeeper/myid

注意,三个主机的/var/lib/zookeeper/myid文件内容不能相同,且与之间的server.0,server.1,server.2的0,1,2相对应。

初始化zookeeper,并启动zookeeper

service zookeeper-server initservice zookeeper-server start

查看zookeeper节点状态

[root@Host0 ~]# zookeeper-server statusJMX enabled by defaultUsing config: /etc/zookeeper/conf/zoo.cfgMode: follower[root@Host1 ~]# zookeeper-server statusJMX enabled by defaultUsing config: /etc/zookeeper/conf/zoo.cfgMode: leader[root@Host2 ~]# zookeeper-server statusJMX enabled by defaultUsing config: /etc/zookeeper/conf/zoo.cfgMode: follower

可得Host1是leader,Host0和Host2是follower

CentOS中配置CDH版本的ZooKeeper