高谈风月

不共青山一笑,不与黄花一醉

0%

kafka伪集群部署

1
wget https://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.6.0/kafka_2.12-2.6.0.tgz
  1. 执行解压命令
1
2
tar -zxvf kafka_2.12-2.6.0.tgz -C /opt/kafka
mv kafka_2.12-2.6.0 kafka
  1. 复制配置修改server1.properties配置
1
2
3
4
cd /opt/kafka/config
cp config/server.properties config/server-1.properties
cp config/server.properties config/server-2.properties
cp config/server.properties config/server-3.properties

复制1的配置到2 3

1
2
3
mkdir -p /opt/kafka/data/kafka-logs-3
mkdir -p /opt/kafka/data/kafka-logs-2
mkdir -p /opt/kafka/data/kafka-logs-1
  1. 修改 每个server 的配置文件 server-x.properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#server-1.properties
broker.id=0
listeners=PLAINTEXT://localhost:9092
log.dirs=/opt/kafka/kafka-logs/kafka01
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
#server-2.properties
broker.id=1
listeners=PLAINTEXT://localhost:9093
log.dirs=/opt/kafka/kafka-logs/kafka02
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
#server-3.properties
broker.id=2
listeners=PLAINTEXT://localhost:9094
log.dirs=/opt/kafka/kafka-logs/kafka03
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
  1. 启动集群及测试
1
2
3
./kafka-server-start.sh -daemon ../config/server1.properties
./kafka-server-start.sh -daemon ../config/server2.properties
./kafka-server-start.sh -daemon ../config/server3.properties

注:如果单机伪集群内存不够,可以修改启动脚本,将红框内的内存改小些,默认为1G

vim ./bin/kafka-server-start.sh

img

如果在启动中报错,kafka会在安装目录下生成一个错误log,可以通过查看该文件排错直至启动

img

  1. 查看是否启动成功:
1
2
3
netstat -nltp | grep 9092
netstat -nltp | grep 9093
netstat -nltp | grep 9094

连接zookeeper测试

/usr/local/zookeeper/bin/zkCli.sh -server 127.0.0.1:2182,127.0.0.1:2183,127.0.0.1:2184

支持不要超过早餐费~