默认三台机器已经安装java,设置好ssh免密连接。
集群hosts文件:
1.下载kafka
http://kafka.apache.org/downl...
2.发送到集群解压到指定目录/usr/local下
tar -zxvf kafka_2.11-0.10.0.1.tar.gz -C /usr/local
3.进入kafka_2.11-0.10.0.1目录,创建文件夹zk_kfk_data(自取)
,并在该目录下创建myid文件,内容在三个集群中不同,分别是1,2,3
cd kafka_2.11-0.10.0.1
mkdir zk_kfk_data
vi myid
4.创建目录
mkdir logs
mkdir kafka-logs-1
5.修改/config/zookeeper.properties文件
cd config
vi zookeeper.properties
6.修改server.properties
vi server.properties
7.把kafka整个文件夹分发给两个子节点
scp -r /usr/local/kafka_2.11-0.10.1.1 hadoop@centos2:/usr/local
scp -r /usr/local/kafka_2.11-0.10.1.1 hadoop@centos3:/usr/local
8.修改centos2和centos3的myid
ssh centos2
cd /usr/local/kafka_2.11-0.10.1.1/zk_kfk_data
vi myid
ssh centos3
cd /usr/local/kafka_2.11-0.10.1.1/zk_kfk_data
vi myid
9.修改centos2和centos3的server.properties
ssh centos2
cd /usr/local/kafka_2.11-0.10.1.1/config
vi server.properties
ssh centos3
cd /usr/local/kafka_2.11-0.10.1.1/config
vi server.properties
安装完成!
运行测试:(默认在/usr/local/kafka_2.11-0.10.1.1目录下执行)
10.三台集群分别启动zk:
./bin/zookeeper-server-start.sh config/zookeeper.properties &
或
nohup ./bin/zookeeper-server-start.sh config/zookeeper.properties &>> zookeeper.log &
11.启动kafka集群
nohup ./bin/kafka-server-start.sh config/server.properties &>> kafka.log &
12.创建topic:
./bin/kafka-topics.sh --create --zookeeper centos1:2181,centos2:2181,centos3:2181 --replication-factor 1 --partitions 1 --topic test
13.查看topic:
./bin/kafka-topics.sh --list --zookeeper localhost:2181
14.发送数据:
./bin/kafka-console-producer.sh --broker-list centos1:9092,centos2:9092,centos3:9092 --topic test
15.消费:
./bin/kafka-console-consumer.sh --zookeeper centos1:2181,centos2:2181,centos3:2181 --from-beginning --topic test
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。