[关闭]
@zhangyy 2021-06-01T10:22:21.000000Z 字数 6338 阅读 181

kafka的安装部署(二)

kafka系列


  • 一:资源规划
  • 二:安装jdk1.8
  • 三:安装zookeeper
  • 四:安装kafka
  • 五:安装kafka Eagle

一:资源规划

组件 node01.vpc.flyfish.cn node02.vpc.flyfish.cn node03.vpc.flyfish.cn
os centos7.8 centos7.8 centos7.8
JDK jdk1.8 jdk1.8 jdk1.8
zk QuorumPeerMain QuorumPeerMain QuorumPeerMain
kafka kafka kafka kafka

二:安装 jdk1.8

  1. 所有节点全部安装
  2. rpm -ivh jdk-8u191-linux-x64.rpm
  3. vim /etc/profile
  4. ---
  5. export JAVA_HOME=/usr/java/jdk1.8.0_191-amd64
  6. export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
  7. PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
  8. ---
  9. source /etc/profile
  10. java -version

image_1ejbv2qsiu9m1q6a1akhtm618je9.png-63.3kB


三:安装zookeeper

  1. tar -zxvf zookeeper-3.4.14.tar.gz
  2. mv zookeeper-3.4.14 /usr/local/zookeeper
  3. mkdir -p /usr/local/zookeeper/data
  4. mkdir -p /usr/local/zookeeper/log
  5. cd /usr/local/zookeeper/data/
  6. echo 1 > myid
  7. ----
  8. cd /usr/local/zookeeper/conf
  9. cp zoo_sample.cfg zoo.cfg
  10. vim zoo.cfg
  11. ----
  12. # 心跳时间
  13. tickTime=2000
  14. # follow连接leader的初始化连接时间,表示tickTime的倍数
  15. initLimit=10
  16. # syncLimit配置表示leader与follower之间发送消息,请求和应答时间长度。如果followe在设置的时间内不能与leader进行通信,那么此follower将被丢弃,tickTime的倍数
  17. syncLimit=5
  18. # 客户端连接端口
  19. clientPort=2181
  20. # 节点数据存储目录,需要提前创建,注意myid添加,用于标识服务器节点
  21. dataDir=/usr/local/zookeeper/data
  22. dataLogDir=/usr/local/zookeeper/log
  23. server.1=192.168.100.11:2888:3888
  24. server.2=192.168.100.12:2888:3888
  25. server.3=192.168.100.13:2888:3888
  26. ---
  27. -----
  28. scp -r zookeeper root@192.168.100.12:/usr/local/
  29. scp -r zookeeper root@192.168.100.13:/usr/local/
  30. 修改192.168.100.12 节点 myid
  31. cd /usr/local/zookeeper/data/
  32. echo 2 > myid
  33. 修改192.168.100.13 节点 myid
  34. cd /usr/local/zookeeper/data/
  35. echo 3 > myid

  1. 启动zookeeper
  2. cd /usr/local/zookeeper/bin/
  3. ./zkServer.sh start

image_1ejc05htc1dsi1o5p17jb1m1qdnfm.png-86.4kB

image_1ejc05tgefsc1duhudm129jjej13.png-84.2kB

image_1ejc06ada126la0moopte514v81g.png-91.3kB


四:安装kafka

4.1 安装kafka

  1. wget https://mirrors.bfsu.edu.cn/apache/kafka/2.3.1/kafka_2.12-2.3.1.tgz
  2. tar -zxvf kafka_2.12-2.3.1.tgz
  3. mv kafka_2.12-2.3.1 /usr/local/kafka

4.2 创建kafka logs 目录

  1. # kafka数据目录
  2. mkdir -p /usr/local/kafka/tmp/kafka-logs
  3. chmod -R a+w /usr/local/kafka/tmp/kafka-logs

