##kafka运行涉及zookeeper,kafka和zookeeper都运行在jvm之上。
###准备三台服务器,ip地址如下:
192.168.137.31
192.168.137.32
192.168.137.33
安装jdk8或者以上版本,详细步骤网上很多教程可以参考
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz
mv apache-zookeeper-3.7.0-bin /opt/zookeeper-3.7
echo 'export ZOOKEEPER_HOME=/opt/zookeeper-3.7' >> /etc/profile echo 'export PATH=$PATH:$ZOOKEEPER_HOME/bin' >> /etc/profile source /etc/profile
cd /opt/zookeeper-3.7/conf/ vim zoo.cfg 输入以下内容 # 服务器心跳时间,单位ms tickTime=2000 # 允许follower连接并同步到leader的初始化连接时间,以tickTime倍数表示 initLimit=10 # leader与follwer心跳检测最大容忍时间 # 超过 tickTime*syncLimit ,判断follower离线 syncLimit=5 # 数据目录 dataDir=/data/zookeeper/data # 日志目录 dateLogDir=/data/zookeeper/log # 对外服务端口 clientPort=2181 ## 集群配置 server.1=192.168.137.31:2888:3888 server.2=192.168.137.32:2888:3888 server.3=192.168.137.33:2888:3888
mkdir -p /data/zookeeper/data mkdir -p /data/zookeeper/log
服务器1执行 192.168.137.31 echo 1 > /data/zookeeper/data/myid 服务器2执行 192.168.137.32 echo 2 > /data/zookeeper/data/myid 服务器3执行 192.168.137.33 echo 3 > /data/zookeeper/data/myid
cd /opt/zookeeper-3.7/bin/; ./zkServer.sh start
./zkServer.sh status
wget https://dlcdn.apache.org/kafka/3.0.0/kafka_2.13-3.0.0.tgz
tar -zxvf kafka_2.13-3.0.0.tgz
mv kafka_2.13-3.0.0 /opt/
echo 'export KAFKA_HOME=/opt/kafka_2.13-3.0.0' >> /etc/profile echo 'export PATH=$PATH:$KAFKA_HOME/bin' >> /etc/profile source /etc/profile
cd /opt/kafka_2.13-3.0.0/config/ vim server.properties 重点修改以下参数 # broker编号,保证每台机器值不同。第一台机器0,第二台机器1,第三台机器2 broker.id=0 # broker对外提供服务的入口地址 注意改为本机ip listeners=PLAINTEXT://192.168.137.31:9092 # 存放消息日志文件 不要使用默认值,会丢失数据 log.dirs=/data/kafka-logs # zookeeper集群地址 zookeeper.connect=192.168.137.31:2181,192.168.137.32:2181,192.168.137.33:2181
mkdir -p /data/kafka-logs
cd /opt/kafka_2.13-3.0.0/bin/; ./kafka-server-start.sh -daemon ../config/server.properties