• 让天下没有难学的技术
    多数学员都来自推荐,这就是口碑的力量

kafka安装

一、安装JDK

yum install java-1.8.0-openjdk* -y

二、安装Zookeeper

进入到/home目录下,下载zookeeper

wget https://archive.apache.org/dist/zookeeper/zookeeper-3.5.8/apache-zookeeper-3.5.8-bin.tar.gz

tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz

cd apache-zookeeper-3.5.8-bin/

cp conf/zoo_sample.cfg conf/zoo.cfg

cd /home/apache-zookeeper-3.5.8-bin/bin

./zkServer.sh start

./zkCli.sh

ls /

打印结果:

[zk: localhost:2181(CONNECTED) 5] ls /

[admin, brokers, cluster, config, consumers, controller, controller_epoch, isr_change_notification, kafka, latest_producer_id_block, log_dir_event_notification, zookeeper]

[zk: localhost:2181(CONNECTED) 6]

三、安装Kafka

进入到/home目录下,下载kafka

wget https://archive.apache.org/dist/kafka/2.4.1/kafka_2.11-2.4.1.tgz

tar -xzf kafka_2.11-2.4.1.tgz

cd /home/kafka_2.11-2.4.1/config

vim config/server.properties

配置文件编辑

#broker.id属性在kafka集群中必须要是唯一

broker.id=0

#kafka部署的机器ip和提供服务的端口号

listeners=PLAINTEXT://内网ip:9092

#kafka的消息存储文件

log.dir=/usr/local/data/kafka-logs

#kafka连接zookeeper的地址

zookeeper.connect=内网ip:2181

如果填写外网ip可能会遇上这种情况:

四、启动并验证kafka

启动kafka

/home/kafka_2.11-2.4.1/bin/kafka-server-start.sh config/server.properties &

进入zookeeper目录通过zookeeper客户端查看下zookeeper的目录树

/home/apache-zookeeper-3.5.8-bin/bin/zkCli.sh

ls /

ls /brokers/ids

校验kafka

创建主题

/home/kafka_2.11-2.4.1/bin/kafka-topics.sh –create –zookeeper 106.14.132.94:2181 –replication-factor 1 –partitions 1 –topic test

查看kafka中目前存在的topic

/home/kafka_2.11-2.4.1/bin/kafka-topics.sh –list –zookeeper 106.14.132.94:2181

发送消息

/home/kafka_2.11-2.4.1/bin/kafka-console-producer.sh –broker-list 106.14.132.94:9092 –topic test

this is a msg

消费消息

/home/kafka_2.11-2.4.1/bin/kafka-console-consumer.sh –bootstrap-server 106.14.132.94:9092–topic test

消费之前的消息

/home/kafka_2.11-2.4.1/bin/kafka-console-consumer.sh –bootstrap-server 106.14.132.94:9092 –from-beginning –topic test

通过jps命令查看运行的情况

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注