kafka分布式集群的搭建
使用ZooKeeper+kafka搭建高可用集群。
-
ZooKeeper安装包:apache-zookeeper-3.6.1-bin.tar.gz
-
kafka安装包:kafka_2.13-2.6.0.tgz
-
jdk1.8及以上(自行配置环境变量)
-
假设为三台服务器搭建kafka集群(192.168.12.86、192.168.12.87、192.168.12.88)
主机IP | 消息端口 | 通信端口 | 节点目录 |
---|---|---|---|
192.168.12.86 | 2181 | 2888:3888 | /db/dev/env/zookeeper/zk1 |
192.168.12.87 | 2181 | 2888:3888 | /db/dev/env/zookeeper/zk2 |
192.168.12.88 | 2181 | 2888:3888 | /db/dev/env/zookeeper/zk3 |
集群通信端口 | 节点目录 | |
---|---|---|
192.168.12.86 | 9092 | /db/dev/env/kafka/kafkaServer/kafka |
192.168.12.87 | 9092 | /db/dev/env/kafka/kafkaServer/kafka |
192.168.12.88 | 9092 | /db/dev/env/kafka/kafkaServer/kafka |
[dev@datanode6 zookeeper]$ tar -zxvf apache-zookeeper-3.6.1-bin.tar.gz -C zkServer/
vim /etc/profile
添加后
#zookeeper export ZOOKEEPER_HOME=/db/dev/env/zookeeper/zkServer/apache-zookeeper-3.6.1-bin export PATH=$ZOOKEEPER_HOME/bin:$PATH #JDK export JAVA_HOME=/db/java8 export JRE_HOME=$JAVA_HOME/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
使环境变量生效:
source /etc/profile
添加zoo.cfg
cd /opt/zookeeper/zookeeper-3.4.13/conf
复制一份zoo_sample.cfg改名为zoo.cfg并添加配置
cp zoo_sample.cfg zoo.cfg vim zoo.cfg
修改为:
dataDir=/db/dev/env/zookeeper/zkServer/apache-zookeeper-3.6.1-bin
添加:vim zoo.cfg
dataDir=/db/dev/env/zookeeper/zkServer/zkinfo/data/data_1 dataLogDir=/db/dev/env/zookeeper/zkServer/zkinfo/logs/logs_1 server.0=192.168.12.86:2888:3888 server.1=192.168.12.87:2888:3888 server.2=192.168.12.88:2888:3888
添加data文件夹:
[root@hadoop2 zookeeper-3.4.13]# mkdir data
创建myid根据serverip对应填写0 1 2
[root@hadoop2 data]# vim myid
vi /etc/sysconfig/iptables
添加
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 2181 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 2888 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 3888 -j ACCEPT
备注:这里使用2181/2888/3888是Zookeeper需要用到的端口号,22端口是用来远程的端口,可以不用添加。一般将需要开放的端口号添加到“-A INPUT -p tcp -m state --state NEW -m tcp--dport 22 -j ACCEPT”行的上面或者下面,切记不要添加到最后一行,否则防火墙重启后不生效
重启防火墙:
service iptables restart
zkServer.sh start
查看状态
zkServer.sh status
vim server.properties //三个节点都要根据不同的ip 设置broker.id=0 1 2 broker.id=0 delete.topic.enable=true listeners=PLAINTEXT://192.168.12.8*:9092 log.dirs==/db/dev/env/kafka/kafkaServer/kafkainfo/kafka-logs1 zookeeper.connect=192.168.12.86:2181,192.168.12.87:2181,192.168.12.88:2181
cd bin ./kafka-server-start.sh -daemon ../config/server.properties jps 后出现 20613 QuorumPeerMain 38582 Kafka