Download the source code

This article uses Zookeeper 3.5.4 as an example, source code download address: github.com/apache/zook…

The source code to compile

There were some problems when compiling with Ant command line, and the solution was not found on the Internet. Therefore, IDEA was used to compile, and we hope that there are some big people who know the reason to guide us. The following is an error message after executing Ant Eclipse

The following is the detailed procedure

First open the project using IDEA

Right-click build.xml and select Add as Ant Build File

Expand the right Ant sidebar and double-click Eclipse

Wait for the build to complete. The time depends on the network environment

The eclipse configuration file is generated when the compilation is complete

Source import

Close the Project window and select File –> New –> Project from Existing Sources…

Select the project directory, select Import Eclipse project, and go all the way to Next

At this time the source code is imported successfully ~

Start the Zookeeper server

For the single-machine version and the cluster version, there are two startup classes:

  • LAN: ZooKeeperServerMain
  • Cluster: QuorumPeerMain

We only do stand-alone testing here

CFG copy zoo_sample. CFG in the conf directory and name it zoo.cfg

To configure the main startup class, select Add Configuration

Select add an Application

In figure 1, VM options; 2 is Main Class; 3 as the Program arguments

If you cannot find VM Options for version 2020, click Modify Options –> Add VM Options in the upper right corner

If you cannot find VM Options for version 2020, click Modify Options –> Add VM Options in the upper right corner

If you cannot find VM Options for version 2020, click Modify Options –> Add VM Options in the upper right corner

The configuration is as follows

The main class path: all org. Apache. Zookeeper. Server. Quorum. QuorumPeerMainCopy the code

Run the configured Application. If the log output is displayed, the Application is successfully started

Start the Zookeeper client

By running the QuorumPeerMain command to obtain the log, you can see that the ZooKeeper server has been started and the service address is 127.0.0.1:2182. Start the client to test the connection.

Client startup class for org. Apache. Zookeeper. ZooKeeperMain, configure the following:

Also add an Application

Run the configured Application

You can see that the connection is successful and you can type commands.