大数据集群搭建—《kafka(集群)篇》 --菜鸟小回
- 创建:
mkdir -p /opt/kafka
- 进入:
cd /opt/kafka
- 上传
- 解压:
tar -zxvf kafka_2.12-1.1.0.tgz
- 修改配置文件 server.properties
cd /opt/kafka/kafka_2.12-1.1.0/config/
vi server.properties
//修改broker.id
broker.id=1
//修改zookeeper
zookeeper.connect=zhiyou001:2181,zhiyou002:2181,zhiyou003:2181
//文件最后添加host.name
host.name=zhiyou001
- 复制到其他节点
scp -r /opt/kafka/ root@zhiyou002:/opt/kafka/
scp -r /opt/kafka/ root@zhiyou003:/opt/kafka/
- 更改其他节点先的broker.id和host.name
zhiyou002 的 broker.id=02
host.name=zhiyou02
zhiyou003 的 broker.id=03
Host.name=zhiyou03 - 先启动zookeeper (3台)
//启动zookeeper(三台)
cd /opt/zookeeper/zookeeper-3.4.12/bin/
./zkServer.sh start
- 再启动kafka (3台)
cd /opt/kafka/kafka_2.12-1.1.0
./bin/kafka-server-start.sh -daemon config/server.properties &
- 创建主题(主机)
./bin/kafka-topics.sh --create --zookeeper zhiyou01:2181,zhiyou02:2181,zhiyou03:2181 --replication-factor 3 --partitions 3 --topic test
- 启动生产者
./bin/kafka-console-producer.sh --broker-list zhiyou001:9092, zhiyou002:9092, zhiyou003:9092 --topic test
//可以在此之后写入内容等待消费者
./bin/kafka-console-producer.sh --broker-list zhiyou01:9092, zhiyou02:9092, zhiyou03:9092 --topic test
- 启动消费者(从节点)
./bin/kafka-console-consumer.sh --bootstrap-server zhiyou001:9092, zhiyou002:9092, zhiyou003:9092 --from-beginning --topic test
- 测试: 从生成者输入消息,在消费者查看消息