JDK 环境(略)
使用vim /etc/profile
添加环境变量
JAVA_HOME=/usr/java/jdk1.8.0_161
JRE_HOME=/usr/java/jdk1.8.0_161/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
source /etc/profile
echo $PATH
ZooKeeper
https://zookeeper.apache.org/releases.html#download
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0.tar.gz
tar -zxvf zookeeper-3.8.0.tar.gz
mv zookeeper-3.8.0 /usr/local/zookeeper
cd /usr/local/zookeeper/conf/
cp zoo_sample.cfg zoo.cfg
修改配置文件vim zoo.cfg
#ZooKeeper 服务器心跳时间,单位为 ms
tickTime=2000
# 允许 follower 连接并同步到 leader 的初始化连接时间,以 tickTime 的倍数来表示
initLimit=10
#leader 与 follower 心跳检测最大容忍时间,响应超过 syncLimit*tickTime,leader 认为 follower “死掉”,从服务器列表中删除 follower
syncLimit=5
#数据目录
dataDir=/data/zookeeper/data
#日志目录
dataLogDir=/data/zookeeper/log
#ZooKeeper 对外服务端口
clientPort=2181
#创建数据、日志文件夹
mkdir /data/zookeeper/data
mkdir /data/zookeeper/log
cd /usr/local/zookeeper/bin/
sh zkServer.sh start
sh zkServer.sh status
echo stat | nc localhost 2181
Kafka
https://kafka.apache.org/downloads.html
wget https://archive.apache.org/dist/kafka/2.4.0/kafka_2.12-2.4.0.tgz
tar -zxvf kafka_2.12-2.4.0.tgz
mv kafka-2.12-2.4.0 /usr/local/kafka
vim /usr/local/kafka/conf/server.properties
修改配置文件server.properties
#broker 的编号,如果集群中有多个 broker,则每个 broker 的编号需要设置的不同
broker.id=0
#broker 对外提供的服务入口地址
listeners=PLAINTEXT://localhost:9092
#存放消息日志文件的地址
log.dirs=/data/kafka/log
#ZooKeeper 集群地址
zookeeper.connect=192.168.10.1:2181,192.168.10.2:2181,192.168.10.3:2181,
mkdir -p /data/kafka/log
kafka-server-start.sh config/server.properties &
消息传输
#创建 topic
kafka-topics.sh --zookeeper localhost:2181 --create --topic topic-demo --replication-factor 1 --partitions 4
#查看 topic
kafka-topics.sh --zookeeper localhost:2181 --describe --topic topic-demo
#创建消费者
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic-demo
#创建生产者
kafka-console-producer.sh --broker-list localhost:9092 --topic topic-demo
>Hello, Kafka!