mac安装包安装zookeeper和kafka

1.安装ZooKeeper 3.6.1
官网下载最新版的zookeeper

https://zookeeper.apache.org/...

  • 给/opt目录赋予当前用户的权限
sudo chown -R ${USER}:${USER} /opt
  • 将下载好的zooKeeper安装包copy到/opt下面并解压
cp ~/Downloads/apache-zookeeper-3.6.1-bin.tar.gz /opt
tar xvf apache-zookeeper-3.6.1-bin.tar.gz
  • 将zookeeper目录下的conf里的zoo_sample.cfg拷贝命名为zoo.cfg
cd /opt/apache-zookeeper-3.6.1-bin/conf
cp zoo_sample.cfg zoo.cfg
  • 修改系统环境变量~/.zshrc
vim ~/.zshrc
export zk=/opt/apache-zookeeper-3.6.1-bin
export PATH=$PATH:$zk/bin
  • 启动zookeeper
zkServer.sh start
menglong@menglong conf % zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/apache-zookeeper-3.6.1-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
  • jps查看zookeeper是否启动
jps
menglong@menglong conf % jps
1410 QuorumPeerMain
1432 Jps

2.安装kafka2.5.0
官网下载最新版的kafka
http://kafka.apache.org/downl...

  • 将下载好的zooKeeper安装包copy到/opt下面并解压
cp ~/Downloads/kafka_2.12-2.5.0.tgz /opt
tar xvf kafka_2.12-2.5.0.tgz
  • 修改server.properties
cd /opt/kafka_2.12-2.5.0/config
vim server.properties
查找到#advertised.listeners=PLAINTEXT://your.host.name:9092

修改为advertised.listeners=PLAINTEXT://localhost:9092

  • 修改系统环境变量~/.zshrc
vim ~/.zshrc
export zk=/opt/apache-zookeeper-3.6.1-bin
export kafka=/opt/kafka_2.12-2.5.0
export PATH=$PATH:$zk/bin:$kafka/bin
  • 启动kafka
nohup kafka-server-start.sh config/server.properties&
  • 查看kafka启动
jps
menglong@menglong kafka_2.12-2.5.0 % jps
1410 QuorumPeerMain
2052 Jps
1733 Kafka

3.创建topic test

kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 5 --topic test

4.使用test topic生产数据

menglong@menglong kafka_2.12-2.5.0 % kafka-console-producer.sh --broker-list localhost:9092 --topic test
>this is my first message

5.使用test topic消费数据

menglong@menglong kafka_2.12-2.5.0 % jps
4689 Kafka
1410 QuorumPeerMain
6297 ConsoleProducer
6623 Jps
menglong@menglong kafka_2.12-2.5.0 % kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test
this is my first message

你可能感兴趣的:(kafka)