15 years old article, take some time to reprint it with MarkDown, look more comfortable, OCD can’t help it…
Click here to see
Content in this paper,
This article introduces the detailed steps of building zooKeeper pseudo-cluster
The cluster structures,
Recently, the company used ZooKeeper to do cluster management. Here is a step-by-step record of some of the experience and some reference for the future students. Since there is only one server here, the construction is actually a pseudo cluster, and the construction process of multiple servers is similar.
Cluster Building Environment
Distribution: CentOS6.6 64bIt the kernel:2.632.CPU: Intel i73.6Gb of memory:2G
Copy the code
Procedure for Setting up a cluster
Make sure the machine has JDK installed
[root@rocket ~]# java -version
openjdk version "1.8.0_51"
OpenJDK Runtime Environment (build 1.8.0_51-b16)
OpenJDK 64-Bit Server VM (build 25.51-b03, mixed mode)
Copy the code
If you cannot find the JDK, use yum to install it. If the distribution is not CentOS, search for the installation method of the corresponding distribution.
[root@rocket local]# yum -y install java
Copy the code
Download ZooKeeper and choose a suitable version
Find a suitable image on the official website to download. The image of beili is used here for download.
[root@rocket local]# wget http:/ / mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
Copy the code
When the download is complete, unzip the files to
[root@rocket local]# tar -zxvf zookeeper-3.4.6.tar.gz zookeeper-server1
[root@rocket local]# tar -zxvf zookeeper-3.4.6.tar.gz zookeeper-server2
[root@rocket local]# tar -zxvf zookeeper-3.4.6.tar.gz zookeeper-server3
Copy the code
Copying configuration Files
[root@rocket local]# cd /usr/local/zookeeper-server1/; cp conf/zoo_sample.cfg conf/zoo_test.cfg
[root@rocket local]# cd /usr/local/zookeeper-server2/; cp conf/zoo_sample.cfg conf/zoo_test.cfg
[root@rocket local]# cd /usr/local/zookeeper-server3/; cp conf/zoo_sample.cfg conf/zoo_test.cfg
Copy the code
Modifying a Configuration File
The main differences between the three nodes are the data directory and port.
zookeeper-server1
# 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
dataDir=/tmp/zookeeper-server1/data
dataLogDir=/tmp/zookeeper-server1/logs
# the port at which the clients will connect
clientPort=2181
server1.=127.0. 01.:7770:6660
server2.=127.0. 01.:7771:6660
server3.=127.0. 01.:7772:6660
Copy the code
zookeeper-server2
# 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
dataDir=/tmp/zookeeper-server2/data
dataLogDir=/tmp/zookeeper-server2/logs
# the port at which the clients will connect
clientPort=3181
server1.=127.0. 01.:7770:6660
server2.=127.0. 01.:7771:6660
server3.=127.0. 01.:7772:6660
Copy the code
zookeeper-server3
# 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
dataDir=/tmp/zookeeper-server3/data
dataLogDir=/tmp/zookeeper-server3/logs
# the port at which the clients will connect
clientPort=4181
server1.=127.0. 01.:7770:6660
server2.=127.0. 01.:7771:6660
server3.=127.0. 01.:7772:6660
Copy the code
Create the ZooKeeper running directory, data directory, and log directory
[root@rocket local]# mkdir -p zookeeper-server1/logs zookeeper-server1/data
[root@rocket local]# mkdir -p zookeeper-server2/logs zookeeper-server2/data
[root@rocket local]# mkdir -p zookeeper-server3/logs zookeeper-server3/data
Copy the code
View the current running directory:
[root@rocket tmp]# tree├── all exercises, all exercises, all exercises, all exercises, all exercises, all exercises, all exercises └ ─ ─ logsCopy the code
Create a file myID file in the data directory, and write the server ID of the current machine to each file
[root@rocket tmp]# echo "1" > zookeeper-server1/data/myid
[root@rocket tmp]# echo "2" > zookeeper-server2/data/myid
[root@rocket tmp]# echo "3" > zookeeper-server3/data/myid
Copy the code
Start ZooKeeper in each directory
[root@rocket local]# cd /usr/local/zookeeper-server1/; bin/zkServer.sh start
[root@rocket local]# cd /usr/local/zookeeper-server2/; bin/zkServer.sh start
[root@rocket local]# cd /usr/local/zookeeper-server3/; bin/zkServer.sh start
Copy the code
Viewing the Startup Status
[root@rocket zookeeper-server1]# cd /usr/local/zookeeper-server1/bin/zkServer.sh status
JMX enabled by defaultUsing config: /usr/local/zookeeper-server1/bin/.. /conf/zoo.cfg Mode: followerCopy the code
Notice that if you are prompted here
Error contacting service. It is probably not running.
Copy the code
The process fails to start or the cluster fails to be established. In this case, you need to view the Zookeeper. out log in the corresponding directory to locate the cause and rectify the fault.
Test the connection to the ZooKeeper cluster
[root@rocket local]# cd zookeeper-server1; bin/zkCli.sh -server localhost:2181
Copy the code
You can see that the connection is successful and the zooKeeper cluster is working.