Zookeeper installation and configuration
-
Download Zookeeper
Go to the download page of Zookeeper
Select the stable version
Right click to copy the link address
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/apache-zookeeper-3.5.6-bin.tar.gz
Download using wget
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/apache-zookeeper-3.5.6-bin.tar.gz
-
Copy files
tar unzip
tar -zxf apache-zookeeper-3.5.6-bin.tar.gz
Copy the entire program to /usr/local/
cp -r apache-zookeeper-3.5.6-bin /usr/local/zookeeper
-
Configure Zookeeper
cd /usr/local/zookeeper cp zoo_sample.cfg zoo.cfg vi zoo.cfg
An example of the entire configuration file is as follows
# 服务器之间或客户端与服务器之间维持心跳的时间间隔 # tickTime以毫秒为单位。 tickTime=2000 # 集群中的follower服务器(F)与leader服务器(L)之间的初始连接心跳数 initLimit=10 # 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数 syncLimit=5 # 快照保存目录 # 不要设置为/tmp,该目录重新启动后会被自动清除 dataDir=/usr/local/zookeeper/zkdata # 日志保存目录 dataLogDir=/usr/local/zookeeper/zkdatalog # 客户端连接端口 clientPort=2181 # 客户端最大连接数。 # 根据自己实际情况设置,默认为60个 # maxClientCnxns=60 # 三个接点配置,格式为: # server.服务编号=服务地址、LF通信端口、选举端口 server.1=salve1:2888:3888 server.2=slave2:2888:3888 server.3=slave3:2888:3888
The service number followed by the multiple servers filled in above will be put into the myid of the corresponding machine later
for i in $(seq 1 3); do scp -r /usr/local/zookeeper Slave$i:/usr/local/zookeeper; done
Copied to each node but has not officially run
-
Create a working directory, configure myid
for i in $(seq 1 3); do ssh Slave$i 'mkdir -p /usr/local/zookeeper/zkdata'; done for i in $(seq 1 3); do ssh Slave$i 'mkdir -p /usr/local/zookeeper/zkdatalog'; done for i in $(seq 1 3); do ssh Slave$i 'touch /usr/local/zookeeper/zkdata/myid'; done
Then log in to each node to modify myid (the content depends on the zoo.cfg file above)
ssh Slave1 vi /usr/local/zookeeper/zkdata/myid
-
Configure environment variables
vi /etc/profile
Add the following content
export ZOOKEEPER_HOME=/usr/local/zookeeper
-
Start Zookeeper
Log in to each node to start zookeeper
ssh Slave1 cd /usr/local/zookeeper/bin ./zkServer.sh start
View zookeeper node status
./zkServer.sh status
Should be able to query the following information
Execute the following command
jps
Can be seen in the output
QuorumPeerMain
At this point Zookeeper distributed completion