ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户,今天做单机版,一台就够了。
实验环境:
主机名 | 系统 | IP地址 |
hadoop1 | CentOS 6.5 | 192.168.241.131 |
zookeeper3.4.9 的tar包链接为https://pan.baidu.com/s/1bpqZ9bHgzeri53AWgW2L4Q 提取码:sbp0 永久有效。
开始步骤:
检查jdk环境:为jdk1.8最好,随便什么方式安装都行。
java -version java version "1.8.0_152" Java(TM) SE Runtime Environment (build 1.8.0_152-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
1.解压修改配置文件,注意将zookeeper包解压在/data/soft目录下。
tar -xvf zookeeper-3.4.9.tar.gz mv zookeeper-3.4.9 zookeeper mv conf/zoo_sample.cfg conf/zoo.cfg
目录/data/soft需要自己先创建,至于后面的zookeeper/data里的data目录可以自己创建也行,或者改完后启动服务,系统会自动创建一个data目录。
vim conf/zoo.cfg dataDir=/data/soft/zookeeper/data
2.服务说明,里面有详细的使用参数
sh bin/zkServer.sh ZooKeeper JMX enabled by default Using config: /data/soft/zookeeper/bin/../conf/zoo.cfg Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
3.启动服务
sh bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /data/soft/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
查看服务是否启动完成
ps -ef|grep zookeeper root 5851 1 0 13:21 pts/0 00:00:01 /usr/local/jdk1.8.0_152/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /data/soft/zookeeper/bin/../build/classes:/data/soft/zookeeper/bin/../build/lib/*.jar:/data/soft/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/data/soft/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/data/soft/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/data/soft/zookeeper/bin/../lib/log4j-1.2.16.jar:/data/soft/zookeeper/bin/../lib/jline-0.9.94.jar:/data/soft/zookeeper/bin/../zookeeper-3.4.9.jar:/data/soft/zookeeper/bin/../src/java/lib/*.jar:/data/soft/zookeeper/bin/../conf:.:/usr/local/jdk1.8.0_152/lib/dt.jar:/usr/local/jdk1.8.0_152/lib/tools.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /data/soft/zookeeper/bin/../conf/zoo.cfg root 5944 2594 0 13:24 pts/0 00:00:00 grep zookeeper
查看服务状态,单机版为standalone模式,如下。
sh bin/zkServer.sh status ZooKeeper JMX enabled by default Using config: /data/soft/zookeeper/bin/../conf/zoo.cfg Mode: standalone
可以进入zookeeper的交互模式
sh bin/zkCli.sh Connecting to localhost:2181 2018-04-19 13:23:24,276 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/2016 06:50 GMT 2018-04-19 13:23:24,280 [myid:] - INFO [main:Environment@100] - Client environment:host.name=hadoop1 2018-04-19 13:23:24,280 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_152 2018-04-19 13:23:24,283 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation 2018-04-19 13:23:24,283 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/jdk1.8.0_152/jre 2018-04-19 13:23:24,283 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/data/soft/zookeeper/bin/../build/classes:/data/soft/zookeeper/bin/../build/lib/*.jar:/data/soft/zookeeper/bin/../lib/slf4j-log4j12-1.6.1.jar:/data/soft/zookeeper/bin/../lib/slf4j-api-1.6.1.jar:/data/soft/zookeeper/bin/../lib/netty-3.10.5.Final.jar:/data/soft/zookeeper/bin/../lib/log4j-1.2.16.jar:/data/soft/zookeeper/bin/../lib/jline-0.9.94.jar:/data/soft/zookeeper/bin/../zookeeper-3.4.9.jar:/data/soft/zookeeper/bin/../src/java/lib/*.jar:/data/soft/zookeeper/bin/../conf:.:/usr/local/jdk1.8.0_152/lib/dt.jar:/usr/local/jdk1.8.0_152/lib/tools.jar 2018-04-19 13:23:24,283 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2018-04-19 13:23:24,284 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2018-04-19 13:23:24,284 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2018-04-19 13:23:24,284 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2018-04-19 13:23:24,284 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2018-04-19 13:23:24,284 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-431.el6.x86_64 2018-04-19 13:23:24,284 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2018-04-19 13:23:24,284 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2018-04-19 13:23:24,284 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/data/soft/zookeeper 2018-04-19 13:23:24,287 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@579bb367 Welcome to ZooKeeper! 2018-04-19 13:23:24,386 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled 2018-04-19 13:23:24,539 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2018-04-19 13:23:24,579 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x162dc5a0a620000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] ls / [zookeeper]
4.停止服务
sh bin/zkServer.sh stop ZooKeeper JMX enabled by default Using config: /data/soft/zookeeper/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED
查看服务是否关闭。
ps -ef|grep zookeeper root 5967 2594 0 13:25 pts/0 00:00:00 grep zookeeper
这是简单的单机版,我尽量做得简单,快速,直接,希望朋友们多多支持!!!