如果您觉得文本对您有帮助,请打赏,谢谢。
下载地址:https://www.apache.org/dyn/closer.cgi?path=/kafka/2.8.0/kafka_2.13-2.8.0.tgz
1、自动化安装脚本
#!/bin/bash
#zhouyihua
#v0.1
#2021-07-20
rpm -qa | grep wget
if [ $? != 0 ] ; then
yum install wget
else
echo "wget already exist"
fi
#config DNS
echo nameserver 8.8.8.8 > /etc/resolv.conf
#download jdk
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
tar -zxvf jdk-8u141-linux-x64.tar.gz
#config java env
echo "export JAVA_HOME=$PWD/jdk1.8.0_141" >> /etc/profile
echo 'export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH' >> /etc/profile
echo 'export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib' >> /etc/profile
source /etc/profile
#download kafka
cd /opt
#wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.8.0/kafka_2.13-2.8.0.tgz --no-check-certificate -O kafka_2.13-2.8.0.tgz
wget https://mirrors.bfsu.edu.cn/apache/kafka/2.8.0/kafka_2.13-2.8.0.tgz --no-check-certificate
tar -zxvf kafka_2.13-2.8.0.tgz
cd kafka_2.13-2.8.0
#background start zookeeper
./bin/zookeeper-server-start.sh ./config/zookeeper.properties 1>/dev/null 2>&1 &
#config kafka
cp -rf config/server.properties config/server.properties.bak
hostip=$(ifconfig | grep inet | head -n 1 | awk '{print $2}')
sed -i "s/#listeners=PLAINTEXT:\/\/:9092/listeners=PLAINTEXT:\/\/${hostip}:9092/" config/server.properties
sed -i "s/dataDir=\/tmp\/zookeeper/dataDir=\/opt\/zookeeper/" /opt/kafka_2.13-2.8.0/config/zookeeper.properties
sed -i "s/log.dirs=\/tmp\/kafka-logs/log.dirs=\/opt\/kafka-logs/" /opt/kafka_2.13-2.8.0/config/server.properties
#background start kafka
./bin/kafka-server-start.sh ./config/server.properties 1>/dev/null 2>&1 &
rm -rf kafka_2.13-2.8.0.tgz
exit
2、测试
创建一个topic
#cd /root/kafka_2.13-2.8.0/bin
./kafka-topics.sh --create --zookeeper localhost:2181 --config max.message.bytes=12800000 --config flush.messages=1 --replication-factor 1 --partitions 1 --topic test
在topic中添加消息
./kafka-console-producer.sh --broker-list localhost:9092 --topic test
添加后使用ctrl+c中断
查看topic
./kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
消费topic中的消息
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
添加后使用ctrl+c中断
查看broker的数量:
./zookeeper-shell.sh 127.0.0.1:2181
ls /brokers/ids