1、安装Zookeeper
将Zookeeper安装文件解压到相应目录下,并配置环境变量,步骤参考单机模式
$https://www.jianshu.com/p/3b680a192c6c
2、建立配置文件
在安装目录的conf文件夹下分别新建三个配置文件 zoo1.cfg、zoo2.cfg、zoo3.cfg
[victor@node1 ~]$ cd /opt/module/zookeeper-3.4.10/conf/
[victor@node1 conf]$ pwd
/opt/module/zookeeper-3.4.10/conf
[victor@node1 conf]$ touch zoo{1..3}.cfg
zoo1.cfg内容如下
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/module/zookeeper-3.4.10/zkdata1
dataLogDir=/opt/module/zookeeper-3.4.10/zkdata1
clientPort=2181
server.1=node1:20881:30881
server.2=node1:20882:30882
server.3=node1:20883:30883
zoo2.cfg内容如下
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/module/zookeeper-3.4.10/zkdata2
dataLogDir=/opt/module/zookeeper-3.4.10/zkdata2
clientPort=2182
server.1=node1:20881:30881
server.2=node1:20882:30882
server.3=node1:20883:30883
zoo3.cfg内容如下
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/module/zookeeper-3.4.10/zkdata3
dataLogDir=/opt/module/zookeeper-3.4.10/zkdata3
clientPort=2183
server.1=node1:20881:30881
server.2=node1:20882:30882
server.3=node1:20883:30883
3、建立数据目录和日志目录
[victor@node1 zookeeper-3.4.10]$ cd /opt/module/zookeeper-3.4.10/
[victor@node1 zookeeper-3.4.10]$ pwd
/opt/module/zookeeper-3.4.10
[victor@node1 zookeeper-3.4.10]$ mkdir zkdata1 zkdata2 zkdata3
在数据目录创建myid文件,并写入相对应数字
zkdata1
[victor@node1 zookeeper-3.4.10]$ cd /opt/module/zookeeper-3.4.10/zkdata1/
[victor@node1 zkdata1]$ touch myid
[victor@node1 zkdata1]$ echo 1 > myid
[victor@node1 zkdata1]$ cat myid
1
zkdata2
[victor@node1 zookeeper-3.4.10]$ cd /opt/module/zookeeper-3.4.10/zkdata2/
[victor@node1 zkdata2]$ touch myid
[victor@node1 zkdata2]$ echo 2 > myid
[victor@node1 zkdata2]$ cat myid
2
zkdata3
[victor@node1 zookeeper-3.4.10]$ cd /opt/module/zookeeper-3.4.10/zkdata3/
[victor@node1 zkdata3]$ touch myid
[victor@node1 zkdata3]$ echo 3 > myid
[victor@node1 zkdata3]$ cat myid
3
4、启动服务并查看状态
分别执行以下命令进行启动Zookeeper服务
[victor@node1 ~]$ cd /opt/module/zookeeper-3.4.10/
[victor@node1 zookeeper-3.4.10]$ bin/zkServer.sh start conf/zoo1.cfg
[victor@node1 zookeeper-3.4.10]$ bin/zkServer.sh start conf/zoo2.cfg
[victor@node1 zookeeper-3.4.10]$ bin/zkServer.sh start conf/zoo3.cfg
分别执行以下命令进行查看Zookeeper服务状态
[victor@node1 ~]$ cd /opt/module/zookeeper-3.4.10/
[victor@node1 zookeeper-3.4.10]$ bin/zkServer.sh status conf/zoo1.cfg
[victor@node1 zookeeper-3.4.10]$ bin/zkServer.sh status conf/zoo2.cfg
[victor@node1 zookeeper-3.4.10]$ bin/zkServer.sh status conf/zoo3.cfg