标签:接收 信息 font 技术分享 状态 cal mod default 解压
Kafka依赖Zookeeper,虽然Kafka自带zookeeper,但是建议单独部署,所以先部署Zookeeper。
citus1,citus2,citus3三台机器。对主机名和ip在/etc/hosts文件中进行映射自行完成。
Zookeeper版本:zookeeper-3.4.6
vi zoo.cfg中修改配置,没有的添加:
tickTime=2000 dataDir=/var/lib/zookeeper clientPort=2181 initLimit=5 syncLimit=2 server.1=citus1:2888:3888 server.2=citus2:2888:3888 server.3=citus3:2888:3888
scp -r zookeeper-3.4.6 citus2:/opt/ scp -r zookeeper-3.4.6 citus3:/opt/
[root@citus1 opt]# mkdir /var/lib/zookeeper [root@citus1 opt]# echo "1" > /var/lib/zookeeper/myid [root@citus2 opt]# mkdir /var/lib/zookeeper [root@citus2 opt]# echo "2" > /var/lib/zookeeper/myid [root@citus3 opt]# mkdir /var/lib/zookeeper [root@citus3 opt]# echo "3" > /var/lib/zookeeper/myid
[root@citus1 zookeeper-3.4.6]# bin/zkServer.sh start JMX enabled by default Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@citus2 zookeeper-3.4.6]# bin/zkServer.sh start JMX enabled by default Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@citus3 zookeeper-3.4.6]# bin/zkServer.sh start JMX enabled by default Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
[root@citus1 zookeeper-3.4.6]# bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg Mode: follower [root@citus1 zookeeper-3.4.6]# bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg Mode: leader [root@citus1 zookeeper-3.4.6]# bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg Mode: follower
tar -xzvf kafka_2.10-0.10.2.1.tgz -C /opt vi /opt/kafka_2.10-0.10.2.1/config/server.properties
修改zookeeper配置如下:
Broker.id为当前机器在集群中的唯一标识,每台服务器的broker.id都不能相同。
scp -r kafka_2.10-0.10.2.1/ citus2:/opt scp -r kafka_2.10-0.10.2.1/ citus3:/opt
citus2上修改broker.id为1
citus3上修改broker.id为2
每台机器都执行:
bin/kafka-server-start.sh config/server.properties &
新建一个topic:
./bin/kafka-topics.sh --zookeeper citus1:2181,citus2:2181,citus3:2181 --topic test --replication-factor 2 --partitions 5 --create
查看当前topic:
./bin/kafka-topics.sh --zookeeper citus1:2181,citus2:2181,citus3:2181 --list
在一个节点创建一个producer:
./bin/kafka-console-producer.sh --broker-list citus1:9092,citus2:9092,citus3:9092 --topic test
在另外一个节点创建consumer:
./bin/kafka-console-consumer.sh --zookeeper citus1:2181,citus2:2181,citus3:2181 --from-beginning -topic test
在producer端输入信息,在consumer端能接收到信息。
标签:接收 信息 font 技术分享 状态 cal mod default 解压
原文地址:http://www.cnblogs.com/zeppelin/p/6958758.html