您好,登錄后才能下訂單哦!
一、環境配置
1.系統環境
[root@date ~]# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core)
2..安裝JAVA環境
yum -y install java java-1.8.0-openjdk-devel #jps需要jdk-devel支持
3.下載kafka
[root@slave1 ~]# ls kafka_2.11-1.0.0.tgz kafka_2.11-1.0.0.tgz
二、配置zookeeper
1.修改kafka中zookeeper的配置文件
[root@slave1 ~]# cat /opt/kafka/config/zookeeper.properties | grep -v "^$" | grep -v "^#" tickTime=2000 initLimit=10 syncLimit=5 maxClientCnxns=300 dataDir=/opt/zookeeper/data dataLogDir=/opt/zookeeper/log clientPort=2181 server.1=20.0.5.11:2888:3888 server.2=20.0.5.12:2888:3888 server.3=20.0.5.13:2888:3888
2.復制配置文件到其他節點
[root@slave1 ~]# pscp.pssh -h zlist /opt/kafka/config/zookeeper.properties /opt/kafka/config/ [root@slave1 ~]# cat zlist 20.0.5.11 20.0.5.12 20.0.5.13
3.在各個節點創建數據和日志目錄
[root@slave1 ~]# pssh -h zlist 'mkdir /opt/zookeeper/data' [root@slave1 ~]# pssh -h zlist 'mkdir /opt/zookeeper/log'
4.創建myid文件
[root@slave1 ~]# pssh -H slave1 -i 'echo 1 > /opt/zookeeper/data/myid' [root@slave1 ~]# pssh -H slave2 -i 'echo 2 > /opt/zookeeper/data/myid' [root@slave1 ~]# pssh -H slave3 -i 'echo 3 > /opt/zookeeper/data/myid'
5.啟動zookeeper
[root@slave1 ~]# pssh -h zlist 'nohup /opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties &' [root@slave1 ~]# pssh -h zlist -i 'jps' [1] 23:29:36 [SUCCESS] 20.0.5.12 3492 QuorumPeerMain 3898 Jps [2] 23:29:36 [SUCCESS] 20.0.5.11 7369 QuorumPeerMain 9884 Jps [3] 23:29:36 [SUCCESS] 20.0.5.13 3490 QuorumPeerMain 3898 Jps
三、配置kafka
1.修改server.properties
[root@slave1 ~]# cat /opt/kafka/config/server.properties broker.id=1 #機器唯一標識 host.name=20.0.5.11 #當前broker機器ip port=9092 #broker監聽端口 num.network.threads=3 #服務器接受請求和響應請求的線程數 num.io.threads=8 #io線程數 socket.send.buffer.bytes=102400 #發送緩沖區大小,數據先存儲到緩沖區了到達一定的大小后在發送 socket.receive.buffer.bytes=102400 #接收緩沖區大小,達到一定大小后序列化到磁盤 socket.request.max.bytes=104857600 #向kafka請求消息或者向kafka發送消息的請求的最大數 log.dirs=/opt/kafkalog #消息存放目錄 delete.topic.enable=true #能夠通過命令刪除topic num.partitions=1 #默認的分區數,一個topic默認1個分區數 num.recovery.threads.per.data.dir=1 #設置恢復和清理超時數據的線程數量 offsets.topic.replication.factor=3 #用于配置offset記錄的topic的partition的副本個數 transaction.state.log.replication.factor=3 transaction.state.log.min.isr=3 log.retention.hours=168 #消息保存時間 log.segment.bytes=1073741824 #日志文件最大值,當日志文件的大于最大值,則創建一個新的 log.retention.check.interval.ms=300000 #日志保留檢查間隔 zookeeper.connect=20.0.5.11:2181,20.0.5.12:2181,20.0.5.13:2181 #zookeeper地址 zookeeper.connection.timeout.ms=6000 #連接zookeeper超時時間
2.復制broke配置文件到其他服務節點上(修改broker.id和host.name)
3.啟動kafka broke
[root@slave1 ~]# pssh -h zlist '/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties > /root/kafka.log 2>1&' [1] 02:13:05 [SUCCESS] 20.0.5.11 [2] 02:13:05 [SUCCESS] 20.0.5.12 [3] 02:13:05 [SUCCESS] 20.0.5.13 [root@slave1 ~]# pssh -h zlist -i 'jps' [1] 02:14:51 [SUCCESS] 20.0.5.12 3492 QuorumPeerMain 6740 Jps 6414 Kafka [2] 02:14:51 [SUCCESS] 20.0.5.13 3490 QuorumPeerMain 4972 Kafka 5293 Jps [3] 02:14:51 [SUCCESS] 20.0.5.11 7369 QuorumPeerMain 11534 Kafka 11870 Jps
4.創建topic
[root@slave1 ~]# /opt/kafka/bin/kafka-topics.sh --create --zookeeper 20.0.5.11:2181,20.0.5.12:2181,20.0.5.13:2181 --replication-factor 3 --partitions 3 --topic test1 Created topic "test1". [root@slave1 ~]# /opt/kafka/bin/kafka-topics.sh --describe --zookeeper 20.0.5.11:2181,20.0.5.12:2181,20.0.5.13:2181 --topic test1 Topic:test1 PartitionCount:3 ReplicationFactor:3 Configs: Topic: test1 Partition: 0 Leader: 2 Replicas: 2,3,1 Isr: 2,3,1 Topic: test1 Partition: 1 Leader: 3 Replicas: 3,1,2 Isr: 3,1,2 Topic: test1 Partition: 2 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3
5.啟動producer和consumer
[root@slave4 ~]# /opt/kafka/bin/kafka-console-producer.sh --broker-list 20.0.5.12:9092 --topic test1 [root@slave5 ~]# /opt/kafka/bin/kafka-console-consumer.sh --zookeeper 20.0.5.13:2181 --topic test1
6.刪除topic
[root@slave1 ~]# /opt/kafka/bin/kafka-topics.sh --delete --zookeeper 20.0.5.11:2181 --topic test1 Topic test1 is marked for deletion. Note: This will have no impact if delete.topic.enable is not set to true.
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。