JDK 环境(略)

使用vim /etc/profile添加环境变量

  1. JAVA_HOME=/usr/java/jdk1.8.0_161
  2. JRE_HOME=/usr/java/jdk1.8.0_161/jre
  3. PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
  4. CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
  5. export JAVA_HOME JRE_HOME PATH CLASSPATH
  1. source /etc/profile
  2. echo $PATH

ZooKeeper

https://zookeeper.apache.org/releases.html#download
image.png

  1. wget https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0.tar.gz
  2. tar -zxvf zookeeper-3.8.0.tar.gz
  3. mv zookeeper-3.8.0 /usr/local/zookeeper
  4. cd /usr/local/zookeeper/conf/
  5. cp zoo_sample.cfg zoo.cfg

修改配置文件vim zoo.cfg

  1. #ZooKeeper 服务器心跳时间,单位为 ms
  2. tickTime=2000
  3. # 允许 follower 连接并同步到 leader 的初始化连接时间,以 tickTime 的倍数来表示
  4. initLimit=10
  5. #leader 与 follower 心跳检测最大容忍时间,响应超过 syncLimit*tickTime,leader 认为 follower “死掉”,从服务器列表中删除 follower
  6. syncLimit=5
  7. #数据目录
  8. dataDir=/data/zookeeper/data
  9. #日志目录
  10. dataLogDir=/data/zookeeper/log
  11. #ZooKeeper 对外服务端口
  12. clientPort=2181
  1. #创建数据、日志文件夹
  2. mkdir /data/zookeeper/data
  3. mkdir /data/zookeeper/log
  4. cd /usr/local/zookeeper/bin/
  5. sh zkServer.sh start
  6. sh zkServer.sh status
  7. echo stat | nc localhost 2181

Kafka

https://kafka.apache.org/downloads.html

  1. wget https://archive.apache.org/dist/kafka/2.4.0/kafka_2.12-2.4.0.tgz
  2. tar -zxvf kafka_2.12-2.4.0.tgz
  3. mv kafka-2.12-2.4.0 /usr/local/kafka
  4. vim /usr/local/kafka/conf/server.properties

修改配置文件server.properties

  1. #broker 的编号,如果集群中有多个 broker,则每个 broker 的编号需要设置的不同
  2. broker.id=0
  3. #broker 对外提供的服务入口地址
  4. listeners=PLAINTEXT://localhost:9092
  5. #存放消息日志文件的地址
  6. log.dirs=/data/kafka/log
  7. #ZooKeeper 集群地址
  8. zookeeper.connect=192.168.10.1:2181,192.168.10.2:2181,192.168.10.3:2181,
  1. mkdir -p /data/kafka/log
  2. kafka-server-start.sh config/server.properties &

消息传输

  1. #创建 topic
  2. kafka-topics.sh --zookeeper localhost:2181 --create --topic topic-demo --replication-factor 1 --partitions 4
  3. #查看 topic
  4. kafka-topics.sh --zookeeper localhost:2181 --describe --topic topic-demo
  5. #创建消费者
  6. kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic-demo
  7. #创建生产者
  8. kafka-console-producer.sh --broker-list localhost:9092 --topic topic-demo
  9. >Hello, Kafka!