赞
踩
1、环境准备
ZooKeeper服务器是用Java创建的,它运行在JVM之上。需要安装JDK 7或更高版本。
将下载的ZooKeeper放到/opt/ZooKeeper目录下
-
- #上传zookeeper alt+p
- put f:/setup/apache-zookeeper-3.5.6-bin.tar.gz
- #打开 opt目录
- cd /opt
- #创建zooKeeper目录
- mkdir zooKeeper
- #将zookeeper安装包移动到 /opt/zooKeeper
- mv apache-zookeeper-3.5.6-bin.tar.gz /opt/zookeeper/
将tar包解压到/opt/zookeeper目录下
tar -zxvf apache-ZooKeeper-3.5.6-bin.tar.gz
进入到conf目录拷贝一个zoo_sample.cfg并完成配置
- #进入到conf目录
- cd /opt/zooKeeper/apache-zooKeeper-3.5.6-bin/conf/
- #拷贝
- cp zoo_sample.cfg zoo.cfg
修改zoo.cfg
- #打开目录
- cd /opt/zooKeeper/
- #创建zooKeeper存储目录
- mkdir zkdata
- #修改zoo.cfg
- vim /opt/zooKeeper/apache-zooKeeper-3.5.6-bin/conf/zoo.cfg
修改存储目录:dataDir=/opt/zookeeper/zkdata
2、启动ZooKeeper
- cd /opt/zooKeeper/apache-zooKeeper-3.5.6-bin/bin/
- #启动
- ./zkServer.sh start
看到上图表示ZooKeeper成功启动
3、查看ZooKeeper状态
./zkServer.sh status
zookeeper启动成功。standalone代表zk没有搭建集群,现在是单节点
zookeeper没有启动
真实的集群是需要部署在不同的服务器上的,但是在我们测试时同时启动很多个虚拟机内存会吃不消,所以我们通常会搭建伪集群,也就是把所有的服务都搭建在一台虚拟机上,用端口进行区分。
我们这里要求搭建一个三个节点的Zookeeper集群(伪集群)。
重新部署一台虚拟机作为我们搭建集群的测试服务器。
(1)安装JDK 【此步骤省略】。
(2)Zookeeper压缩包上传到服务器
(3)将Zookeeper解压 ,建立/usr/local/zookeeper-cluster目录,将解压后的Zookeeper复制到以下三个目录
/usr/local/zookeeper-cluster/zookeeper-1
/usr/local/zookeeper-cluster/zookeeper-2
/usr/local/zookeeper-cluster/zookeeper-3
- [root@localhost ~]# mkdir /usr/local/zookeeper-cluster
- [root@localhost ~]# cp -r apache-zookeeper-3.5.6-bin /usr/local/zookeeper-cluster/zookeeper-1
- [root@localhost ~]# cp -r apache-zookeeper-3.5.6-bin /usr/local/zookeeper-cluster/zookeeper-2
- [root@localhost ~]# cp -r apache-zookeeper-3.5.6-bin /usr/local/zookeeper-cluster/zookeeper-3
(4)创建data目录 ,并且将 conf下zoo_sample.cfg 文件改名为 zoo.cfg
- mkdir /usr/local/zookeeper-cluster/zookeeper-1/data
- mkdir /usr/local/zookeeper-cluster/zookeeper-2/data
- mkdir /usr/local/zookeeper-cluster/zookeeper-3/data
-
- mv /usr/local/zookeeper-cluster/zookeeper-1/conf/zoo_sample.cfg /usr/local/zookeeper-cluster/zookeeper-1/conf/zoo.cfg
- mv /usr/local/zookeeper-cluster/zookeeper-2/conf/zoo_sample.cfg /usr/local/zookeeper-cluster/zookeeper-2/conf/zoo.cfg
- mv /usr/local/zookeeper-cluster/zookeeper-3/conf/zoo_sample.cfg /usr/local/zookeeper-cluster/zookeeper-3/conf/zoo.cfg
(5) 配置每一个Zookeeper 的dataDir 和 clientPort 分别为2181 2182 2183
修改/usr/local/zookeeper-cluster/zookeeper-1/conf/zoo.cfg
- vim /usr/local/zookeeper-cluster/zookeeper-1/conf/zoo.cfg
-
- clientPort=2181
- dataDir=/usr/local/zookeeper-cluster/zookeeper-1/data
修改/usr/local/zookeeper-cluster/zookeeper-2/conf/zoo.cfg
- vim /usr/local/zookeeper-cluster/zookeeper-2/conf/zoo.cfg
-
- clientPort=2182
- dataDir=/usr/local/zookeeper-cluster/zookeeper-2/data
修改/usr/local/zookeeper-cluster/zookeeper-3/conf/zoo.cfg
- vim /usr/local/zookeeper-cluster/zookeeper-3/conf/zoo.cfg
-
- clientPort=2183
- dataDir=/usr/local/zookeeper-cluster/zookeeper-3/data
(1)在每个zookeeper的 data 目录下创建一个 myid 文件,内容分别是1、2、3 。这个文件就是记录每个服务器的ID
- echo 1 >/usr/local/zookeeper-cluster/zookeeper-1/data/myid
- echo 2 >/usr/local/zookeeper-cluster/zookeeper-2/data/myid
- echo 3 >/usr/local/zookeeper-cluster/zookeeper-3/data/myid
(2)在每一个zookeeper 的 zoo.cfg配置客户端访问端口(clientPort)和集群服务器IP列表。
集群服务器IP列表如下
- vim /usr/local/zookeeper-cluster/zookeeper-1/conf/zoo.cfg
- vim /usr/local/zookeeper-cluster/zookeeper-2/conf/zoo.cfg
- vim /usr/local/zookeeper-cluster/zookeeper-3/conf/zoo.cfg
-
- server.1=192.168.149.135:2881:3881
- server.2=192.168.149.135:2882:3882
- server.3=192.168.149.135:2883:3883
解释:server.服务器ID=服务器IP地址:服务器之间通信端口:服务器之间投票选举端口
启动集群就是分别启动每个实例。
- /usr/local/zookeeper-cluster/zookeeper-1/apache-zookeeper-3.5.6-bin/bin/zkServer.sh start
- /usr/local/zookeeper-cluster/zookeeper-2/apache-zookeeper-3.5.6-bin/bin/zkServer.sh start
- /usr/local/zookeeper-cluster/zookeeper-3/apache-zookeeper-3.5.6-bin/bin/zkServer.sh start
- /usr/local/zookeeper-cluster/zookeeper-1/apache-zookeeper-3.5.6-bin/bin/zkServer.sh statue
- /usr/local/zookeeper-cluster/zookeeper-2/apache-zookeeper-3.5.6-bin/bin/zkServer.sh statue
- /usr/local/zookeeper-cluster/zookeeper-3/apache-zookeeper-3.5.6-bin/bin/zkServer.sh statue
Mode为follower表示是跟随者(从)
再查询第二个服务Mod 为leader表示是领导者(主)
1、环境准备
安装包下载地址:https://archive.apache.org/dist/kafka/2.4.0/kafka_2.12-2.4.0.tgz
解压kafka_2.12-2.4.0.tgz,得到 "kafka_2.12-2.4.0 " 文件夹。
tar -zxvf kafka_2.12-2.4.0.tgz
(1)、kafka需要安装zookeeper使用,但kafka集成zookeeper,在单机搭建时可直接使用。使用需配置kafka_2.12-2.4.0/config 下的“zookeeper.properties”
cd kafka_2.12-2.5.0/config
(2)、配置"zookeeper.properties"。修改dataDir和clientPort。前者是快照存放地址(自己随意配置),后者是客户端连接zookeeper服务的端口。默认端口2181 最好默认不修改
vim kafka_2.12-2.5.0/config/zookeeper.properties
(4)、配置kafka_2.12-2.4.0/config下的“server.properties”,修改log.dirs和zookeeper.connect。前者是日志存放文件夹,后者是zookeeper连接地址(端口和clientPort保持一致)。
vim kafka_2.12-2.4.0/config/server.properties
注:若需要外部访问 一定需要配置listeners 默认为本机IP 端口默认9092 如图:
同理,每个节点都这样改下即可
前台运行:
bin/kafka-server-start.sh config/server.properties
后台运行:
./bin/kafka-server-start.sh -daemon ./config/server.properties
(1)、创建kafka主题:test_topic3
./kafka-topics.sh --create --zookeeper localhost:2181,localhost:2182,localhost:2183 --replication-factor 1 --partitions 1 --topic test_topic3
(2)、查看topic的信息
./kafka-topics.sh --describe --zookeeper localhost:2181,localhost:2181,localhost:2181 --topic test_topic3
(3)、创建生产者
./kafka-console-producer.sh --broker-list localhost:9092 --topic test_topic3
(4)、创建消费者
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic test_topic3
(1)、首先强调一个原则,升级后kafka客户端和服务端版本最好保持一致
(2)、zookeeper和kafka集群的版本适配,其中zk版本比要求的高一点也可以
kafka zookeeper
kafka_2.13-2.7.0 zookeeper-3.5.7
kafka_2.13-2.6.x zookeeper-3.5.7
kafka_2.12-2.5.0 zookeeper-3.5.7
kafka_2.12-2.4.0 zookeeper-3.5.6
kafka_2.12-2.3.1 zookeeper-3.4.14
kafka_2.12-2.3.0 zookeeper-3.4.14
kafka_2.12-1.1.1 zookeeper-3.4.10
kafka_2.12-1.1.0 zookeeper-3.4.10
kafka_2.12-1.0.2 zookeeper-3.4.10
kafka_2.12-0.11.0.0 zookeeper-3.4.10
kafka_2.12-0.10.2.2 zookeeper-3.4.9
kafka_2.12-0.10.0.0 zookeeper-3.4.6
kafka_2.12-0.9.0.0 zookeeper-3.4.6
- docker run --rm -it \
- -p 2181:2181 -p 9092:9092 -p 3030:3030 \
- -p 8081:8081 -p 8082:8082 -p 8083:8083 \
- -e ADV_HOST=127.0.0.1 \
- landoop/fast-data-dev
注意,此方式需要服务器内存要求比较高
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。