kafkazookeeper配置初步-创新互联
1.软件需求
创新互联服务项目包括内乡网站建设、内乡网站制作、内乡网页制作以及内乡网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,内乡网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到内乡省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!CentOS 7.2 X64
jdk-8u121-linux-x64.rpm
zookeeper-3.4.9.tar.gz
kafka_2.11-0.10.1.0.tgz
setuptools-33.1.1.zip
kafka-python-1.3.2.tar.gz
2.安装zookeeper、kafka
1).zookeeper
# tar -zxf zookeeper-3.4.9.tar.gz
# mv zookeeper-3.4.9 /usr/local/zookeeper
# mkdir -p /var/lib/zookeeper
# cat > /usr/local/zookeeper/conf/zoo.cfg << EOF
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
EOF
# /usr/local/zookeeper/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
#
2).kafka
# tar -zxf kafka_2.11-0.10.1.0.tgz
# mv kafka_2.11-0.10.1.0 /usr/local/kafka
# mkdir /tmp/kafka-logs
# /usr/local/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic telematics
fCreated topic "telematics".
#
3.create topics
# /usr/local/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic telematics
4.topic操作
1).list topic
# /usr/local/kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --list
telematics
2).describe topic
# /usr/local/kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic telematics
Topic:telematics PartitionCount:1 ReplicationFactor:1 Configs:
Topic: telematics Partition: 0 Leader: 0 Replicas: 0 Isr: 0
#
3).delete topic
#/usr/local/kafka/bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic telematics
5.添加选项执行删除命令时生效,否则只是标记为删除
/usr/local/kafka/config/server.properties
delete.topic.enable=true
6.测试脚本
1). producer.py
#!/usr/bin/python
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='192.168.1.201:9092')
producer = KafkaProducer(key_serializer=str.encode, value_serializer=str.encode)
producer.send('telematics', key='ping', value=b'1234')
#
2). consumer.py
from kafka import KafkaConsumer
# To consume latest messages and auto-commit offsets
consumer = KafkaConsumer('telematics',bootstrap_servers=['192.168.1.201:9092'])
for message in consumer:
# message value and key are raw bytes -- decode if necessary!
# e.g., for unicode: `message.value.decode('utf-8')`
print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
message.offset, message.key,
message.value))
#
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享题目:kafkazookeeper配置初步-创新互联
新闻来源:http://myzitong.com/article/dcecps.html