1,基础环境
1,首先准备三台节点,(有钱的可以买云服务器,华为的相对便宜一些,没钱的找个配置好一些的电脑,装个Vmvare 虚拟机器主机就Ok了,具体方法,度娘,这是基本的功力,哈哈哈哈)
2, 安装好jdk,
本位的jdk 版本如下:
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
2,安装zookeeper
本文的版本是3.4.10
2,1把zookeeper 安装包上传到服务器中的一个固定目录,然后解压:
本文的目录大致如下:
[root@master /opt/bigdata/component/zookeeper]# pwd
/opt/bigdata/component/zookeeper
[root@master /opt/bigdata/component/zookeeper]#
2,2到conf 目录下面配置zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/bigdata/component/zookeeper/data
clientPort=2181
#把相应的ip 改成自己的ip , 数据目录改成自己的目录即可
server.1=172.16.0.47:2888:3888
server.2=172.16.0.155:2888:3888
server.3=172.16.0.192:2888:3888
2.3到bin目录下面配置其log 日记目录(不是必须,只是此处本人为了方法查看日记)
if [ "x${ZOO_LOG_DIR}" = "x" ]
then
ZOO_LOG_DIR="/opt/bigdata/logs/zookeeper/logs"
fi
2.4 为了方便,在/opt下面放置了一个配置文件,用来记录zookeeper 的安装目录和把bin 目录加到环境变量中
[root@master /opt/bigdata/component]# cat //opt/env_bigdata.sh
export ZOOKEEPER_HOME=/opt/bigdata/component/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
[root@master /opt/bigdata/component]#
2.5 把配置好的安装目录zookeeper 发送到另外两个节点
scp -r zookeeper workerI:`pwd`
scp -r zookeeper workerII:`pwd`
[root@master /opt/bigdata/component]# pwd
/opt/bigdata/component
2.6, 分别在三个zookeeper 的目录的data 目录下创建一个myid 文件
[root@master /opt/bigdata/component/zookeeper/data]# echo 1 > myid
[root@master /opt/bigdata/component/zookeeper/data]# pwd
/opt/bigdata/component/zookeeper/data
[root@workerI /opt/bigdata/component/zookeeper/data]# echo 2 > myid
[root@workerI /opt/bigdata/component/zookeeper/data]#
[root@workerII /opt/bigdata/component/zookeeper/data]# echo 3 > myid
[root@workerII /opt/bigdata/component/zookeeper/data]# cat myid
3
3,安装大功告成,接下来就可以启动了。
在三个节点上面分别执行如下脚本即可:
[root@workerII /opt/bigdata/component/zookeeper]# sh bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/component/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
查看其状态:
[root@workerII /opt/bigdata/component/zookeeper]# sh bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/component/zookeeper/bin/../conf/zoo.cfg
Mode: follower
[root@workerI /opt/bigdata/component/zookeeper]# sh bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/component/zookeeper/bin/../conf/zoo.cfg
Mode: leader
[root@master /opt/bigdata/component/zookeeper]# sh bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/component/zookeeper/bin/../conf/zoo.cfg
Mode: follower