Kakfa集群搭建
作者:互联网
3台机器,hadoop01,hadoop02,hadoop03集群上都已经安装好zookeeper
1)将下载好的kafka安装包上传到集群上,更名为kakfa
2) 修改kafka/config/server.properties文件
#broker的全局唯一编号,不能重复 broker.id=0 #删除 topic 功能使能 delete.topic.enable=true #kafka 运行日志存放的路径 log.dirs=/home/hadoop/software/kafka/logs #配置连接 Zookeeper 集群地址 zookeeper.connect=hadoop01:2181,hadoop02:2181,hadoop03:2181/kafka
3) 配置环境变量
vi .bash_profile
source .bash_profile 使之生效
4)文件分发
sh /home/hadoop/software/xrsync.sh /home/hadoop/software/kafka
在hadoop02,hadoop03上server.properties中的 broker.id=1、broker.id=2sh /home/hadoop/software/xrsync.sh /home/hadoop/.bash_profile
在hadoop02,hadoop03使.bash_profile内容生效
5)测试启动停止
启动 bin/kafka-server-start.sh /home/hadoop/software/kafka/config/server.properties & 停止 bin/kafka-server-stop.sh 启动停止脚本 xkafka.sh启动停止脚本集合 xkafka.sh: #!/bin/sh pcount=$# if((pcount==0)); then echo no args...; exit; fi echo $JAVA_HOME case $1 in "start") for((host=1; host<=3; host++)); do echo ==================hadoop0$host================== ssh hadoop0$host -l hadoop "/home/hadoop/software/kafka/bin/kafka-server-start.sh -daemon /home/hadoop/software/kafka/config/server.properties " done ;; "stop") for((host=1; host<=3; host++)); do echo ==================hadoop0$host================== ssh hadoop0$host -l hadoop '/home/hadoop/software/kafka/bin/kafka-server-stop.sh stop' done ;; esac
遇到的问题: ① sh xkafka.sh start 启动日志报错 nohup: failed to run command ‘java’: No such file or directory 经排查,是因为: ssh登陆之后会发现找不到JAVA_HOME,远程登录和直接登录执行的文件是不一样的:
- /etc/profile: 当用户登录时,该文件被执行.
- /etc/bashrc: 当bash shell被打开时,该文件被执行
配置完成后,使之生效,source ~/.bashrc ,分发给其他机器,同样的使之生效
②启动成功后,测试停止,报错:No kafka server to stop
但是jps能查到kafka进程
解决办法:
修改bin/kafka-run-class.sh 文件
将 PIDS=$(ps ax | grep -i 'kafka\.Kafka' | grep java | grep -v grep | awk '{print $1}') 修改成
PIDS=$(jps -lm | grep -i 'kafka.Kafka' | awk '{print $1}')
保存,分发到其他几个节点上
6)命令使用
①创建 topic /home/hadoop/software/kafka/bin/kafka-topics.sh --zookeeper hadoop01:2181,hadoop02:2181,hadoop03:2181/kafka --create --replication-factor 1 --partitions 1 --topic first 选项说明: --topic 定义 topic 名 --replication-factor 定义副本数 --partitions 定义分区数 注意:hadoop01:2181,hadoop02:2181,hadoop03:2181/kafka 要与配置的一致,不然报错 Error while executing topic command : Replication factor: 1 larger than available brokers: 0.②查看当前服务器中的所有 topic
/home/hadoop/software/kafka/bin/kafka-topics.sh --zookeeper hadoop01:2181,hadoop02:2181,hadoop03:2181/kafka --list③删除topic
/home/hadoop/software/kafka/bin/kafka-topics.sh --zookeeper hadoop01:2181,hadoop02:2181,hadoop03:2181/kafka --delete --topic first 需要 server.properties 中设置 delete.topic.enable=true 否则只是标记删除或者直接重启
标签:--,kafka,topic,Kakfa,2181,sh,集群,home,搭建 来源: https://www.cnblogs.com/kopao/p/14330157.html