CentOS中配置CDH版本的ZooKeeper

三臺CentOS:Host0,Host1,Host2express

在三臺中分別安裝zookeeper-serverapache

yum install zookeeper-server -y

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

由於zookeeper集羣共有3個節點,因此在配置文件中添加server.0,server.1,server.2less

# 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 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.
dataDir=/var/lib/zookeeper
# the port at which the clients will connect
clientPort=2181
# the directory where the transaction logs are stored.
dataLogDir=/var/lib/zookeeper
#server
server.0 = Host0:2888:3888
server.1 = Host1:2888:3888
server.2 = Host2:2888:3888

2888:3888是Zookeeper多節點之間的通訊端口ui

2888接收端端口,3888發送端端口this

在各個Host中添加myid文件,並修改文件所屬用戶。spa

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相對應。code

初始化zookeeper,並啓動zookeeperorm

service zookeeper-server init
service zookeeper-server start

查看zookeeper節點狀態server

[root@Host0 ~]# zookeeper-server status
JMX enabled by default
Using config: /etc/zookeeper/conf/zoo.cfg
Mode: follower

[root@Host1 ~]# zookeeper-server status
JMX enabled by default
Using config: /etc/zookeeper/conf/zoo.cfg
Mode: leader

[root@Host2 ~]# zookeeper-server status
JMX enabled by default
Using config: /etc/zookeeper/conf/zoo.cfg
Mode: follower

可得Host1是leader,Host0和Host2是follower

相關文章
相關標籤/搜索