Harvey Jhuang
Backend Engineer, Golang Developer
Kafka is a distributed message system with these metrics:
Round-robin
Randomness
Key-ordering
A topic is a category or feed name to which records are published.
Name | Description | Value |
---|---|---|
broker.id | unique and permanent name of each node in the cluster | 1 |
log.dirs | The directories in which the log data is kept. If not set, the value in log.dir is used | /kafka/data |
zookeeper.connect | Specifies the ZooKeeper connection | zk1:2181,zk2:2181,zk3:2181 |
listeners | list of URIs we will listen on | host:9092 |
advertised.listeners | Listeners to publish to ZooKeeper for clients to use | host:9092 |
unclean.leader.election.enable | Indicates whether to enable replicas not in the ISR set to be elected as leader | false |
log.retention.{hours|minutes|ms} | The number of {hours|minutes|ms} to keep a log file before deleting it | 48 |
auto.leader.rebalance.enable | A background thread checks and triggers leader balance if required at regular intervals | false |
max.message.bytes | The largest record batch size allowed by Kafka. | 104857600 (100mb) |
default.replication.factor | default replication factors for automatically created topics | >3 |
min.insync.replicas | specifies the minimum number of replicas that must acknowledge a write for the write to be considered successful. | >1 |
# install tools
yum -y install which wget nc net-tools
# install jdk
yum -y install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64
# java home
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
# get zk from web
wget "${ZOOKEEPER_URL}" -O "/tmp/${ZOOKEEPER_FILENAME}"
# install zookeeper
tar xfz /tmp/${ZOOKEEPER_FILENAME} -C /opt
# add zookeeper config (add all zk node ip)
cp /opt/zookeeper/conf/zoo_sample.cfg /opt/zookeeper/conf/zoo.cfg
# add myid file for zookeeper
touch /zookeeper/log/myid
echo $NODE_ID >> /zookeeper/log/myid
# start zk
/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
# [4 letter words]
echo [word] | nc localhost 2181
conf : Print details about serving configuration.
cons : List full connection/session details for all clients connected to this server.
crst : Reset connection/session statistics for all connections.
dump : Lists the outstanding sessions and ephemeral nodes.
This only works on the leader.
envi : Print details about serving environment
ruok : Tests if server is running in a non-error state.
The server will respond with imok
if it is running. Otherwise it will not respond at all.
srst : Reset server statistics.
srvr : Lists full details for the server.
stat : Lists brief details for the server and connected clients.
wchs : Lists brief information on watches for the server.
mntr : Outputs a list of variables that could be used for monitoring the health
of the cluster.
# example
echo srvr | nc localhost 2181
# install tools
yum -y install which wget nc net-tools
# install jdk
yum -y install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64
# java home
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
# Get Kafka From web
wget "${KAFKA_URL}" -O "/tmp/${KAFKA_FILENAME}"
# install kafka
tar xfz /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C /opt
# edit config/server.properties (listener, zookeeper.connect)
cp /opt/kafka/config/server.properties /opt/kafka/config/server-default.properties
# start setting your broker cfg (plz follow previous slides)
vi /opt/kafka/config/server.properties
# start kafka
/opt/kafka/bin/kafka-server-start.sh -daemon /opt/kafka/config/server.properties
# check kafka cluster size
echo dump | nc 10.200.252.232 2181 | grep brokers
# test create topic
/opt/kafka/bin/kafka-topics.sh --zookeeper {{zks_ip:2181}} --create --topic {{name}}
--partitions 3 --replication-factor 3
# list topic
/opt/kafka/bin/kafka-topics.sh --zookeeper {{zks_ip:2181}} --list
# show topic detail
/opt/kafka/bin/kafka-topics.sh --zookeeper {{zks_ip:2181}} --describe --topic {{name}}
# produce msg to topic
/opt/kafka/bin/kafka-console-producer.sh --broker-list {{kas_ip:9092}} --topic {{name}}
# consuming msg from topic
/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server {{kas_ip:9092}}
--topic {{name}} --group {{name}} --from-beginning
--consumer-property enable.auto.commit=false
Kafka Basic Concept
Overview
Broker
Producer
Consumer
Topic
Zookeeper
How to install
Install Zookeeper Cluster
Install Kafka
Most Important Properties
Demonstration: Horizontally scalable
Name | Description | Value |
---|---|---|
broker.id | unique and permanent name of each node in the cluster | 1 |
log.dirs | The directories in which the log data is kept. If not set, the value in log.dir is used | /kafka/data |
zookeeper.connect | Specifies the ZooKeeper connection | zk1:2181,zk2:2181,zk3:2181 |
listeners | list of URIs we will listen on | host:9092 |
advertised.listeners | Listeners to publish to ZooKeeper for clients to use | host:9092 |
unclean.leader.election.enable | Indicates whether to enable replicas not in the ISR set to be elected as leader | false |
log.retention.{hours|minutes|ms} | The number of {hours|minutes|ms} to keep a log file before deleting it | 48 |
auto.leader.rebalance.enable | A background thread checks and triggers leader balance if required at regular intervals | false |
max.message.bytes | The largest record batch size allowed by Kafka. | 104857600 (100mb) |
default.replication.factor | default replication factors for automatically created topics | >3 |
min.insync.replicas | specifies the minimum number of replicas that must acknowledge a write for the write to be considered successful. | >1 |
By Harvey Jhuang
Kafka basic concept and use