安装zookeeper需要先安装java,请看linux centos 安装java jdk
下载zookeeper并解压
zookeeper下载链接:http://archive.apache.org/dist/zookeeper/
解压zookeeper
tar -zxvf zookeeper-3.4.5.tar.gz
建立zoo.cfg配置文件
在conf目录,把zoo_sample.cfg复制成zoo.cfg,使用默认配置
cd zookeeper-3.4.5/conf
cp zoo_sample.cfg zoo.cfg
配置文件中,各个语句的含义:
tickTime : 服务器与客户端之间交互的基本时间单元(ms)
dataDir : 保存zookeeper数据路径
dataLogDir : 保存zookeeper日志路径,当此配置不存在时默认路径与dataDir一致
clientPort : 客户端访问zookeeper时经过服务器端时的端口号
可以自己修改相应的配置
启动或停止zookeeper的命令
./bin/zkServer.sh start
./bin/zkServer.sh stop
./bin/zkServer.sh restart
./bin/zkServer.sh status
客户端查看是否安装成功
./bin/zkCli.sh
启动zookeeper后启动客户端,出现下面信息,表示安装成功:
[root@localhost zookeeper-3.4.0]# ./bin/zkCli.sh Connecting to localhost:2181 2018-09-15 08:11:45,304 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.4.0-1202560, built on 11/16/2011 07:18 GMT 2018-09-15 08:11:45,312 [myid:] - INFO [main:Environment@98] - Client environment:host.name=localhost 2018-09-15 08:11:45,312 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_181 2018-09-15 08:11:45,312 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Oracle Corporation 2018-09-15 08:11:45,313 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/usr/local/src/jdk1.8.0_181/jre 2018-09-15 08:11:45,313 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../build/classes:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../build/lib/*.jar:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../lib/netty-3.2.2.Final.jar:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../lib/log4j-1.2.15.jar:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../lib/jline-0.9.94.jar:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../zookeeper-3.4.0.jar:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../src/java/lib/*.jar:/usr/local/application/zookeeper/zookeeper-3.4.0/bin/../conf:.:/usr/local/src/jdk1.8.0_181/jre/lib/rt.jar:/usr/local/src/jdk1.8.0_181/lib/dt.jar:/usr/local/src/jdk1.8.0_181/lib/tools.jar 2018-09-15 08:11:45,313 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2018-09-15 08:11:45,313 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/tmp 2018-09-15 08:11:45,314 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=<NA> 2018-09-15 08:11:45,314 [myid:] - INFO [main:Environment@98] - Client environment:os.name=Linux 2018-09-15 08:11:45,314 [myid:] - INFO [main:Environment@98] - Client environment:os.arch=amd64 2018-09-15 08:11:45,314 [myid:] - INFO [main:Environment@98] - Client environment:os.version=3.10.0-862.el7.x86_64 2018-09-15 08:11:45,315 [myid:] - INFO [main:Environment@98] - Client environment:user.name=root 2018-09-15 08:11:45,315 [myid:] - INFO [main:Environment@98] - Client environment:user.home=/root 2018-09-15 08:11:45,315 [myid:] - INFO [main:Environment@98] - Client environment:user.dir=/usr/local/application/zookeeper/zookeeper-3.4.0 2018-09-15 08:11:45,316 [myid:] - INFO [main:ZooKeeper@433] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@4b85612c 2018-09-15 08:11:45,341 [myid:] - INFO [main-SendThread():ClientCnxn$SendThread@933] - Opening socket connection to server /0:0:0:0:0:0:0:1:2181 Welcome to ZooKeeper! JLine support is enabled 2018-09-15 08:11:45,454 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@846] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session 2018-09-15 08:11:45,485 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1181] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x165dd1fc7540002, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0]