zookeeper+kafka集群部署 以及kafka单机部署
137 zookeeper+kafka集群文档
#搭建资料来源
https://juejin.im/post/5d85953bf265da03f47c5be4#heading-10
#启动zookeeper集群
/home/dataexa/zookeeper1/bin/zkServer.sh start
/home/dataexa/zookeeper2/bin/zkServer.sh start
/home/dataexa/zookeeper3/bin/zkServer.sh start
#查看zookeeper集群状态
/home/dataexa/zookeeper1/bin/zkServer.sh status
/home/dataexa/zookeeper2/bin/zkServer.sh status
/home/dataexa/zookeeper3/bin/zkServer.sh status
#启动kafka集群 占用端口 9092 9093 9094
cd /home/dataexa/kafka
bin/kafka-server-start.sh -daemon config/server-1.properties
bin/kafka-server-start.sh -daemon config/server-2.properties
bin/kafka-server-start.sh -daemon config/server-3.properties
#kafka集群使用状况
#创建主题
cd /home/dataexa/kafka
bin/kafka-topics.sh --create --bootstrap-server 192.168.191.10:9092 192.168.191.10:9093 192.168.191.10:9094 --replication-factor 3 --partitions 1 --topic my-test-topic
#查看主题
cd /home/dataexa/kafka
bin/kafka-topics.sh --describe --bootstrap-server 192.168.191.10:9092 --topic my-replicated-topic
bin/kafka-topics.sh --describe --bootstrap-server 192.168.191.10:9092 192.168.191.10:9093 192.168.191.10:9094 --topic my-test-topic
#消费者展示
cd /home/dataexa/kafka
bin/kafka-console-consumer.sh --bootstrap-server 192.168.191.10:9093 --topic my-replicated-topic --from-beginning
bin/kafka-console-consumer.sh --bootstrap-server 192.168.191.10:9092 192.168.191.10:9093 192.168.191.10:9094 --topic my-test-topic --from-beginning
#生产输出
cd /home/dataexa/kafka
bin/kafka-console-producer.sh --broker-list 192.168.191.10:9092 192.168.191.10:9093 192.168.191.10:9094 --topic my-test-topic
#bin/kafka-console-producer.sh --broker-list 192.168.191.10:9092 192.168.191.10:9093 192.168.191.10:9094 --topic my-replicated-topic
kafka 检测启停端口脚本
#!/bin/bash
# author:gaofeng
# write sh date 20200224
# this scirpt is check kafka port
kafka_port_9092=`netstat -lntup | grep 192.168.1.137 | grep 9092 | awk '{print $4}' | awk -F ":" '{print $2}'`
kafka_port_9093=`netstat -lntup | grep 192.168.1.137 | grep 9093 | awk '{print $4}' | awk -F ":" '{print $2}'`
kafka_port_9094=`netstat -lntup | grep 192.168.1.137 | grep 9094 | awk '{print $4}' | awk -F ":" '{print $2}'`
if [ -n "$kafka_port_9092" ]
then
echo "$kafka_port_9092 is running"
else
echo "scirpt start kafka 9092 Example"
/home/dataexa/kafka/bin/kafka-server-start.sh -daemon /home/dataexa/kafka/config/server-1.properties
fi
sleep 15
if [ -n "$kafka_port_9093" ]
then
echo "$kafka_port_9093 is running"
else
echo "scirpt start kafka 9093 Example"
/home/dataexa/kafka/bin/kafka-server-start.sh -daemon /home/dataexa/kafka/config/server-2.properties
fi
sleep 15
if [ -n "$kafka_port_9094" ]
then
echo "$kafka_port_9094 is running"
else
echo "scirpt start kafka 9094 Example"
/home/dataexa/kafka/bin/kafka-server-start.sh -daemon /home/dataexa/kafka/config/server-3.properties
fi
定时任务每半个小时检查一次
crontab -l
*/30 * * * * /bin/sh /home/dataexa/application/scripts/check_kafka_port_status.sh
150 kafka依赖自带的zookeeper 单机
#资料来源 http://www.54tianzhisheng.cn/2018/01/04/Kafka/
#以后台方式启动Kafka自带的zookeeper
cd /usr/local/kafka
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
#以后台方式启动kafka (必须先启动kakfa自带的zookeeper)
cd /usr/local/kafka
bin/kafka-server-start.sh -daemon config/server.properties
#消费者
/usr/local/kafka/bin/kafka-console-consumer.sh --zookeeper 192.168.1.150:2181 --topic test --from-beginning
#生产者
/usr/local/kafka/bin/kafka-console-producer.sh --broker-list 192.168.1.150:9092 --topic test