列出 topic:
kafka-topics.sh --bootstrap-server 1.1.1.1:8100 --list
控制台消费者:
kafka-console-consumer.sh --bootstrap-server 1.1.1.1:8100 --topic nba --from-beginning
手动设置 offset:
kafka-consumer-groups.sh --bootstrap-server 1.1.1.1:8100 --list
kafka-consumer-groups.sh --bootstrap-server 1.1.1.1:8100 --group china --describe
kafka-consumer-groups.sh --bootstrap-server 1.1.1.1:8100 --group china -topic nba --reset-offsets --to-latest --execute
zookeeper
➜ bin ./zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2023-01-11 16:35:35,435 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.6.4--d65253dcf68e9097c6e95a126463fd5fdeb4521c, built on 12/18/2022 18:10 GMT
2023-01-11 16:35:35,446 [myid:] - INFO [main:Environment@98] - Client environment:host.name=0.0.1.1
2023-01-11 16:35:35,447 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_333
2023-01-11 16:35:35,447 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2023-01-11 16:35:35,447 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_333.jdk/Contents/Home/jre
......
[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[jcloud-cap-db-dbs-stag-stag, sanguo, zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 2]
[zk: 127.0.0.1:2181(CONNECTED) 2] ls /sanguo // 查看目录 ls -R /sanguo 递归显示
[jin, jin1, shuguao, weiguo, wuguo]
[zk: 127.0.0.1:2181(CONNECTED) 3]
[zk: 127.0.0.1:2181(CONNECTED) 3]
[zk: 127.0.0.1:2181(CONNECTED) 3] get /sanguo // 获取当前节点的值
diaochan
[zk: 127.0.0.1:2181(CONNECTED) 4]
节点的监控:
控制台1:
[zk: 127.0.0.1:2181(CONNECTED) 4] ls -w /sanguo // 监控 /sanguo 目录的变化,递归监控 ls -R -w /sanguo; get -w /sanguo 监控值的变化
[jin, jin1, shuguao, weiguo, wuguo]
[zk: 127.0.0.1:2181(CONNECTED) 5]
WATCHER::
WatchedEvent state:SyncConnected type:NodeChildrenChanged path:/sanguo
[zk: 127.0.0.1:2181(CONNECTED) 5]
[zk: 127.0.0.1:2181(CONNECTED) 5] ls /sanguo
[jin, jin1, jin2, shuguao, weiguo, wuguo]
[zk: 127.0.0.1:2181(CONNECTED) 6]
控制台2:
[zk: 127.0.0.1:2181(CONNECTED) 9] create /sanguo/jin2 "simayi" //创建节点
Created /sanguo/jin2
[zk: 127.0.0.1:2181(CONNECTED) 10]
上面提到的 ls -w /sanguo 和 get -w /sanguo 都只能监听到一次变化就不监听了,而永久监听的命令:
addWatch -m PERSISTENT_RECURSIVE /sanguo