欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

kafka_2.11-0.10.2.0集群安装笔记

程序员文章站 2022-06-14 10:33:22
...

环境:3台物理服务器:
Server1 IP:192.168.0.137
Server2 IP:192.168.0.232
Server3 IP:192.168.0.235

1、每台服务器都要下载kafka_2.11-0.10.2.0:

点此下载 kafka_2.11-0.10.2.0

2、每台服务器都解压:

> wget http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/0.10.2.0/kafka_2.11-0.10.2.0.tgz
> tar -xzf kafka_2.11-0.10.2.0.tgz
> cd kafka_2.11-0.10.2.0

3、每台服务器都配置server.properties 和 zookeeper.properties:

配置server.properties

Server1

broker.id=1
listeners=PLAINTEXT://192.168.0.137:9092
advertised.listeners=PLAINTEXT://192.168.0.137:9092
log.dirs=/home1/irteam/data/kafka
num.partitions=3
zookeeper.connect=192.168.0.137:2181,192.168.0.232:2181,192.168.0.235:2181

Server2

broker.id=2
listeners=PLAINTEXT://192.168.0.232:9093
advertised.listeners=PLAINTEXT://192.168.0.232:9093
log.dirs=/home1/irteam/data/kafka
num.partitions=3
zookeeper.connect=192.168.0.137:2181,192.168.0.232:2181,192.168.0.235:2181

Server3

broker.id=3
listeners=PLAINTEXT://192.168.0.235:9094
advertised.listeners=PLAINTEXT://192.168.0.235:9094
log.dirs=/home1/irteam/data/kafka
num.partitions=3
zookeeper.connect=192.168.0.137:2181,192.168.0.232:2181,192.168.0.235:2181

配置zookeeper.properties

Server1

dataDir=/home1/irteam/data/zookeeper
tickTime=2000
initLimit=10
syncLimit=5
server.1=192.168.0.137:2888:3888
server.2=192.168.0.232:2888:3888
server.3=192.168.0.235:2888:3888

Server2

dataDir=/home1/irteam/data/zookeeper
tickTime=2000
initLimit=10
syncLimit=5
server.1=192.168.0.137:2888:3888
server.2=192.168.0.232:2888:3888
server.3=192.168.0.235:2888:3888

Server3

dataDir=/home1/irteam/data/zookeeper
tickTime=2000
initLimit=10
syncLimit=5
server.1=192.168.0.137:2888:3888
server.2=192.168.0.232:2888:3888
server.3=192.168.0.235:2888:3888

分别在3台服务器的/home1/irteam/data/zookeeper目录中新建一个myid的文件,里面存当前zookeeper的PID:

Server1

> echo 1 >myid

Server2

> echo 2 >myid

Server3

> echo 3 >myid

Server1的myid为1,Server2的myid为2,Server3的myid为3

4、3台服务器分别启动zookeeper:

> bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

5、3台服务器分别启动kafka:

> bin/kafka-server-start.sh -daemon config/server.properties

6、在Server1上安装kafka-manager:

安装sbt

> cd ~/apps
> wget https://dl.bintray.com/sbt/native-packages/sbt/0.13.15/sbt-0.13.15.tgz
> tar -zxvf sbt-0.13.15.tgz
> export SBT_HOME=/home1/irteam/apps/sbt
> export PATH=$SBT_HOME/bin:$PATH
> sbt sbt-version (用于测试是否成功,需要等一会)

安装jdk8,kafka-manager只能在jdk8下面运行

> cd ~/apps
> wget http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u92-linux-x64.tar.gz
> tar -zxvf jdk-8u92-linux-x64.tar.gz
> ln -s jdk1.8.0_92 jdk (再把新的jdk1.8.0_92软链接到jdk目录)
> java -version (测试一下是否成功)

安装kafka-manager

> git clone https://github.com/yahoo/kafka-manager.git
> cd kafka-manager/
> sbt clean dist (执行后需要等很久...)
> cd target/universal/(进入后会发现多了一个kafka-manager-1.3.3.7.zip,这是编译生成的)
> cd ~/apps
> mkdir kafka-manager-web
> cp /home1/irteam/apps/kafka-manager/target/universal/kafka-manager-1.3.3.7.zip kafka-manager-web
> cd kafka-manager-web
> unzip kafka-manager-1.3.3.7.zip
> rm -f kafka-manager-1.3.3.7.zip (删除zip包)
> cd kafka-manager-1.3.3.7/conf/
> vi application.conf
只需要修改这一行即可,把3台服务器的zookeeper地址加入到配置中:
kafka-manager.zkhosts="192.168.0.137:2181,192.168.0.232:2181,192.168.0.235:2181"

启动kafka-manager

> cd /home1/irteam/apps/kafka-manager-web/kafka-manager-1.3.3.7
>  bin/kafka-manager  -Dconfig.file=conf/application.conf -Dapplication.home=/home1/irteam/apps/kafka-manager-web/kafka-manager-1.3.3.7 -Dhttp.port=8080 > /dev/null &

在地址栏中输入http://192.168.0.137:8080访问即可