Article directory
1. Zookeeper official website download
- Download address: https://archive.apache.org/dist/zookeeper/
- Find the corresponding version to download
2. JDK environment installation
- Directly use
yum
the command to install online
yum install -y java-1.8.0-openjdk.x86_64
- Environment variable configuration
sudo vi /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_291/
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
- Reload configuration file
sudo source /etc/profile
3. Zookeeper installation
1.zookeeper decompression
- First upload the downloaded
apache-zookeeper-3.5.9-bin.tar.gz
to the server - Unzip and install to
/usr/local/
directory
tar -zxvf apache-zookeeper-3.5.9-bin.tar.gz -C /usr/local/
-
As shown below
-
Rename to
zookeeper
mv apache-zookeeper-3.5.9-bin zookeeper
- As shown below
2.Zookeeper configuration file introduction
- Enter
zookeeper
configuration fileusr/local/zookeeper/conf/
zoo_sample.cfg
Rename the configuration file tozoo.cfg
mv zoo_sample.cfg zoo.cfg
- Configuration file introduction
# The number of milliseconds of each tick
# 用于计算基础的实际单位
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
# 初始化时间
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
# 选举时间
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
# 配置zookeeper数据存放路径
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
- First,
zookeeper
create a directory for storing data and logs under the directoryzookeeper
, and add file read and write permissions.
mkdir data
sudo chmod 777 data
mkdir logs
sudo chmod 777 logs
- As shown in the picture
- Modify configuration file
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
- Cluster configuration
# 集群配置 2888:选举端口 3888:投票端口
server.1=server001:2888:3888
server.2=server002:2888:3888
server.3=server003:2888:3888
- KAFKA001 represents the host name, and you can also write the IP address.
- View hostname
hostnamectl
- Set hostname
sudo hostnamectl set-hostname server001
/usr/local/zookeeper/data
Add the unique identifier of this machine cluster to the previously created data directory.- write
1
- Note:
myid
The data insideservice一致
echo "1" > myid
- Configuration
host
filevi /etc/hosts
adds the host names and IP addresses of the three clusters
192.168.204.130 server001
192.168.204.131 server002
192.168.204.132 server003
- As shown below
Clone server
- For detailed operations, see this article: VMware virtual machine cloning and virtual machine copying
1. Network check
- After cloning, check that the three servers can access each other's IP addresses.
2. Cluster configuration
- Remember to modify the host names of the next two servers
sudo hostnamectl set-hostname server002
sudo hostnamectl set-hostname server003
- In the previously created
/usr/local/zookeeper/data
data directory, add the unique identifier of this machine cluster [modify the last two] - The latter two machines write respectively
2
,3
echo "2" > myid
echo "3" > myid
3. Start the cluster
- Enter
/usr/local/zookeeper/bin
the directory and execute./zkServer.sh start
# 可在三台服务器分别执行
/usr/local/zookeeper/bin/zkServer.sh start
- check status
# 可在三台服务器分别执行
/usr/local/zookeeper/bin/zkServer.sh status
- As shown below
4.Error record
- In case of abnormality
ERROR
- Execute the command
./zkServer.sh start-foreground
and read the error details in the log to further determine the cause of the error.
/usr/local/zookeeper/bin/zkServer.sh start-foreground
- You need to first rule out that the firewall is turned off. Related commands: CentOS7 [Manage Firewall Port Command]