1.创建目录
mkdir -p /zookeeper/zkp-1 /zookeeper/zkp-2 /zookeeper/zkp-3
2.下载zookeeper
链接地址:http://mirror.bit.edu.cn/apache/zookeeper/ 命令下载:
cd /zookeeper/zkp-1
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.5.5/apache-zookeeper-3.5.5-bin.tar.gz 3.解压
tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz
复制到zkp-2和zkp-3
cp -R /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin /zookeeper/zkp-2
cp -R /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin /zookeeper/zkp-3
4.修改配置文件
cd /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/conf
vim zoo.cfg
cd /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/conf
vim zoo.cfg
cd /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/conf
vim zoo.cfg
5.创建数据目录
mkdir -p /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/data
mkdir -p /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/data
mkdir -p /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/data
6.写入myid文件
cd /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/data
echo ‘1’ > myid
cd /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/data
echo ‘2’ > myid
cd /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/data
echo ‘3’ > myid
7.启动,三个都执行
cd /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin/bin
./zkServer.sh start
cd /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin/bin
./zkServer.sh start
cd /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin/bin
./zkServer.sh start
打印日志启动:./zkServer.sh start-foreground
8.查看jps结果
jps
8099 Jps
6808 QuorumPeerMain
6746 QuorumPeerMain
8014 QuorumPeerMain
kafka伪集群安装
1.创建目录
mkdir -p /kafka/kafka-1 /kafka/kafka-2 /kafka/kafka-3
2.下载kafka
链接:http://kafka.apache.org/downloads cd /kafka/kafka-1
wget http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.2.1/kafka_2.12-2.2.1.tgz 3.解压
tar -zxvf kafka_2.12-2.2.1.tgz
复制到kafka-2和kafka-3
cp -R /kafka/kafka-1/kafka_2.12-2.2.1 /kafka/kafka-2/kafka_2.12-2.2.1
cp -R /kafka/kafka-1/kafka_2.12-2.2.1 /kafka/kafka-3/kafka_2.12-2.2.1
4.修改配置文件
cd /kafka/kafka-1/kafka_2.12-2.2.1/config
vim server.properties
(listeners=PLAINTEXT://wzj-ThinkPad-Edge-E440:9092//这个参数非常重要,想要外网访问docker内的集群,只能配置主机名,不能配置IP地址,命令hostname, 配置文件时注意参数broker.id,log.dirs,zookeeper.connect)
cd /kafka/kafka-2/kafka_2.12-2.2.1/config
vim server.properties
cd /kafka/kafka-3/kafka_2.12-2.2.1/config
vim server.properties
4.启动,三个都执行
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-server-start.sh /kafka/kafka-1/kafka_2.12-2.2.1/config/server.properties &
cd /kafka/kafka-2/kafka_2.12-2.2.1
bin/kafka-server-start.sh /kafka/kafka-2/kafka_2.12-2.2.1/config/server.properties &
cd /kafka/kafka-3/kafka_2.12-2.2.1
bin/kafka-server-start.sh /kafka/kafka-3/kafka_2.12-2.2.1/config/server.properties &
后台启动方式:
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-server-start.sh -daemon /kafka/kafka-1/kafka_2.12-2.2.1/config/server.properties
cd /kafka/kafka-2/kafka_2.12-2.2.1
bin/kafka-server-start.sh -daemon /kafka/kafka-2/kafka_2.12-2.2.1/config/server.properties
cd /kafka/kafka-3/kafka_2.12-2.2.1
bin/kafka-server-start.sh -daemon /kafka/kafka-3/kafka_2.12-2.2.1/config/server.properties
netstat lntp|grep 9092
5.测试kafka集群
#创建topic
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-topics.sh --create --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181 --replication-factor 3 --partitions 3 --topic test
#显示topic信息
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-topics.sh --describe --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181 --topic test
#列出topic
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-topics.sh --list --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181
#创建 producer
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-console-producer.sh --broker-list master:9092 -topic test
#创建 consumer
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-console-consumer.sh --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181 -topic test --from-beginning
#删除topic
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-topics.sh --delete --zookeeper 192.168.0.79:2181,192.168.0.79:3181,192.168.0.79:4181 --topic test
#查询topic内容
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicName --from-beginning
6.关闭kafka
cd /kafka/kafka-1/kafka_2.12-2.2.1
bin/kafka-server-stop.sh /kafka/kafka-1/kafka_2.12-2.2.1/config/server.properties
cd /kafka/kafka-2/kafka_2.12-2.2.1
bin/kafka-server-stop.sh /kafka/kafka-2/kafka_2.12-2.2.1/config/server.properties
cd /kafka/kafka-3/kafka_2.12-2.2.1
bin/kafka-server-stop.sh /kafka/kafka-3/kafka_2.12-2.2.1/config/server.properties
7.关闭zookeeper
cd /zookeeper/zkp-1/apache-zookeeper-3.5.5-bin
bin/zkServer.sh stop conf/zoo.cfg
cd /zookeeper/zkp-2/apache-zookeeper-3.5.5-bin
bin/zkServer.sh stop conf/zoo.cfg
cd /zookeeper/zkp-3/apache-zookeeper-3.5.5-bin
bin/zkServer.sh stop conf/zoo.cfg