Zookeepr分布式集群搭建

不要下载源码的问下 下载bin的文件  源码有时候会找不到类

apache-zookeeper-3.6.0-bin.tar.gz

1.1 集群规划

在linux1,linux2和linux3三个节点上部署Zookeeper,三个节点都已安装jdk。

配置好ssh key免密登录

1.首先配置hosts文件

vim /etc/hosts

192.168.10.11 linux1 192.168.10.12 linux2 192.168.10.13 linux3

2.生成ssh rsa 

第一台机器

[Hadoop@linux1 conf]$ ssh-keygen -t rsa

[hadoop@linux1 conf]$ ssh-copy-id linux2

[hadoop@linux1 conf]$ ssh-copy-id linux3

 

第二台机器

 

[hadoop@linux2 conf]$ ssh-keygen -t rsa

[hadoop@linux2 conf]$ ssh-copy-id linux1

[hadoop@linux2 conf]$ ssh-copy-id linux3

 

第三台机器

 

[hadoop@linux3 conf]$ ssh-keygen -t rsa

[hadoop@linux3 conf]$ ssh-copy-id linux1

[hadoop@linux3 conf]$ ssh-copy-id linux2

1.2 解压安装

tar -zxvf apache-zookeeper-3.6.0-bin.tar.gz  -C /opt/module/<br>mv /opt/module/apache-zookeeper-3.6.0-bin /opt/module/apache-zookeeper-3.6.0

在/opt/module/apache-zookeeper-3.6.0/这个目录下创建Data  

[hadoop@linux1 apache-zookeeper-3.6.0]$ mkdir Data

修改文件名称  

mv zoo_sample.cfg zoo.cfg

1.3 配置zoo.cfg文件

具体配置,修改dateDir,添加日志存放目录

ataDir=/opt/module/apache-zookeeper-3.6.0/Data

dataLogDir=/opt/module/apache-zookeeper-3.6.0/Data/logs

 在末尾增加

server.1=linux1:2888:3888 server.2=linux2:2888:3888 server.3=linux3:2888:3888

1.4 集群配置

(1)在/opt/module/apache-zookeeper-3.6.0/Data目录下创建一个myid的文件

[hadoop@linux1 Data]$ touch myid

(2)编辑myid文件, 在文件中添加与server对应的编号:如 1   

[hadoop@linux1 Data]$ vi myid

Zookeepr分布式集群搭建

wq保存退出

[hadoop@linux1 module]$ scp -r apache-zookeeper-3.6.0/ hadoop@linux2:/opt/module/ [hadoop@linux1 module]$ scp -r apache-zookeeper-3.6.0/ hadoop@linux3:/opt/module/

分别设置linux1和linux2的myid文件

[hadoop@linux1 module]$ ssh linux2 Last login: Tue Mar 24 11:32:24 2020 from linux1 [hadoop@linux2 ~]$ echo 2 > /opt/module/apache-zookeeper-3.6.0/Data/myid [hadoop@linux2 ~]$ cat /opt/module/apache-zookeeper-3.6.0/Data/myid 2 [hadoop@linux2 ~]$ exit logout Connection to linux2 closed. [hadoop@linux1 module]$

 

 

[hadoop@linux1 module]$ ssh linux3 Last login: Mon Mar 23 14:15:50 2020 [hadoop@linux3 ~]$ echo 3 > /opt/module/apache-zookeeper-3.6.0/Data/myid [hadoop@linux3 ~]$ cat /opt/module/apache-zookeeper-3.6.0/Data/myid 3 [hadoop@linux3 ~]$ exit logout Connection to linux3 closed. [hadoop@linux1 module]$

1.5 启动集群

[hadoop@linux1 apache-zookeeper-3.6.0]$ ./bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/module/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@linux1 apache-zookeeper-3.6.0]$ ssh linux2 Last login: Tue Mar 24 11:33:58 2020 from linux1 [hadoop@linux2 ~]$ /opt/module/apache-zookeeper-3.6.0/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/module/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@linux2 ~]$ exit logout Connection to linux2 closed. [hadoop@linux1 apache-zookeeper-3.6.0]$ ssh linux 2 ssh: Could not resolve hostname linux: Name or service not known [hadoop@linux1 apache-zookeeper-3.6.0]$ ssh linux3 Last login: Tue Mar 24 11:35:38 2020 from linux1 [hadoop@linux3 ~]$ /opt/module/apache-zookeeper-3.6.0/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/module/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@linux3 ~]$ exit logout Connection to linux3 closed. [hadoop@linux1 apache-zookeeper-3.6.0]$

1.6 配置环境变量

vi /etc/profile

export ZOOKEEPER_HOME=/opt/module/apache-zookeeper-3.6.0 export PATH=$PATH:$ZOOKEEPER_HOME/bin

source /etc/profile

1.7zoo.cfg配置参数解读

Server.A=B:C:D。

A是一个数字,表示这个是第几号服务器

B是这个服务器的ip地址;

C是这个服务器与集群中的Leader服务器交换信息的端口;

D是万一集群中的Leader服务器挂了,需要一个端口来重新进行选举,选出一个新的Leader,而这个端口就是用来执行选举时服务器相互通信的端口。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/20c818f91b8994b7fb5a611f4bdd1df2.html