vim /etc/profile
在最后面添加:
export JAVA_HOME=/app/jdk-12.0.2
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
这样可以使配置文件立即生效
官方地址:https://archive.apache.org/dist/zookeeper/zookeeper-3.7.0/
mkdir /data
wget https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz -P /data --no-check-certificate
tar -zxvf /data/apache-zookeeper-3.7.0-bin.tar.gz
#修改配置文件
cd /data/apache-zookeeper-3.7.0-bin/conf
cp /data/apache-zookeeper-3.7.0-bin/conf/zoo_sample.cfg /data/apache-zookeeper-3.7.0-bin/conf/zoo.cfg
vim /data/apache-zookeeper-3.7.0-bin/conf/zoo.cfg
dataDir=/data/apache-zookeeper-3.7.0-bin/data #修改数据存放目录
dataLogDir=/data/apache-zookeeper-3.7.0-bin/logs
admin.serverPort=8081
......
mkdir -p /data/apache-zookeeper-3.7.0-bin/data #创建 data 文件夹
mkdir -p /data/apache-zookeeper-3.7.0-bin/logs #创建 log 文件夹
#启动 zookeeper
cd /data/apache-zookeeper-3.7.0-bin/bin
./zkServer.sh start
----------------------------------------------
nohup /data/apache-zookeeper-3.7.0-bin/bin/zkServer.sh start &
tail -f /data/apache-zookeeper-3.7.0-bin/bin/nohup.log
./zkServer.sh start-foreground #查看启动失败错误信息,大概率是版本问题,要下带 bin 的版本
启动服务:
/data/apache-zookeeper-3.7.0-bin/bin/zkServer.sh start
连接服务:
/data/apache-zookeeper-3.7.0-bin/bin/zkCli.sh
查看服务状态:
/data/apache-zookeeper-3.7.0-bin/bin/zkServer.sh status
停止服务:
/data/apache-zookeeper-3.7.0-bin/bin/zkServer.sh stop
#查看启动失败错误信息,大概率是版本问题,要下带 bin 的版本
./zkServer.sh start-foreground
启动服务:
systemctl start zookeeper.service
查看服务状态:
systemctl status zookeeper.service
systemctl daemon-reload
systemctl enable zookeeper.service && systemctl restart zookeeper.service
systemctl status zookeeper.service
ps -ef|grep zookeeper
cat > /usr/lib/systemd/system/zookeeper.service <
# 增加权限
chmod 777 /usr/lib/systemd/system/zookeeper.service
# 设置自启
systemctl enable zookeeper.service
systemctl daemon-reload
# 查看是否自启
systemctl is-enabled zookeeper.service
# 取消自启
systemctl disable zookeeper.service
systemctl daemon-reload
vim /etc/profile
ZOOKEEPER_HOME=/data/apache-zookeeper-3.7.0-bin
PATH=$PATH:$ZOOKEEPER_HOME/bin
export PATH ZOOKEEPER_HOME PATH
vim /data/apache-zookeeper-3.7.0-bin/bin/zkEnv.sh
添加 JAVA_HOME
官网:http://kafka.apache.org/downloads
wget https://archive.apache.org/dist/kafka/2.8.0/kafka_2.12-2.8.0.tgz -P /data --no-check-certificate
tar xf /data/kafka_2.12-2.8.0.tgz
cd /data/kafka_2.12-2.8.0
vim /data/kafka_2.12-2.8.0/config/server.properties
nohup /data/kafka_2.12-2.8.0/bin/kafka-server-start.sh ./config/server.properties &
或者
守护进程方式启动kafka:
/data/kafka_2.12-2.8.0/bin/kafka-server-start.sh -daemon /data/kafka_2.12-2.8.0/config/server.properties
cat > /usr/lib/systemd/system/kafka.service <
systemctl daemon-reload
systemctl enable kafka.service && systemctl restart kafka.service
systemctl status kafka.service
netstat -antp | grep 9092
ps aux | grep kafka
lsof -i:9092
jps -l
nohup /data/kafka_2.12-2.8.0/bin/kafka-server-start.sh ./config/server.properties &
1.创建 Topic
/data/kafka_2.12-2.8.0/bin/kafka-topics.sh --create --zookeeper localhost:3181 --replication-factor 1 --partitions 1 --topic test
2.查看 topic 列表
/data/kafka_2.12-2.8.0/bin/kafka-topics.sh --list --zookeeper localhost:3181
3.查看描述 topics 信息
/data/kafka_2.12-2.8.0/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
4.启动生产者(窗口不要关闭)
/data/kafka_2.12-2.8.0/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
5.启动消费者(窗口不要关闭)
/data/kafka_2.12-2.8.0/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
6.在生产者窗口输入内容,消费者端可查看到输入的内容
生产端:
{"id":"1"}