目录
前提条件
步骤
ZooKeeper集群规划
下载解压
配置环境变量
配置服务器编号
配置zoo.cfg
分别启动zk服务
查看zk状态
进入zk客户端命令行测试
zk集群启动停止脚本
前提条件
拥有3台CentOS7机器,并且都安装好jdk8
步骤
ZooKeeper集群规划
node2 | node3 | node4 |
zk | zk | zk |
下载解压
下载apache-zookeeper-3.5.7-bin.tar.gz
Index of /dist/zookeeper
将下载的文件上传到node2,并解压
[hadoop@node2 installfile]$ tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C ~/soft/
重命名
[hadoop@node2 installfile]$ cd ~/soft/ [hadoop@node2 soft]$ ls apache-zookeeper-3.5.7-bin hadoop-3.1.3 jdk1.8.0_212 重命名 [hadoop@node2 soft]$ mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7 [hadoop@node2 soft]$ ls hadoop-3.1.3 jdk1.8.0_212 zookeeper-3.5.7
同步至其他机器
[hadoop@node2 soft]$ xsync zookeeper-3.5.7
若没有xsycn脚本,可点击参考。
配置环境变量
配置环境变量(所有机器都执行)
$ sudo nano /etc/profile.d/my_env.sh
添加如下内容
#ZOOKEEPER_HOME export ZOOKEEPER_HOME=/home/hadoop/soft/zookeeper-3.5.7 export PATH=$PATH:$ZOOKEEPER_HOME/bin
让环境变量生效
$ source /etc/profile
配置服务器编号
新建myid
机器2 [hadoop@node2 zookeeper-3.5.7]$ cd $ZOOKEEPER_HOME/ [hadoop@node2 zookeeper-3.5.7]$ mkdir zkData [hadoop@node2 zookeeper-3.5.7]$ nano zkData/myid 内容为 2 机器3 [hadoop@node2 zookeeper-3.5.7]$ cd $ZOOKEEPER_HOME/ [hadoop@node2 zookeeper-3.5.7]$ mkdir zkData [hadoop@node2 zookeeper-3.5.7]$ nano zkData/myid 内容为 3 机器4 [hadoop@node2 zookeeper-3.5.7]$ cd $ZOOKEEPER_HOME/ [hadoop@node2 zookeeper-3.5.7]$ mkdir zkData [hadoop@node2 zookeeper-3.5.7]$ nano zkData/myid 内容为 4
配置zoo.cfg
[hadoop@node2 conf]$ cd $ZOOKEEPER_HOME/conf [hadoop@node2 conf]$ cp zoo_sample.cfg zoo.cfg [hadoop@node2 conf]$ ls configuration.xsl log4j.properties zoo.cfg zoo_sample.cfg nano zoo.cfg 修改 dataDir=/home/hadoop/soft/zookeeper-3.5.7/zkData 末尾添加 server.2=node2:2888:3888 server.3=node3:2888:3888 server.4=node4:2888:3888
server.A=B:C:D。
A:机器编号
B:主机名
C: Leader与Follower的访问端口
D: 选举Leader接口
同步zoo.cfg
xsync zoo.cfg
分别启动zk服务
[hadoop@node2 zookeeper-3.5.7]$ zkServer.sh start ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@node3 zookeeper-3.5.7]$ zkServer.sh start ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@node4 zookeeper-3.5.7]$ zkServer.sh start ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
查看zk状态
[hadoop@node2 zookeeper-3.5.7]$ zkServer.sh status ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower [hadoop@node3 zookeeper-3.5.7]$ zkServer.sh status ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: leader [hadoop@node4 zookeeper-3.5.7]$ zkServer.sh status ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower
进入zk客户端命令行测试
[hadoop@node2 zookeeper-3.5.7]$ zkCli.sh [zk: localhost:2181(CONNECTED) 1] ls / [zookeeper] [zk: localhost:2181(CONNECTED) 2] create -e /a 1 Created /a [zk: localhost:2181(CONNECTED) 3] get /a 1
zk集群启动停止脚本
进入~/bin
目录,创建zk.sh
[hadoop@node2 ~]$ cd ~/bin/ [hadoop@node2 bin]$ vim zk.sh
内容如下:
#!/bin/bash case $1 in "start"){ for i in node2 node3 node4 do echo ---------- zookeeper $i 启动 ------------ ssh $i "/home/hadoop/soft/zookeeper-3.5.7/bin/zkServer.sh start" done };; "stop"){ for i in node2 node3 node4 do echo ---------- zookeeper $i 停止 ------------ ssh $i "/home/hadoop/soft/zookeeper-3.5.7/bin/zkServer.sh stop" done };; "status"){ for i in node2 node3 node4 do echo ---------- zookeeper $i 状态 ------------ ssh $i "/home/hadoop/soft/zookeeper-3.5.7/bin/zkServer.sh status" done };; esac
添加执行权限
[hadoop@node2 bin]$ ll total 16 -rwxrwxr-x. 1 hadoop hadoop 125 Apr 2 09:40 jpsall -rwxrwxr-x. 1 hadoop hadoop 1142 Apr 2 09:48 myhadoop.sh -rwxrwxr-x. 1 hadoop hadoop 731 Apr 1 11:36 xsync -rw-rw-r--. 1 hadoop hadoop 565 Apr 7 09:53 zk.sh [hadoop@node2 bin]$ chmod u+x zk.sh [hadoop@node2 bin]$ ll total 16 -rwxrwxr-x. 1 hadoop hadoop 125 Apr 2 09:40 jpsall -rwxrwxr-x. 1 hadoop hadoop 1142 Apr 2 09:48 myhadoop.sh -rwxrwxr-x. 1 hadoop hadoop 731 Apr 1 11:36 xsync -rwxrw-r--. 1 hadoop hadoop 565 Apr 7 09:53 zk.sh
测试文章来源:https://www.toymoban.com/news/detail-758894.html
[hadoop@node2 bin]$ zk.sh start ---------- zookeeper node2 启动 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED ---------- zookeeper node3 启动 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED ---------- zookeeper node4 启动 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@node2 bin]$ zk.sh status ---------- zookeeper node2 状态 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower ---------- zookeeper node3 状态 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: leader ---------- zookeeper node4 状态 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Client port found: 2181. Client address: localhost. Mode: follower [hadoop@node2 bin]$ zk.sh stop ---------- zookeeper node2 停止 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED ---------- zookeeper node3 停止 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED ---------- zookeeper node4 停止 ------------ ZooKeeper JMX enabled by default Using config: /home/hadoop/soft/zookeeper-3.5.7/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED
完成!enjoy it!文章来源地址https://www.toymoban.com/news/detail-758894.html
到了这里,关于CentOS7环境ZooKeeper集群的安装的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!