一、ZooKeeper的安装
-
导入安装包 (tunabook102)(tunabook103)(tunabook104)
-
解压文件(tunabook102)(tunabook103)(tunabook104)
tar -zxvf zookeeper-3.4.6.tar.gz
-
文件夹重命名(tunabook102)(tunabook103)(tunabook104)
mv zookeeper-3.4.6 zookeeper
-
修改环境变量(tunabook102)(tunabook103)(tunabook104)
vi /etc/profile
# 新增加的内容 export ZOOKEEPER_HOME=/export/server/zookeeper export PATH=$PATH:$ZOOKEEPER_HOME/bin
-
更新配置文件(tunabook102)(tunabook103)(tunabook104)
source /etc/profile
-
修改Zookeeper配置文件(tunabook102)(tunabook103)(tunabook104)
cd zookeeper/conf mv zoo_sample.cfg zoo.cfg vim zoo.cfg
# 新增加的内容 dataDir=/export/data/zkdata ## (心跳端口、选举端口) server.1=tunabook102:2888:3888 server.2=tunabook103:2888:3888 server.3=tunabook104:2888:3888
-
添加每个节点zk服务编号myid
tunabook102mkdir -p /export/data/zkdata echo 1 > /export/data/zkdata/myid
tunabook103
mkdir -p /export/data/zkdata echo 2 > /export/data/zkdata/myid
tunabook104
mkdir -p /export/data/zkdata echo 3 > /export/data/zkdata/myid
二、ZooKeeper的启动
-
方式一:每台机器节点逐个启动(tunabook102)(tunabook103)(tunabook104)
/export/server/zookeeper/bin/zkServer.sh start|stop|status
-
方式二:编写脚本批量启动(tunabook102)(tunabook103)(tunabook104)
# 启动服务 #!/bin/bash hosts=(tunabook102 tunabook103 tunabook104) for host in ${hosts[*]} do ssh $host "source /etc/profile;/export/server/zookeeper/bin/zkServer.sh start" done
# 关闭服务 #!/bin/bash hosts=(tunabook102 tunabook103 tunabook104) for host in ${hosts[*]} do ssh $host "/export/server/zookeeper/bin/zkServer.sh stop" done
三、查看ZooKeeper状态
-
查看进程(tunabook102)(tunabook103)(tunabook104)
jps
-
查看集群状态、主从信息(tunabook102)(tunabook103)(tunabook104)
zkServer.sh status