Zookeeper: local installation and cluster installation

Local installation

1. Upload the zookeeper package to /opt/software

2. Unzip
tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/

3. Change the name (under /opt/module)
mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7

4. Configure environment variables
. Edit the file
sudo vim /etc/profile.d/my_env.sh
and add
export ZOOKEEPER_HOME=/opt/module/zookeeper-3.5.7
export PATH= PATH : PATH:PATH:ZOOKEEPER_HOME/bin

5. Let the environment variables take effect
① Disconnect and reconnect
② source /etc/profile.d/my_env.sh

6. Modify the configuration file.
Enter the directory
cd /opt/module/zookeeper-3.5.7/conf
and modify the file name.
mv zoo_sample.cfg zoo.cfg.
Edit zoo.cfg.
vim zoo.cfg.
Modify
dataDir=/opt/module/zookeeper-3.5. .7/zkData

(创建目录 mkdir /opt/module/zookeeper-3.5.7/zkData)

7. Start zookeeper | View status
zkServer.sh start | status

8. Start the client
zkCli.sh

9. Quit the client
quit

Configuration parameters

1) tickTime = 2000: communication heartbeat time, Zookeeper server and client heartbeat time, unit milliseconds
Insert image description here

2) initLimit = 10: LF initial communication time limit
Insert image description here

The maximum number of heartbeats (the number of tickTimes) that the Leader and Follower can tolerate during the initial connection
3) syncLimit = 5: LF synchronization communication time limit
Insert image description here

If the communication time between the Leader and Follower exceeds syncLimit * tickTime, the Leader considers the Follower to be dead and deletes the Follower from the server list.
4) dataDir: Save data in Zookeeper
Note: The default tmp directory is easily deleted regularly by the Linux system, so the default tmp directory is generally not used.

5) clientPort = 2181: Client connection port, usually not modified.

Cluster installation

1. Modify after the local mode is configured

2. Stop the ZK service first (if it cannot be stopped, kill it and restart linux)
zkServer.sh stop

3. Delete the data in zkData
cd /opt/module/zookeeper-3.5.7/zkData
rm -rf ./*

4. Create the myid file in the zkData directory
touch myid
and write the id value of the node in the file
hadoop102 (write) ----> 2
hadoop103 (write) ----> 3
hadoop104 (write) ----> 4

5. Modify the configuration file
cd /opt/module/zookeeper-3.5.7/conf

vim zoo.cfg
添加如下内容
server.2=hadoop102:2888:3888
server.3=hadoop103:2888:3888
server.4=hadoop104:2888:3888

(说明:server.myid的值=myid对应的服务器的地址:zk通讯端口号:zk选举Leader的端口号)

6. Distribution (synchronization)
xsync /opt/module/zookeeper-3.5.7

7. Do the following operations on hadoop103 and hadoop104
① Configure environment variables (synchronize on hadoop102)
rsync -av /etc/profile.d/my_env.sh root@hadoop104:/etc/profile.d/
rsync -av /etc/ profile.d/my_env.sh root@hadoop103:/etc/profile.d/
Let hadoop103 and hadoop104 environment variables take effect
② Modify the value of myid
hadoop103 (write)---->3
hadoop104 (write)---->4

8. Start Server on each node
zkServer.sh start
zkServer.sh status

group script

zkCluster.sh

#!/bin/bash

#判断参数的个数
if [ $# -ne 1 ]
	then
		echo "参数的个数不对!!!"
		exit
fi

#判断参数的内容
var=""
case $1 in
"start")
	var=start
	;;
"stop")
	var=stop
	;;
"status")
	var=status
	;;
*)
	echo "输入的参数内容不对!!!"
	exit
	;;
esac

for host in hadoop102 hadoop103 hadoop104
do
	echo ====================$host==============================
	ssh $host zkServer.sh $var
done

Guess you like

Origin blog.csdn.net/weixin_45427648/article/details/131756608