单节点部署三台zookeeper和三台kafka

一台机器部署三台zookeeper:同理kafka也可以这样部署

解压复制三个目录,分别为 zookeeper,zookeeper1,zookeeper2
[hadoop@hadoop001 app]$ ll
lrwxrwxrwx.  1 hadoop hadoop   25 Sep  1 03:37 zookeeper -> zookeeper-3.4.5-cdh5.7.0/
drwxr-xr-x. 14 hadoop hadoop 4096 Oct 29 23:21 zookeeper1
drwxr-xr-x. 14 hadoop hadoop 4096 Oct 29 23:21 zookeeper2
drwxr-xr-x. 14 hadoop hadoop 4096 Oct 29 22:59 zookeeper-3.4.5-cdh5.7.0
[hadoop@hadoop001 app]$ 

修改配置文件:dataDir需要不一样,每个server的端口号需要不一样,clientPort需要不一样
第一台:
[hadoop@hadoop001 zookeeper]$ cp ./conf/zoo_sample.cfg zoo.cfg
[hadoop@hadoop001 zookeeper]$ vi ./conf/zoo.cfg 
##该目录需手动创建
dataDir=/home/hadoop/data/zookeeper
server.1=hadoop001:2888:3888
server.2=hadoop001:2889:3889
server.3=hadoop001:2890:3890
clientPort=2181

第二台:
[hadoop@hadoop001 zookeeper1]$ cp ./conf/zoo_sample.cfg zoo.cfg
[hadoop@hadoop001 zookeeper1]$ vi ./conf/zoo.cfg 
##该目录需手动创建
dataDir=/home/hadoop/data/zookeeper1
server.1=hadoop001:2888:3888
server.2=hadoop001:2889:3889
server.3=hadoop001:2890:3890
clientPort=2182

第三台:
[hadoop@hadoop001 zookeeper2]$ cp ./conf/zoo_sample.cfg zoo.cfg
[hadoop@hadoop001 zookeeper2]$ vi ./conf/zoo.cfg 
##该目录需手动创建
dataDir=/home/hadoop/data/zookeeper2
server.1=hadoop001:2888:3888
server.2=hadoop001:2889:3889
server.3=hadoop001:2890:3890
clientPort=2183


创建dataDir目录:
[hadoop@hadoop001 zookeeper]$ mkdir /home/hadoop/data/zookeeper
[hadoop@hadoop001 zookeeper1]$ mkdir /home/hadoop/data/zookeeper1
[hadoop@hadoop001 zookeeper2]$ mkdir /home/hadoop/data/zookeeper2

创建myid文件到dataDir目录下:
[hadoop@hadoop001 zookeeper]$ echo 1 >  /home/hadoop/data/zookeeper/myid
[hadoop@hadoop001 zookeeper1]$ echo 2 >  /home/hadoop/data/zookeeper1/myid
[hadoop@hadoop001 zookeeper2]$ echo 3 >  /home/hadoop/data/zookeeper2/myid

启动:
[hadoop@hadoop001 zookeeper]$ ./bin/zkServer.sh start
[hadoop@hadoop001 zookeeper1]$ ./bin/zkServer.sh start
[hadoop@hadoop001 zookeeper2]$ ./bin/zkServer.sh start




查看状态:
[hadoop@hadoop001 zookeeper]$ ./bin/zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/app/zookeeper/bin/../conf/zoo.cfg
Mode: follower


[hadoop@hadoop001 zookeeper1]$ ./bin/zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/app/zookeeper1/bin/../conf/zoo.cfg
Mode: leader



[hadoop@hadoop001 zookeeper2]$ ./bin/zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/app/zookeeper2/bin/../conf/zoo.cfg
Mode: follower

zookeeper的三种端口号:

  2181:客户端连接Zookeeper集群使用的监听端口号

  3888:选举leader使用

  2888:集群内机器通讯使用(Leader和Follower之间数据同步使用的端口号,Leader监听此端口)

-------------------------------------------------
kafka部署:跟zookeeper不太一样的是不需要三个kafka目录,只需要配置三个不同的配置文件,在启动的时候指定不同的配置文件即可
[hadoop@hadoop001 config]$ cp server.properties server1.properties 
[hadoop@hadoop001 config]$ cp server.properties server2.properties 

分别修改三个配置文件:
第一台:
[hadoop@hadoop001 kafka]$ vi config/server.properties 

broker.id=0
listeners=PLAINTEXT://:9092
log.dirs=/home/hadoop/log/kafka-logs
zookeeper.connect=hadoop001:2181,hadoop001:2182,hadoop001:2183/kafka


第二台:
[hadoop@hadoop001 kafka]$ vi config/server1.properties 

broker.id=1
listeners=PLAINTEXT://:9093
log.dirs=/home/hadoop/log/kafka-logs1
zookeeper.connect=hadoop001:2181,hadoop001:2182,hadoop001:2183/kafka

第三台:
[hadoop@hadoop001 kafka]$ vi config/server.properties 

broker.id=2
listeners=PLAINTEXT://:9094
log.dirs=/home/hadoop/log/kafka-logs2
zookeeper.connect=hadoop001:2181,hadoop001:2182,hadoop001:2183/kafka


启动命令:
启动脚本为 bin/kafka-server-start.sh 查看启动命令
USAGE: ./kafka-server-start.sh [-daemon] server.properties [--override property=value]*
启动三台kafka:
[hadoop@hadoop001 kafka]$ ./bin/kafka-server-start.sh -daemon ./config/server.properties 
[hadoop@hadoop001 kafka]$ ./bin/kafka-server-start.sh -daemon ./config/server1.properties 
[hadoop@hadoop001 kafka]$ ./bin/kafka-server-start.sh -daemon ./config/server2.properties 

仅供测试使用



你可能感兴趣的:(Zookeeper)