Zookeeper environment construction and configuration

1. zookeeper download

Zookeeper official website link: https://zookeeper.apache.org/

After entering its official website, select download to download the corresponding zookeeper version (I take 3.8.1 as an example here).
insert image description here

insert image description here

Here you can directly select the corresponding link of Http to download

insert image description here

After clicking, the download is complete, and soon...

insert image description here

2. Zookeeper installation and configuration

First, start the three nodes (node-01, node-02, node-03), and use XShell to remotely log in to the three hosts at the same time, and then open Xftp to transfer the installation package just downloaded.

insert image description here

insert image description here

2.1 Unzip the uploaded compressed package to the specified directory location

First switch to the uploaded directory /export/software, and then use the tar command to decompress it to a specific location (I am /export/servers/ here).

cd /export/software/ #切换目录
tar -zxvf apache-zookeeper-3.8.1.tar.gz -C /export/servers/ #解压到/export/servers/
cd /export/servers/ #切换目录
ll # 查看当前目录信息
mv apache-zookeeper-3.8.1 zookeeper-3.8.1 # 重命名
ll # 查看当前目录信息

insert image description here
insert image description here

2.2 Configure zookeeper environment variables and zookeeper configuration files

Configure environment variables, use the vi editor to modify the /etc/profile configuration file ( vi /etc/profile ), in its configuration file, add the following statement:

export ZK_HOME=/export/servers/zookeeper-3.8.1
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZK_HOME/bin

insert image description here

After modifying the environment variables, use the source command to refresh the configuration

source /etc/profile

Then switch to the zookeeper installation directory, find the conf folder, which contains the zoo-sample.cfg file, which is the zookeeper configuration file, rename it to zoo.cfg, and then use the vi editor to modify the configuration.

cd /export/servers/zookeeper-3.8.1/conf #切换到zookeeper的conf目录中
mv zoo-sample.cfg zoo.cfg #重命名
vi zoo.cfg #使用vi编辑器进行修改

The modified content is as follows:

# 指定数据文件目录+数据持久化路径
dataDir=/export/data/zookeeper/zkdata

# 配置zookeeper集群的服务器编号以及对应的主机名,选举端口号和通信端口号
server.1=node-01:2888:3888
server.2=node-02:2888:3888
server.3=node-03:2888:3888

insert image description here

2.3 Create zkdata folder

Because the /zookeeper/zkdata directory configured above does not exist, we need to create a zkdata folder and create a myid file in it (myid is used to set the server number and use the leader election).

cd /export/data/ #切换路径
mkdir -p zookeeper/zkdata #直接创建多级目录
ll #查看当前目录信息
cd zookeeper/zkdata
echo 1>myid #设定服务器编号为1

insert image description here

2.4 Forward and copy zookeeper and its configuration files to other nodes

Use the scp command for remote copying

First, remotely copy the files in the directory where zookeeper is installed to other nodes

scp -r /export/servers/zookeeper-3.8.1 node-02:/export/servers/
scp -r /export/servers/zookeeper-3.8.1 node-03:/export/servers/

Copy zkdata (the location where the myid server number is stored) to the other two nodes

scp -r /export/data/zookeeper/ node-02:/export/data/
scp -r /export/data/zookeeper/ node-03:/export/data/

Remotely copy the zookeeper environment variable configuration file to other nodes

scp -r /etc/profile node-02:/etc/profile
scp -r /etc/profile node-03:/etc/profile

2.5 Configure the myid (server id value) of the other two nodes

Configure the myid of the other two nodes to 2 and 3 respectively

cd /export/data/zookeeper/zkdata/
vi myid
# 修改为2
cat myid

insert image description here

cd /export/data/zookeeper/zkdata/
vi myid
# 修改为3
cat myid

insert image description here

2.6 Running tests

The configuration is ok, we just need to start zookeeper to see if it can start and stop normally, and we have observed the roles inside.

zkServer.sh start #启动
zkServer.sh status # 观察状态
zkServer.sh stop #停止

tip: Client port found: 2181. Client address: localhost. Client SSL: false. Error contacting service. It is probably not running.If this exception is reported, it means that the jdk version is incompatible, and you can replace it with a higher version of jdk or a lower version of zookeeper.


Guess you like

Origin blog.csdn.net/m0_63622279/article/details/129737751