1. First, install ZooKeeper

  2. Modify the kafka server.properties file

    Number of brokers. If there are multiple brokers in a cluster, the number of each broker needs to be set differently
    broker.id=0
    # Broker specifies the address of the external service
    listeners=PLAINTEXT: / / 192.168.94.151:9092
    The address where the message log file is stored
    log.dirs=/ opt/module/kafka_2. 12-2.3.1 / logs /
    # kafka specifies the zooKeeper cluster address
    zookeeper.connect=192.168.94.151:2181 / kafka
    Copy the code
  3. Single machine start

    / opt/module/kafka_2. 12-2.3.1 / bin/kafka - server - start. Sh - daemon/opt/module/kafka_2 12-2.3.1 / config/server propertiesCopy the code
  4. Create a theme

    Number of partitions 2, copy factor 1 (only one broker)

    [[email protected] kafka_2. 12-2.3.1] $kafka - switchable viewer. Sh - zookeeper 192.168.94.151:2181 / kafka - create topic topic-demo01 --replication-factor 1 --partitions 2 Created topic topic-demo01.Copy the code
  5. Viewing Topic Details

    [[email protected] kafka_2. 12-2.3.1] $kafka - switchable viewer. Sh - zookeeper 192.168.94.151:2181 / kafka - go - the topic topic-demo01 Topic:topic-demo01 PartitionCount:2 ReplicationFactor:1 Configs: Topic: topic-demo01 Partition: 0 Leader: 0 Replicas: 0 Isr: 0 Topic: topic-demo01 Partition: 1 Leader: 0 Replicas: 0 Isr: 0Copy the code
  6. Receives the message

    [[email protected] ~]$kafka-console-consumer.sh --bootstrap-server 192.168.94.151:9092 --topic -- demo01Copy the code

    –bootstrap-server specifies the kafka cluster address to connect to, and –topic specifies the topic to which the consumer subscribs

  7. Send a message

    [[email protected] ~]$kafka-console-producer.sh --bootstrap-server 192.168.94.151:9092 --topic -- demo01Copy the code

    –broker-list is obsolete, use –bootstrap-server

  8. Modifying JVM parameters

    Example Modify the bin/kafka-run-class.sh file

    #The default
    if [ -z "$KAFKA_HEAP_OPTS" ]; then
      KAFKA_HEAP_OPTS="-Xmx256M"
    fi
    Copy the code
  9. Open the Jmx

    Can access monitoring

    Kafka enables JMX in two ways:

    JMX_PORT=9988 when kafka is started JMX_PORT=9988 bin/kafka-server-start.sh -daemon config/server.properties Modify the kafka-run-class.sh script to add JMX_PORT=9988.