1 Building Steps
1.1 Download the project to GitHub
Project Address Https://github.com/apache/zookeeper. Download the. zip package to local decompression.
file directory after decompression:
1.2 using ant to compile the source code into Eclipse Engineering
The above source code is not an Eclipse project. You need to use the ant Eclipse command to convert to eclipse Engineering. Ant does not have to say again, self-search and configuration on the Internet.
CD Zookeeper-trunk
ant eclipse
Here's the point to focus on the failure of Ant Eclipse Execution:
The above command will download the ant-eclipse-1.0.bin.tar.bz2 file, always download unsuccessful, unable to continue, modify the source code in the Build.xml configuration, will address:
Get src= "http://downloads.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2"
Change to the following address
get src= "http://ufpr.dl.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2"
Also found missing dependency package commons-collections, add the following configuration in the Ivy.xml file:
<dependency org= "commons-collections" name= "commons-collections" rev= "3.0"/>
Once these two issues are resolved, then re-execute the ant Eclipse command. 1.3 importing Eclipse projects via idea
Set the compiler version of idea to 1.7. Then the whole world was quiet, finally no more error. 2 Running Zookeeper
We first look at the launch of the standalone version of the Zookeeper class Org.apache.zookeeper.server.ZooKeeperServerMain, its startup parameters in two cases:
Case 1: Give the corresponding parameter setting directly
There are 4 parameters, the first two parameters are required, the latter two parameters are optional, the client burst out of the port Port,datadir directory, Ticktime value, Maxclientcnxns value (maximum number of client connections). Here is a brief introduction to the following:
Port for client-side burst, which is the port specified by the following client code:
New ZooKeeper ("192.168.126.130:2181", 5000,this)
Directory of DataDir:
Zookeeper has two types of data to store. One is the transaction record, and the other is the data in the Zookeeper memory tree, stored as a snapshot. So you can specify a different directory for both types of data. DataDir is used to specify where the memory tree snapshot is stored, and datalogdir is used to specify where the transaction records are stored. Only the DataDir directory is given, which means that two kinds of data are stored in that directory. Ticktime value, Unit MS, default 3000:
Purpose 1: used to specify the interval for session checking, the server checks whether the session of the client connecting to it expires at a certain time. The interval is ticktime.
use 2: used to give the default Minsessiontimeout and Maxsessiontimeout, if not given Maxsessiontimeout and minsessiontimeout (1), Then the values of Minsessiontimeout and Maxsessiontimeout are as follows:
Minsessiontimeout = =-1? Ticktime 2:minsessiontimeout; Maxsessiontimeout = =-1? Ticktime 20:maxsessiontimeout;
the ticktime were twice times and 20 times times .
The client code gives a sessiontimeout time when creating the Zookeeper object, and the Minsessiontimeout and maxsessiontimeout above are used to constrain the sessiontimeout of the client. The source code is as follows:
The Maxclientcnxns value that specifies the maximum number of connections on the server side.
when the parameters are finished, let's set it up:
At the same time, Zookeeper uses log4j as the log output, so the log4j configuration file (in the Conf folder) needs to be placed under the classpath.
Scenario 2: Give the profile address
When the Org.apache.zookeeper.server.ZooKeeperServerMain class has only one startup parameter, it represents the path to the configuration file. You can also modify the Zoo_sample.cfg configuration file in the Conf folder to modify the path specified under DataDir. Then take the path of the configuration file as a parameter: