1. Download zookeeper
http://zookeeper.apache.org/releases.html
I downloaded zookeeper-3.4.9.tar.gz
2. Unzip the tar -zxvf zookeeper-3.4.9.tar.gz
3. ZooKeeper software files and directories
bin directory zk executable script directory, including zk service process, zk client, and other scripts. Among them, .sh is the script in the Linux environment, and .cmd is the script in the Windows environment. conf directory Configuration file directory. zoo_sample.cfg is a sample configuration file, which needs to be changed to your own name, usually zoo.cfg. log4j.properties is the log configuration file. lib zk-dependent packages. contrib directory Some toolkits for manipulating zk. recipes directory Code examples for some usages of zk
4.conf zoo.cfg description
tickTime The duration is in milliseconds, the basic time measurement unit used by zk. For example, 1 * tickTime is the heartbeat time between the client and the zk server, and 2 * tickTime is the client session timeout. The default value of tickTime is 2000 milliseconds, lower tickTime values can detect timeout problems faster, but also result in higher network traffic (heartbeat messages) and higher CPU usage (trace processing of sessions). clientPort The TCP port that the zk service process listens to. By default, the server will listen to port 2181. dataDir No default configuration, must be configured, used to configure the directory where snapshot files are stored. If dataLogDir is not configured, transaction logs are also stored in this directory.
5. Start
windows do not say
In the Linux environment, enter the bin directory and execute the command ./zkServer.sh start
This command makes the zk service process run in the background. If you want to run in the foreground to view the output log of the server process, you can run the following command: ./zkServer.sh start-foreground
Executing this command, you can see the output of a lot of details to allow to see what happened to the server.
Open the zkServer.cmd or zkServer.sh file with a text editor, and you can see that it will call the zkEnv.cmd or zkEnv.sh script. The role of the zkEnv script is to set some environment variables for zk to run, such as the location and name of the configuration file.
Client connection bin/zkCli.sh -server 192.168.0.1:2181
reported an error
[root@localhost zookeeper-3.4.9]# bin/zkCli.sh - server 127.0.0.1:2181 Connecting to localhost:2181 2017-04-07 11:08:30,578 [myid:] - INFO [main:Environment@100] - Client environ ment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT 2017-04-07 11:08:30,706 [myid:] - INFO [main:Environment@100] - Client environ ment:host.name=localhost.localdomain 2017-04-07 11:08:30,709 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.4.2 2017-04-07 11:08:30,710 [myid:] - INFO [main:Environment@100] - Client environ ment:java.vendor=Free Software Foundation, Inc. 2017-04-07 11:08:30,711 [myid:] - INFO [main:Environment@100] - Client environ ment:java.home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre 2017-04-07 11:08:30,713 [myid:] - INFO [main:Environment@100] - Client environ ment:java.class.path=/opt/zookeeper-3.4.9/bin/../build/classes:/opt/zookeeper-3 .4.9/bin/../build/lib/*.jar:/opt/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1 .jar:/opt/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper-3.4.9/b in/../lib/netty-3.10.5.Final.jar:/opt/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.j ar:/opt/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.9/bin/ .. /zookeeper-3.4.9.jar:/opt/zookeeper -3.4.9 / bin /../ src / java / lib / *. Jar: / opt / zookee per-3.4.9 / bin /../ conf: 2017-04-07 11:08:30,715 [myid:] - INFO [main:Environment@100] - Client environ ment:java.library.path=/usr/lib/gcj-4.1.1 2017-04-07 11:08:30,716 [myid:] - INFO [main:Environment@100] - Client environ ment:java.io.tmpdir=/tmp 2017-04-07 11:08:30,717 [myid:] - INFO [main:Environment@100] - Client environ ment:java.compiler=<NA> 2017-04-07 11:08:30,718 [myid:] - INFO [main:Environment@100] - Client environ ment:os.name=Linux 2017-04-07 11:08:30,720 [myid:] - INFO [main:Environment@100] - Client environ ment:os.arch=i386 2017-04-07 11:08:30,722 [myid:] - INFO [main:Environment@100] - Client environ ment:os.version=2.6.18-8.el5xen 2017-04-07 11:08:30,724 [myid:] - INFO [main:Environment@100] - Client environ ment:user.name=root 2017-04-07 11:08:30,725 [myid:] - INFO [main:Environment@100] - Client environ ment:user.home=/root 2017-04-07 11:08:30,726 [myid:] - INFO [main:Environment@100] - Client environ ment:user.dir=/opt/zookeeper-3.4.9 2017-04-07 11:08:30,729 [myid:] - INFO [main:ZooKeeper@438] - Initiating clien t connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apa che.zookeeper.ZooKeeperMain$MyWatcher@49470 Exception in thread "main" java.lang.NoClassDefFoundError: java.util.concurrent .CopyOnWriteArraySet at org.apache.zookeeper.ClientCnxn.<init>(ClientCnxn.java:133) at org.apache.zookeeper.ClientCnxn.<init>(ClientCnxn.java:359) at org.apache.zookeeper.ZooKeeper.<init>(ZooKeeper.java:447) at org.apache.zookeeper.ZooKeeperMain.connectToZK(ZooKeeperMain.java:281) at org.apache.zookeeper.ZooKeeperMain.<init>(ZooKeeperMain.java:296) at org.apache.zookeeper.ZooKeeperMain.main(ZooKeeperMain.java:289) [root@localhost zookeeper-3.4.9]# [root@localhost zookeeper-3.4.9]# [root@localhost zookeeper-3.4.9]#
Obviously jdk is installed java.lang.NoClassDefFoundError: java.util.concurrent.CopyOnWriteArraySet
Don't talk nonsense, download jdk and install it here to refer to other people's blogs
Reference address: http://www.cnblogs.com/shihaiming/p/5809553.html
Detailed steps to install jdk8 under Linux As a Java developer, installing some development tools under Linux is a must-have skill. This article takes the installation of jdk as an example, and records the operation commands of each step in detail for reference. 0. Download jdk8 Login URL: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html Select the corresponding jdk version to download. (After the download is complete under Windows, it can be shared to Linux through a folder) 1. Log in to Linux and switch to root user su root to obtain root user permissions, the current working directory remains unchanged (requires root password) or sudo -i does not require root password to switch directly to root (requires current user password) 2. Create a java installation directory in the usr directory cd /usr mkdir java 3. Copy jdk-8u60-linux-x64.tar.gz to the java directory cp /mnt/hgfs/linux/jdk-8u60-linux-x64.tar.gz /usr/java/ 4. Unzip the jdk to the current directory tar -zxvf jdk-8u60-linux-x64.tar.gz get the folder jdk1.8.0_60 5. After installation, create a link for him to save directory length (I didn't use this step) ln -s /usr/java/jdk1.8.0_60/ /usr/jdk 6. Edit the configuration file and configure environment variables vim /etc/profile Add the following: JAVA_HOME is based on the actual directory JAVA_HOME=/usr/java/jdk1.8.0_60 CLASSPATH=$JAVA_HOME/lib/ PATH=$PATH:$JAVA_HOME/bin export PATH JAVA_HOME CLASSPATH 7. Restart the machine or execute the command: source /etc/profile sudo shutdown -r now 8. Check the installation java -version java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode) Possible error messages: bash: ./java: cannot execute binary file The reason for this error may be that a 64-bit jdk is installed on a 32-bit operating system, Check whether the bitness of the jdk version and the Linux version are the same. Check if your Ubuntu installation is 32-bit or 64-bit: sudo uname --m i686 //represents 32 bits x86_64 // means 64-bit
See http://www.joyphper.net/article/201303/185.html for solving permission problems