准备环境
准备三台虚拟机
ip192.168.43.64 ip192.168.43.129 ip192.168.43.134
为三台虚拟机准备java环境
[root@localhost src]# rz
解压并配置环境变量
[root@localhost src]# tat zxf jdk-8u91-linux-x64.gz
[root@localhost src]# vim /etc/profile
增加以下三行
export JAVA_HOME=/data/server/jdk1.8.0_91
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
使其立即生效
[root@localhost src]# source /etc/profile
[root@localhost src]# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
下载zookeeper
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/
上传安装包到ip为192.168.43.64中
解压
tar zxf zookeeper-3.4.14.tar.gz -C /data/server/
修改配置文件
cd /data/server/zookeeper-3.4.14/conf/
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
dataDir=/data/server/zookeeper-3.4.14/data
server.1=192.168.43.64:2888:3888
server.2=192.168.43.134:2888:3888
server.3=192.168.43.129:2888:3888
创建目录并创建文件
mkdir /data/server/zookeeper-3.4.14/data
cd /data/server/zookeeper-3.4.14/data/
touch myid
echo "1" >myid
将配置好的zookeeper文件发送到其他两台机子
scp -r /data/server/zookeeper-3.4.14/ root@192.168.43.129:/data/server/
scp -r /data/server/zookeeper-3.4.14/ root@192.168.43.134:/data/server/
修改其他两台机子的myid文件
192.168.43.134:echo “2”>myid
192.168.43.129 echo “3”>myid
关闭三台机子的防火墙
systemctl stop firewalld
然后分别开启服务
[root@localhost data]# ../zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /data/server/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
查看各个机器的状态
[root@localhost data]# ../bin/zkServer.sh status 192.168.43.129
ZooKeeper JMX enabled by default
Using config: /data/server/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower
[root@localhost data]# ../bin/zkServer.sh status 192.168.43.132
ZooKeeper JMX enabled by default
Using config: /data/server/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower
[root@localhost data]# ../bin/zkServer.sh status 192.168.43.64
ZooKeeper JMX enabled by default
Using config: /data/server/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: leader
成功!