【zookeeper】apache-zookeeper-3.5.5的安装测试
下载:apache-zookeeper-3.5.5.tar.gz
进入zookeeper安装目录查看lib文件夹和zookeeper-3.5.5.jar是否存在,如果没有需要手动添加,不然启动时会报错。
注:启动失败时,可以进入out.log日志进行查看错误原因
[hadoop@hadoop01 apache-zookeeper-3.5.5]$ ls -l
total 176
drwxr-xr-x. 2 hadoop hadoop 232 Apr 9 19:13 bin
-rw-r--r--. 1 hadoop hadoop 94388 May 3 19:40 build.xml
drwxr-xr-x. 2 hadoop hadoop 120 Sep 20 00:45 conf
-rw-r--r--. 1 hadoop hadoop 411 Feb 15 2019 excludeFindBugsFilter.xml
-rw-r--r--. 1 hadoop hadoop 1709 Feb 15 2019 ivysettings.xml
-rw-r--r--. 1 hadoop hadoop 7597 Apr 9 19:13 ivy.xml
drwxr-xr-x. 2 root root 4096 Sep 20 00:02 lib
-rw-r--r--. 1 hadoop hadoop 11358 Feb 15 2019 LICENSE.txt
drwxrwxr-x. 2 hadoop hadoop 50 Sep 19 23:34 logs
-rw-r--r--. 1 hadoop hadoop 432 Apr 9 19:13 NOTICE.txt
-rw-r--r--. 1 hadoop hadoop 1398 Apr 2 21:05 owaspSuppressions.xml
-rw-r--r--. 1 hadoop hadoop 26485 May 3 19:40 pom.xml
-rw-r--r--. 1 hadoop hadoop 1560 May 3 19:41 README.md
-rw-r--r--. 1 hadoop hadoop 1347 Apr 2 21:05 README_packaging.txt
drwxr-xr-x. 3 hadoop hadoop 32 May 3 20:07 zookeeper-assembly
drwxr-xr-x. 3 hadoop hadoop 47 May 3 20:07 zookeeper-client
drwxr-xr-x. 12 hadoop hadoop 4096 May 3 19:40 zookeeper-contrib
drwxr-xr-x. 3 hadoop hadoop 32 May 3 20:07 zookeeper-docs
drwxr-xr-x. 3 hadoop hadoop 35 Feb 15 2019 zookeeper-it
drwxr-xr-x. 3 hadoop hadoop 32 May 3 20:07 zookeeper-jute
drwxr-xr-x. 5 hadoop hadoop 176 May 3 20:07 zookeeper-recipes
drwxr-xr-x. 7 hadoop hadoop 84 May 3 20:07 zookeeper-server
配置zookeeper:
进入安装目录下conf文件夹,执行下面命令对zoo_sample.cfg进行复制修改;
[hadoop@hadoop01 conf]$ cp zoo_sample.cfg zoo.cfg
[hadoop@hadoop01 conf]$ gedit zoo.cfg
添加内容:
server.1 = hadoop01:2888:3888
server.2 = hadoop02:2888:3888
server.3 = hadoop03:2888:3888
创建节点标识文件:
[hadoop@hadoop01 ~]$ mkdir -p /tmp/zookeeper
[hadoop@hadoop01 ~]$ gedit /tmp/zookeeper/myid
添加内容(输入对应服务器的ID号):
1
注:在其他节点也要进行同样设置,只是ID号不同
复制zookeeper安装文件:
scp -r apache-zookeeper-3.5.5 hadoop02:~/
scp -r apache-zookeeper-3.5.5 hadoop03:~/
测试zookeeper:
[hadoop@hadoop01 apache-zookeeper-3.5.5]$ bin/zkServer.sh start --启动hadoop01上的zookeeper
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@hadoop02 apache-zookeeper-3.5.5]$ bin/zkServer.sh start --启动hadoop02上的zookeeper
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@hadoop03 apache-zookeeper-3.5.5]$ bin/zkServer.sh start --启动hadoop03上的zookeeper
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[hadoop@hadoop01 apache-zookeeper-3.5.5]$ bin/zkServer.sh status --查看zookeeper集群启动状态
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
注1:如果服务器不启动两台以上,会报错
注2:我们可以看到下载hadoop01是follower,根据zookeeper工作原理,集群中应该有一个leader
[hadoop@hadoop02 apache-zookeeper-3.5.5]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/hadoop/apache-zookeeper-3.5.5/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
zookeeper客户端命令:
[hadoop@hadoop02 apache-zookeeper-3.5.5]$ bin/zkCli.sh -server hadoop02:2181 --进入命令模式
Connecting to hadoop02:2181
2019-09-20 01:08:45,673 [myid:] - INFO [main:Environment@109] - Client environment:zookeeper.version=3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT
2019-09-20 01:08:45,675 [myid:] - INFO [main:Environment@109] - Client environment:host.name=hadoop02
2019-09-20 01:08:45,676 [myid:] - INFO [main:Environment@109] - Client environment:java.version=1.8.0_11
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:java.vendor=Oracle Corporation
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:java.home=/usr/java/jdk1.8.0_11/jre
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:java.class.path=/home/hadoop/apache-zookeeper-3.5.5/bin/../zookeeper-server/target/classes:/home/hadoop/apache-zookeeper-3.5.5/bin/../build/classes:/home/hadoop/apache-zookeeper-3.5.5/bin/../zookeeper-server/target/lib/*.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../build/lib/*.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/zookeeper-jute-3.5.5.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/zookeeper-3.5.5.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/slf4j-log4j12-1.7.25.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/slf4j-api-1.7.25.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/netty-all-4.1.29.Final.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/log4j-1.2.17.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/json-simple-1.1.1.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jline-2.11.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jetty-util-9.4.17.v20190418.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jetty-servlet-9.4.17.v20190418.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jetty-server-9.4.17.v20190418.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jetty-security-9.4.17.v20190418.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jetty-io-9.4.17.v20190418.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jetty-http-9.4.17.v20190418.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/javax.servlet-api-3.1.0.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jackson-databind-2.9.8.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jackson-core-2.9.8.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/jackson-annotations-2.9.0.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/commons-cli-1.2.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../lib/audience-annotations-0.5.0.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../zookeeper-*.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../zookeeper-server/src/main/resources/lib/*.jar:/home/hadoop/apache-zookeeper-3.5.5/bin/../conf:
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:java.io.tmpdir=/tmp
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:java.compiler=<NA>
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:os.name=Linux
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:os.arch=amd64
2019-09-20 01:08:45,678 [myid:] - INFO [main:Environment@109] - Client environment:os.version=3.10.0-957.el7.x86_64
2019-09-20 01:08:45,679 [myid:] - INFO [main:Environment@109] - Client environment:user.name=hadoop
2019-09-20 01:08:45,679 [myid:] - INFO [main:Environment@109] - Client environment:user.home=/home/hadoop
2019-09-20 01:08:45,679 [myid:] - INFO [main:Environment@109] - Client environment:user.dir=/home/hadoop/apache-zookeeper-3.5.5
2019-09-20 01:08:45,679 [myid:] - INFO [main:Environment@109] - Client environment:os.memory.free=28MB
2019-09-20 01:08:45,681 [myid:] - INFO [main:Environment@109] - Client environment:os.memory.max=228MB
2019-09-20 01:08:45,681 [myid:] - INFO [main:Environment@109] - Client environment:os.memory.total=31MB
2019-09-20 01:08:45,685 [myid:] - INFO [main:ZooKeeper@868] - Initiating client connection, connectString=hadoop02:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@504bae78
2019-09-20 01:08:45,691 [myid:] - INFO [main:X509Util@79] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2019-09-20 01:08:45,701 [myid:] - INFO [main:ClientCnxnSocket@237] - jute.maxbuffer value is 4194304 Bytes
2019-09-20 01:08:45,708 [myid:] - INFO [main:ClientCnxn@1653] - zookeeper.request.timeout value is 0. feature enabled=
Welcome to ZooKeeper!
2019-09-20 01:08:45,715 [myid:hadoop02:2181] - INFO [main-SendThread(hadoop02:2181):ClientCnxn$SendThread@1112] - Opening socket connection to server hadoop02/192.168.1.101:2181. Will not attempt to authenticate using SASL (unknown error)
2019-09-20 01:08:45,722 [myid:hadoop02:2181] - INFO [main-SendThread(hadoop02:2181):ClientCnxn$SendThread@959] - Socket connection established, initiating session, client: /192.168.1.101:42902, server: hadoop02/192.168.1.101:2181
JLine support is enabled
[zk: hadoop02:2181(CONNECTING) 0] 2019-09-20 01:08:45,779 [myid:hadoop02:2181] - INFO [main-SendThread(hadoop02:2181):ClientCnxn$SendThread@1394] - Session establishment complete on server hadoop02/192.168.1.101:2181, sessionid = 0x200005e4ec10000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: hadoop02:2181(CONNECTED) 0] create /zk 'MyNode' --创建znode
Created /zk
[zk: hadoop02:2181(CONNECTED) 2] ls /zk --显示znode
[]
[zk: hadoop02:2181(CONNECTED) 4] quit --退出
WATCHER::
WatchedEvent state:Closed type:None path:null
2019-09-20 01:11:00,516 [myid:] - INFO [main:ZooKeeper@1422] - Session: 0x200005e4ec10000 closed
2019-09-20 01:11:00,516 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@524] - EventThread shut down for session: 0x200005e4ec10000
[hadoop@hadoop02 apache-zookeeper-3.5.5]$ --返回界面