使用vm虚拟三个linux主机
192.168.212.xxx
192.168.212.xxx
192.168.212.xxx
使用java-v命令测试
2.每台服务器节点上安装Zookeeper
1.下载并且安装zookeeper安装包
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
解压安装包
tar -zxvf zookeeper-3.4.10.tar.gz
重命名
重命名: mv zookeeper-3.4.10 zookeeper
3.搭建Zookeeper集群环境
修改zoo_sample.cfg文件
cd /usr/local/zookeeper/conf
mv zoo_sample.cfg zoo.cfg
修改conf: vi zoo.cfg 修改两处
(1) dataDir=/usr/local/zookeeper/data(注意同时在zookeeper创建data目录)
(2)最后面添加
server.0=192.168.212.xxx:2888:3888
server.1=192.168.212.xxx:2888:3888
server.2=192.168.212.xxx:2888:3888
4.创建服务器标识
服务器标识配置:
创建文件夹: mkdir data
创建文件myid并填写内容为0: vi
myid (内容为服务器标识 : 0)
5.复制zookeeper
进行复制zookeeper目录到hadoop01和hadoop02
还有/etc/profile文件
把hadoop01、 hadoop02中的myid文件里的值修改为1和2
路径(vi /usr/local/zookeeper/data/myid)
关闭每台服务器节点防火墙,systemctl stop firewalld.service
启动zookeeper
启动zookeeper:
路径: /usr/local/zookeeper/bin
执行: zkServer.sh start
(注意这里3台机器都要进行启动)
状态: zkServer.sh status(在三个节点上检验zk的mode,一个leader和俩个follower)
3台虚拟机均进行以下操作:
// 解压下载好的kafka压缩包并重命名
cd /usr/local
wget http://mirror.bit.edu.cn/apache/kafka/1.0.0/kafka_2.11-1.0.0.tgz
tar -zxvf kafka_2.11-1.0.0.tgz
mv kafka_2.12-0.11.0.0 kafka
// 修改配置文件
vi ./kafka/config/server.properties
需要修改的内容如下(192.168.212.169)
broker.id=0
listeners=PLAINTEXT://192.168.131.130:9092
zookeeper.connect=192.168.131.130:2181,192.168.131.131:2181,192.168.131.132:2181
需要修改的内容如下(192.168.212.170)
broker.id=1
listeners=PLAINTEXT://192.168.212.170:9092
zookeeper.connect=192.168.131.130:2181,192.168.131.131:2181,192.168.131.132:2181
需要修改的内容如下(192.168.212.171)
broker.id=2
listeners=PLAINTEXT://192.168.212.171:9092
zookeeper.connect=192.168.131.130:2181,192.168.131.131:2181,192.168.131.132:2181
// 在系统环境中配置kafka的路径
vi /etc/profile
// 在文件最下方添加kafka路径
export KAFKA_HOME=/usr/local/kafka
// 多路径PATH写法为PATH= Z O O K E E P E R H O M E / b i n : {ZOOKEEPER_HOME}/bin: ZOOKEEPERHOME/bin:{KAFKA_HOME}/bin: P A T H P A T H = PATH PATH= PATHPATH={KAFKA_HOME}/bin:$PATH
export PATH
// 使修改完的环境变量生效
source /etc/profile
192.168.212.169:2181,192.168.212.172:2181,192.168.212.173:2181
Kafka集群环境测试
1、开启3台虚拟机的zookeeper程序
/usr/local/zookeeper/bin/zkServer.sh start
开启成功后查看zookeeper集群的状态
/usr/local/zookeeper/bin/zkServer.sh status
出现Mode:follower或是Mode:leader则代表成功
2、在后台开启3台虚拟机的kafka程序(cd /usr/local/kafka)
./bin/kafka-server-start.sh -daemon config/server.properties
3、在其中一台虚拟机(192.168.131.130)创建topic
/usr/local/kafka/bin/kafka-topics.sh –create –zookeeper 192.168.131.130:2181 –replication-factor 3 –partitions 1 –topic my-replicated-topic
// 查看创建的topic信息
/usr/local/kafka/bin/kafka-topics.sh –describe –zookeeper 192.168.131.130:2181 –topic my-replicated-topic