三台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 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多节点之间的通信端口
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 init service zookeeper-server start
查看zookeeper节点状态
[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
转载于:https://www.cnblogs.com/Skyar/p/5836810.html