4.3 配置server.propertie

  1. cat server.properties| egrep -v '^#|^*#|^$'
  2. ----
  3. broker.id=101 # 修改 broker.id
  4. listeners = PLAINTEXT://192.168.100.11:9092 ##侦听端口
  5. advertised.listeners=PLAINTEXT://192.168.100.11:9092 ##节点侦听端口
  6. num.network.threads=3
  7. num.io.threads=8
  8. socket.send.buffer.bytes=102400
  9. socket.receive.buffer.bytes=102400
  10. socket.request.max.bytes=104857600
  11. log.dirs=/usr/local/kafka/kafka-logs ## 日志目录
  12. num.partitions=1
  13. num.recovery.threads.per.data.dir=1
  14. offsets.topic.replication.factor=1
  15. transaction.state.log.replication.factor=1
  16. transaction.state.log.min.isr=1
  17. log.retention.hours=168
  18. log.segment.bytes=1073741824
  19. log.retention.check.interval.ms=300000
  20. zookeeper.connect=192.168.100.11:2181,192.168.100.12:2181,192.168.100.13:3181 ### zookeeper 地址
  21. zookeeper.connection.timeout.ms=6000
  22. group.initial.rebalance.delay.ms=0
  23. delete.topic.enable=true ### 删除属性
  24. ----

4.4 zookeeper.properties

  1. vim zookeeper.properties
  2. ---
  3. #Zookeeper的数据存储路径与Zookeeper集群配置保持一致
  4. dataDir=/usr/local/zookeeer/data
  5. ---

4.5 consumer.properties

  1. vim consumer.properties
  2. ---
  3. bootstrap.servers=192.168.100.11:9092,192.168.100.12:9092,192.168.100.13:9092
  4. #配置Zookeeper地址
  5. zookeeper.connect=192.168.100.11:2181,192.168.100.12:2181,192.168.100.13:2181
  6. # consumer group id
  7. group.id=test-consumer-group
  8. ---

4.6 producer.properties

  1. vim producer.properties
  2. ---
  3. bootstrap.servers=192.168.100.11:9092,192.168.100.12:9092,192.168.100.13:9092
  4. #配置Zookeeper地址
  5. zookeeper.connect=192.168.0.101:2181,192.168.0.102:2181,192.168.0.103:2181
  6. # specify the compression codec for all data generated: none, gzip, snappy, lz4, zstd
  7. compression.type=none
  8. ---

4.7 kafka-run-class.sh

  1. cd /usr/local/kafka/bin
  2. vim kafka-run-class.sh
  3. ---
  4. # 行首新增JAVA_HOME配置
  5. export JAVA_HOME=/usr/java/jdk1.8.0_191-amd64
  6. ---

4.8 分发机器

  1. scp -r kafka root@192.168.100.12:/usr/local/
  2. scp -r kafka root@192.168.100.13:/usr/local/

  1. 修改:192.168.100.12 server.properties
  2. vim server.properties
  3. ---
  4. broker.id=102
  5. listeners = PLAINTEXT://192.168.100.12:9092
  6. advertised.listeners=PLAINTEXT://192.168.100.12:9092
  7. ----
  8. 修改:192.168.100.13 server.properties
  9. vim server.properties
  10. ---
  11. broker.id=103
  12. listeners = PLAINTEXT://192.168.100.13:9092
  13. advertised.listeners=PLAINTEXT://192.168.100.13:9092
  14. ----

4.9 启动 kafka

  1. cd /usr/local/kafka/
  2. # 启动(每个节点)
  3. bin/kafka-server-start.sh config/server.properties >/dev/null 2>&1 &
  4. bin/kafka-server-start.sh -daemon config/server.properties
  5. # 停止(每个节点)
  6. bin/kafka-server-stop.sh config/server.properties

image_1ejc3kr0dvfc1um019shcdo1mp91t.png-141.9kB

image_1ejc3leg419mn1ib110g21823kkd2a.png-77.2kB

image_1ejc3m1ckegl1na71l791dbb1dnr2n.png-48.5kB


4.10 测试

  1. 创建topic。(任意Kafka集群节点)
  2. bin/kafka-topics.sh --zookeeper 192.168.100.11:2181,192.168.100.12:2181,192.168.100.13:2181 --create --topic test --replication-factor 1 --partitions 3

image_1ejc3pd2pucie0g162h1rl719gm34.png-55.8kB

  1. 查看topic
  2. bin/kafka-topics.sh --zookeeper 192.168.100.11:2181,192.168.100.12:2181,192.168.100.13:2181 --list

image_1ejc3udef1si9so716d918lgu2j41.png-40kB

  1. 生产者生成数据
  2. bin/kafka-console-producer.sh --broker-list 192.168.100.11:9092,192.168.100.12:9092,192.168.100.13:9092 --topic test

