zookeeper安装

一、安装

​ zk的安装比较简单,但是运行需要在jdk环境上运行。

​ 安装版本:zookeeper-3.4.5.tar.gz

1.查看是否有jdk环境,如果没有需要安装

[root@localhost bin]# java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

2.准备安装到哪里,可自己选择安装路径

[root@localhost zookeeper]# pwd
/opt/zookeeper

3.上传压缩包至这个文件夹,解压

​ tar -zxvf zookeeper-3.4.5.tar.gz

4.在zookeeper目录下(解压路径同一文件夹)建立一个data文件夹,为了存放运行zookeeper时,产生的数据日志文件

[root@localhost zookeeper]# ll
total 38216
drwxr-xr-x.  3 root root        49 Aug 19 08:44 data    //存放日志文件

5.进入zk的conf文件夹下,复制一份zoo.sample.cfg 重命名为zoo.cfg,然后vi编辑zoo.cfg修改其日志存放路径

1.进入配置文件夹
cd /opt/zookeeper/zookeeper-3.4.5/conf 
2.复制配置文件
cp zoo_sample.cfg zoo.cfg
3.修改配置文件
[root@localhost conf]# vi zoo.cfg 
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/opt/zookeeper/data   #修改日志文件夹
# the port at which the clients will connect
clientPort=2181
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

4. :wq 保存退出
5.进入bin目录下
[root@localhost bin]# ll
total 68
-rwxr-xr-x. 1  501 games   238 Sep 30  2012 README.txt
-rwxr-xr-x. 1  501 games  1909 Sep 30  2012 zkCleanup.sh
-rwxr-xr-x. 1  501 games  1049 Sep 30  2012 zkCli.cmd
-rwxr-xr-x. 1  501 games  1512 Sep 30  2012 zkCli.sh	#查看注册服务
-rwxr-xr-x. 1  501 games  1333 Sep 30  2012 zkEnv.cmd
-rwxr-xr-x. 1  501 games  2599 Sep 30  2012 zkEnv.sh
-rwxr-xr-x. 1  501 games  1084 Sep 30  2012 zkServer.cmd
-rwxr-xr-x. 1  501 games  5467 Sep 30  2012 zkServer.sh	#启动服务,根据不同命令效果不同;
-rw-r--r--. 1 root root  32735 Aug 19 10:12 zookeeper.out

6.启动zk服务
./zkServer.sh start	运行命令
./zkServer.sh status	查看状态
直接执行	./zkServer.sh 会提示你想要执行的操作
[root@localhost bin]# ./zkServer.sh
JMX enabled by default
Using config: /opt/zookeeper/zookeeper-3.4.5/bin/../conf/zoo.cfg
Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
如start启动,stop停止,status查看状态

7.查看服务,以dubbo为例
①
[root@localhost bin]# ./zkCli.sh
Connecting to localhost:2181
2018-08-19 10:46:33,381 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT
2018-08-19 10:46:33,385 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=localhost
2018-08-19 10:46:33,386 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_80
2018-08-19 10:46:33,386 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-08-19 10:46:33,387 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/opt/jdk/jdk1.7.0_80/jre
2018-08-19 10:46:33,387 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/opt/zookeeper/zookeeper-3.4.5/bin/../build/classes:/opt/zookeeper/zookeeper-3.4.5/bin/../build/lib/*.jar:/opt/zookeeper/zookeeper-3.4.5/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper/zookeeper-3.4.5/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper/zookeeper-3.4.5/bin/../lib/netty-3.2.2.Final.jar:/opt/zookeeper/zookeeper-3.4.5/bin/../lib/log4j-1.2.15.jar:/opt/zookeeper/zookeeper-3.4.5/bin/../lib/jline-0.9.94.jar:/opt/zookeeper/zookeeper-3.4.5/bin/../zookeeper-3.4.5.jar:/opt/zookeeper/zookeeper-3.4.5/bin/../src/java/lib/*.jar:/opt/zookeeper/zookeeper-3.4.5/bin/../conf:
2018-08-19 10:46:33,394 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-08-19 10:46:33,398 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-08-19 10:46:33,398 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=
2018-08-19 10:46:33,399 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2018-08-19 10:46:33,400 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2018-08-19 10:46:33,400 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-327.el7.x86_64
2018-08-19 10:46:33,401 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2018-08-19 10:46:33,402 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2018-08-19 10:46:33,402 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/opt/zookeeper/zookeeper-3.4.5/bin
2018-08-19 10:46:33,406 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@178374c9
2018-08-19 10:46:33,443 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@966] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
2018-08-19 10:46:33,449 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@849] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
JLine support is enabled
2018-08-19 10:46:33,510 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1207] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x165523777d20008, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] #上面一堆启动信息不用关注,接着输入 ls /
②
[zk: localhost:2181(CONNECTED) 0] ls /
[dubbo, zookeeper]
[zk: localhost:2181(CONNECTED) 1] 
③
[zk: localhost:2181(CONNECTED) 1] ls /dubbo
[com.cjy.service.DemoService]
④退出
[zk: localhost:2181(CONNECTED) 2] quit
Quitting...
2018-08-19 10:48:53,067 [myid:] - INFO  [main:ZooKeeper@684] - Session: 0x165523777d20008 closed
2018-08-19 10:48:53,072 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@509] - EventThread shut down
[root@localhost bin]# 

zk命令使用:https://blog.csdn.net/hll19950830/article/details/80241189

你可能感兴趣的:(分布式)