kafka集群的安装
kafka集群的安装
1、 将Kafka的安装包上传到虚拟机,并解压 cd /export/software/
tar -xvzf kafka_2.11-2.2.1.tgz -C ../server/
cd /export/server/kafka_2.12-2.4.1/
2、配置文件修改 进入到kafka安装目录下有一个config目录,修改server.properties配置文件
cd …/config vim server.properties
#指定kafka对应的broker id ,唯一, 其它主机分别指定1,2, etc
broker.id=0
#指定数据存放的目录
log.dirs=/kafka_2.12-2.4.1/logs
#指定zk地址
zookeeper.connect=node01:2181,node02:2181,node03:2181
#指定是否可以删除topic ,默认是false 表示不可以删除
delete.topic.enable=true
#指定broker主机名, 其它主机分别指定node02,node03, etc
host.name=node01
修改zookeper.properteis配置文件
dataDir=../zookeeper/zkdata
dataLogDir=../zookeeper/zkdatalog
# the port at which the clients will connect
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
tickTime=2000
initLimit=5
syncLimit=2
server.1=ip:2888:3888
server.2=ip:2888:3888
server.3=ip:2888:3888
启动脚本
start.sh
#!/bin/bash
# start zookeeper
ps -ef |grep "zookeeper.properties" |grep -v grep 2>&1 >/dev/null
if [ $? -eq 0 ];then
echo "OK"
else
nohup ../kafka_2.11-2.2.1/bin/zookeeper-server-start.sh -daemon ../kafka_2.11-2.2.1/config/zookeeper.properties
fi
# start kafka
ps -ef |grep "server.properties" |grep -v grep 2>&1 >/dev/null
if [ $? -eq 0 ];then
echo "OK"
else
nohup ../kafka_2.11-2.2.1/bin/kafka-server-start.sh -daemon ../kafka_2.11-2.2.1/config/server.properties
fi
停止脚步
stop.sh
#!/bin/bash
# stop zookeeper
ps -ef |grep "zookeeper.properties" |grep -v grep 2>&1 >/dev/null
if [ $? -eq 0 ];then
nohup ../kafka_2.11-2.2.1/bin/zookeeper-server-stop.sh -daemon ../kafka_2.11-2.2.1/config/zookeeper.properties
else
echo "OK"
fi
# stop kafka
ps -ef |grep "server.properties" |grep -v grep 2>&1 >/dev/null
if [ $? -eq 0 ];then
nohup ../kafka_2.11-2.2.1/bin/kafka-server-stop.sh -daemon ../kafka_2.11-2.2.1/config/server.properties
else
echo "OK"
fi
创建topic
#!/bin/bash
topic_name=$1
[ -z "${topic_name}" ] && echo "$0 <topic_name>" && exit 1
export BootStrapServer="ip:9092,ip:9092,ip:9092"
# create topic
../kafka_2.11-2.2.1/bin/kafka-topics.sh --bootstrap-server ${BootStrapServer} --create --replication-factor 2 --partitions 2 --topic ${topic_name}
# describe topic
../kafka_2.11-2.2.1/bin/kafka-topics.sh --bootstrap-server ${BootStrapServer} --describe --topic ${topic_name}
以上一切都不如使用docker
docker install zookeeper
docker pull zookeeper
docker run -d -p 2181:2181 –name zookeeper zookeeper
docker run kafka
docker pull wurstmeister/kafka
docker run -d -p 9092:9092 –link zookeeper:zookeeper –name kafka -e KAFKA_ADVERTISED_HOST_NAME=localhost -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -e KAFKA_HEAP_OPTS=”-Xmx256M -Xms128M” wurstmeister/kafka
留下评论