安装jdk 过程略
关闭防火墙 过程略
1、准备3台服务器,10.10.171.157、10.10.171.158、10.10.171.159。在10.10.171.157服务器的/opt/目录下创建zookeeper文件夹,并创建数据文件夹data,日志文件夹logs
mkdir /opt/zookeeper
mkdir /opt/zookeeper/data
mkdir /opt/zookeeper/logs
2、下载zookeeper
zookeeper-3.6.2 ,上传压缩包上传到/opt/zookeeper目录中,解压
tar -zxvf apache-zookeeper-3.6.2-bin.tar.gz
3、进入/opt/zookeeper/apache-zookeeper-3.6.2-bin/conf文件夹,复制zoo_sample.cfg
cd /opt/zookeeper/apache-zookeeper-3.6.2-bin/conf
cp zoo_sample.cfg zoo.cfg
4、修改zoo.cfg
vi zoo.cgf
#修改
dataDir=/usr/opt/zookeeper/data
#添加
dataLogDir=/usr/opt/zookeeper/logs
clientPortAddress=10.10.171.157
server.0=10.10.171.157:2888:3888
server.1=10.10.171.158:2888:3888
server.2=10.10.171.159:2888:3888
#修改服务端口默认为8080
admin.serverPort=8887
5、在/opt/zookeeper/data下创建myid文件,并填写内容0(对应机器server.0=10.10.171.157...中的数字)
vim myid
#添加对应配置的数字
0
6、压缩/opt/zookeeper文件夹,scp到其他两台服务器
cd /opt/
zip -r zk.zip zookeeper.zip
scp zk.zip 10.10.171.158:/opt
scp zk.zip 10.10.171.159:/opt
7、分别修改/opt/zookeeper/apache-zookeeper-3.6.2-bin/conf/zoo.cgf文件中内容为对应ip,分别修改/opt/zookeeper/data/myid为对应数字
8、分别在3台机器上配置环境变量
vi /etc/profile
#添加
export ZOOKEEPER_HOME=/opt/zookeeper/apache-zookeeper-3.6.2-bin
export PATH=$PATH:$ZOOKEEPER_HOME/bin
9、使配置生效
source /etc/profile
10、按myid从小到大启动节点
zkServer.sh start
11、查看状态,如下启动成功
[root@node0 data]# zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/apache-zookeeper-3.6.2-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 10.10.171.157. Client SSL: false.
Mode: follower
[root@node1 data]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/apache-zookeeper-3.6.2-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 10.10.171.158. Client SSL: false.
Mode: leader
[root@node2 data]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/apache-zookeeper-3.6.2-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: 10.10.171.159. Client SSL: false.
Mode: follower