Install the Java environment and configure the Java-related environment variable $java_home.
1, download and extract the latest stable zookeeper files
wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
TAR-ZXVF zookeeper-3.4.6.tar.gz
The executable files are in the bin/directory, and the configuration is in the conf/directory
2. Generate Configuration file
conf/Directory has a zoo_sample.cfg, is a template configuration file
Copying a copy into zoo.cfg
There are two more important configurations:
Datadir=/home/gradven/zookeeper-3.4.6/data # Data storage location, can be modified as needed
CLIENTPORT=2181 # Service Listening port, can be modified as needed.
3. Start the service
bin/zkserver.sh start
If it does not start successfully, a check whether the Java_home is set correctly, two see if the port is conflicting
4. Start the client test
Start command:
Bin/zkcli.sh-server 127.0.0.1:2181
Displays the root directory, files:
LS/
Create the file and set the initial content:
[Zk:127.0.0.1:2181 (CONNECTED) 1] create/treeroot Hello
Created/treeroot
[Zk:127.0.0.1:2181 (CONNECTED) 2] Get/treeroot
Hello
Czxid = 0x2
CTime = Tue Oct 00:30:34 CST 2015
Mzxid = 0x2
Mtime = Tue Oct 00:30:34 CST 2015
Pzxid = 0x2
cversion = 0
dataversion = 0
aclversion = 0
Ephemeralowner = 0x0
Datalength = 5
Numchildren = 0
[Zk:127.0.0.1:2181 (CONNECTED) 3] Delete/treeroot
[Zk:127.0.0.1:2181 (CONNECTED) 4]
To exit the client:
Quit
View the status of zookeeper
[Email protected]:~/zookeeper-3.4.6$ bin/zkserver.sh Status
JMX enabled by default
Using config:/home/gradven/zookeeper-3.4.6/bin/. /conf/zoo.cfg
Mode:standalone
Restart Zookeeper command
[Email protected]:~/zookeeper-3.4.6$ bin/zkserver.sh status
JMX enabled by default
Using config:/home/gradven/zookeeper-3.4.6/bin/. /conf/zoo.cfg
Mode:standalone
[Email protected]:~/zookeeper-3.4.6$ bin/zkserver.sh Restart
JMX enabled by default
Using config:/home/gradven/zookeeper-3.4.6/bin/. /conf/zoo.cfg
JMX enabled by default
Using config:/home/gradven/zookeeper-3.4.6/bin/. /conf/zoo.cfg
Stopping zookeeper ... STOPPED
JMX enabled by default
Using config:/home/gradven/zookeeper-3.4.6/bin/. /conf/zoo.cfg
Starting zookeeper ... STARTED
Install zookeeper under Ubuntu