image_1ejc4602gpu61tec1i511h9r64c4e.png-66.1kB

  1. 消费者数据:
  2. # --from-beginning 从头开始消费,不加该参数则从最新的消息开始消费,之前的丢弃
  3. # --bootstrap-server 将在kafka集群上创建一个名称为“__consumer_offsets”的topic,50个分区,1个副本,用于存放消费者偏移量
  4. bin/kafka-console-consumer.sh --bootstrap-server 192.168.100.11:9092,192.168.100.12:9092,192.168.100.13:9092 --topic test --from-beginning

image_1ejc46fnq16at15h81pee10i11v964r.png-40.3kB

  1. bin/kafka-topics.sh --list --zookeeper 192.168.100.11:2181,192.168.100.12:2181,192.168.100.13:2181
  1. bin/kafka-topics.sh --describe --zookeeper 192.168.100.11:2181,192.168.100.12:2181,192.168.100.13:2181 --topic test

image_1ejc4kvlj1tp0qmf1gneegk18hp58.png-154.4kB


  1. 删除topic
  2. bin/kafka-topics.sh --delete --zookeeper 192.168.100.11:2181,192.168.100.12:2181,192.168.100.13:2181 --topic test

image_1ejc4qbujuph1mv9173g5501hu95l.png-59.7kB


五: 安装kafka Eagle

  1. wget https://codeload.github.com/smartloli/kafka-eagle-bin/tar.gz/v2.0.2
  2. tar -zxvf v2.0.2
  3. cd kafka-eagle-bin-2.0.2
  4. tar -zxvf kafka-eagle-web-2.0.2-bin.tar.gz
  5. mv kafka-eagle-web-2.0.2 /usr/local/eagle

  1. 环境变量配置
  2. vim /etc/profile
  3. ---
  4. export KE_HOME=/usr/local/eagle
  5. export PATH=$KE_HOME/bin:$PATH
  6. ----
  7. source /etc/profile

  1. 进入kafka-eagleconf目录下修改配置文件,配置基础配置
  2. # kafka集群配置
  3. kafka.eagle.zk.cluster.alias=cluster1
  4. cluster1.zk.list=192.168.100.11:2181,192.168.100.12:2181,192.168.100.13:2181
  5. # offset存储配置
  6. cluster1.kafka.eagle.offset.storage=kafka
  7. # 注释或删除以下一行配置
  8. cluster2.kafka.eagle.offset.storage=zk
  9. # 删除topic时需要使用的Token
  10. kafka.eagle.topic.token=polaris
  11. kafka.eagle.metrics.charts=true
  12. kafka.eagle.sql.fix.error=false
  13. kafka.eagle.webui.port=8048
  14. # jdbc配置
  15. kafka.eagle.driver=com.mysql.jdbc.Driver
  16. kafka.eagle.url=jdbc:mysql://192.168.100.11:3306/eagle?createDatabaseIfNotExist=true&amp
  17. kafka.eagle.username=root
  18. kafka.eagle.password=123456

  1. 开启Kafka JMX监控
  2. 修改Kafka各节点JMX启动配置,开启监控功能:
  3. cd /usr/local/kafka/bin
  4. vim kafka-server-start.sh
  5. ---
  6. if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
  7. export KAFKA_HEAP_OPTS="-server -Xms2G -Xmx2G -XX:PermSize=128m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:ParallelGCThreads=8 -XX:ConcGCThreads=5 -XX:InitiatingHeapOccupancyPercent=70"
  8. export JMX_PORT="9999"
  9. fi
  10. ---
  11. scp kafka-server-start.sh root@192.168.100.12:/usr/local/kafka/bin
  12. scp kafka-server-start.sh root@192.168.100.13:/usr/local/kafka/bin

image_1ejc6l5sr16ho137e5gv6ldsc9.png-77.2kB

  1. 验证Kafka Eagle
  2. cd /usr/local/eagle/bin
  3. ./eg.sh start

image_1ejcf9j6c1rlan5d1a3chil196r9.png-162.3kB

image_1ejcfc6nglsq1tp0ji7k3vpgq1m.png-224.5kB

image_1ejcfedia1t7vr5kc5vifqcml23.png-375kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注