Zookeeper cluster construction and deployment

1.Zookeeper introduction

Zookeeper is a distributed coordination component developed by Yahoo based on Chubby’s ideas and later donated to Apache. It is mainly used to solve distributed data consistency problems. Distributed applications can implement functions such as data publishing/subscription, load balancing, naming service, distributed coordination/notification, cluster management, Master election, configuration management, distributed locks and distributed queues based on it.

2. Zookeeper cluster construction and deployment

(1) Installation and configuration of zookeeper

1. Unzip the zookeeper installation package

①Enter the official website to download zookeeper

②Upload the zk package to the hadoop01 directory

rz upload zk package

③View the directory of the zk compressed package

④Unzip

tar -zxvf zookeeper-3.4.6.tar.gz -C ../ruanjian/ decompression

⑤Extract execution results and create soft connections

ln -s zookeeper-3.4.6/ zookeeper creates a soft connection

2. Modify the configuration file

①Modify configuration file

vim /etc/profile

②Configure environment variables

export ZK_HOME=/opt/ruanjian/zookeeper
export PATH=$PATH:$ZK_HOME/bin

③Save and exit

wq

④Use scp to copy environment variables to hadoop02 node

scp /etc/profile root@hadoop02:/etc/profile

⑤Use scp to copy environment variables to hadoop03 node

scp /etc/profile root@hadoop03:/etc/profile

(2) Modify configuration file

1. Modify the configuration file

①Switch to the zk configuration file

cd conf switch to zk configuration file
ll View directory

②Change the configuration file name

mv zoo_sample.cfg zoo.cfg

③Edit the zoo.cfg file

vim zoo.cfg

④Parameter modification

dataDir=/opt/ruanjian/zookeeper/zkdata

ruanjian.1=hadoop01:2888:3888
ruanjian.2=hadoop02:2888:3888
ruanjian.3=hadoop03:2888:3888

⑤Create data file directory

mkdir zkdata

⑥Create myid file

cd zkdata/
vim myid

⑦Set myid

2. Distribute to other nodes

①Use scp to copy jdk to hadoop02 node

scp -r zookeeper-3.4.6/ root@hadoop02:/opt/ruanjian/

②Execution results

③Use scp to copy jdk to hadoop03 node

scp -r zookeeper-3.4.6/ root@hadoop03:/opt/ruanjian/

④Execution results

⑤Modify the value of myid on hadoop02

vim myid

⑥Modify the value of myid on hadoop03

vim myid

(3) Starting and stopping the zookeeper cluster

1. Start the zookeeper cluster

①Switch to the bin file directory of zk

 cd /opt/ruanjian/zookeeper/bin/

②Hadoop01 starts zk

./zkServer.sh start

③Hadoop02 starts zk

./zkServer.sh start

④Hadoop03 starts zk

./zkServer.sh start

⑤hadoop01 Check zk status

zkServer.sh status

⑥hadoop02 Check zk status

zkServer.sh status

⑦hadoop03 Check zk status

zkServer.sh status

⑧Use jps to view the hadoop01 process

jps

⑨Use jps to view the hadoop02 process

jps

⑩Use jps to view the hadoop03 process

jps

2. Stop the zookeeper cluster

①Stop the zk cluster on hadoop01

zkServer.sh stop

②Stop the zk cluster on hadoop02

zkServer.sh stop

③Stop the zk cluster on hadoop03

zkServer.sh stop

(4) Edit the zk cluster start and stop script

1. Edit script file

①Switch to the script file directory

 cd /opt/script/

②Edit the zk.sh cluster control script

vim zk.sh

③Script file

④ Check whether the script file has been created

ll

⑤Authorization

chmod 777 zk.sh

2. Start and stop the zk cluster

./zk.sh start

②View the process

jps

③02.03 Host view process

④. Check cluster status with one click

 ./zk.sh status

⑤Stop the zk cluster

./zk.sh stop

⑥View the process

jps

⑦View zk end status

?
./zk.sh status

?