前言:zookeeper集群
新建文件夹mkdir -p /usr/local/home/kafka
下载安装包
小水管比较慢,可以官网下https://kafka.apache.org/downloads
解压tar zxvf kafka_2.11-0.11.0.3.tgz
mv kafka_2.11-0.11.0.3 kafka
修改配置文件
修改k8s-node02 vim conf/server.properties
#指定kafka对应的broker id ,唯一
broker.id=0
#指定数据存放的目录
log.dirs=/usr/local/home/kafka/kafka/logs
#指定zk地址
zookeeper.connect=k8s-node02:2181,k8s-node03:2181
#指定是否可以删除topic ,默认是false 表示不可以删除
delete.topic.enable=true
#指定broker主机名
host.name=k8s-node02
修改k8s-node03 vim conf/server.properties
#指定kafka对应的broker id ,唯一
broker.id=1
#指定数据存放的目录
log.dirs=/usr/local/home/kafka/kafka/logs
#指定zk地址
zookeeper.connect=k8s-node02:2181,k8s-node03:2181
#指定是否可以删除topic ,默认是false 表示不可以删除
delete.topic.enable=true
#指定broker主机名
host.name=k8s-node03
kafka集群启动停止
启动:
nohup bin/kafka-server-start.sh config/server.properties 2>&1 &
停止
bin/kafka-server-stop.sh
启动与停止脚本
#!/bin/sh
case $1 in
"start"){
source /etc/profile
nohup /usr/local/home/kafka/kafka/bin/kafka-server-start.sh /usr/local/home/kafka/kafka/config/server.properties >/dev/null 2>&1 &
echo "kafka is running"
};;
"stop"){
source /etc/profile
nohup /usr/local/home/kafka/kafka/bin/kafka-server-stop.sh &
echo "kafka is stopping"
};;
esac
也可以在一台机器对多台节点进行启动停止
#!/bin/sh
case $1 in
"start"){
for host in node01 node02 node03
do
ssh $host "source /etc/profile"
ssh $host "nohup /usr/local/home/kafka/kafka/bin/kafka-server-start.sh /usr/local/home/kafka/kafka/config/server.properties >/dev/null 2>&1 &"
ssh $host "echo "kafka is running""
sleep 1.5s
done
};;
"stop"){
for host in node01 node02 node03
do
ssh $host "source /etc/profile"
ssh $host "nohup /usr/local/home/kafka/kafka/bin/kafka-server-stop.sh &"
ssh $host "echo "kafka is stopping""
done
};;
esac