Ubuntu 14.04 下,Zookeeper 3.4.13 单机部署

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yitengtongweishi/article/details/81872307

安装 Java

Ubuntu 14.04 下,安装 Java8

下载 Zookeeper

http://archive.apache.org/dist/zookeeper/,笔者选择的是 zookeeper-3.4.13.tar.gz。
对其进行校验,

blockchain@Dao:~/Downloads$ 
blockchain@Dao:~/Downloads$ md5sum zookeeper-3.4.13.tar.gz
c380eb03049998280895078d570cb944  zookeeper-3.4.13.tar.gz
blockchain@Dao:~/Downloads$ 
blockchain@Dao:~/Downloads$ cat zookeeper-3.4.13.tar.gz.md5 
c380eb03049998280895078d570cb944  zookeeper-3.4.13.tar.gz
blockchain@Dao:~/Downloads$ 

校验通过。

解压 Zookeeper

blockchain@Dao:~$ tar -zxvf Downloads/zookeeper-3.4.13.tar.gz -C ~

修改 Zookeeper 配置文件

进入 zookeeper 的 conf 目录下,找到 zoo_sample.cfg 文件。首先将 zoo_sample.cfg 文件备份,并重命名为 zoo.cfg

blockchain@Dao:~/zookeeper-3.4.13/conf$ cp zoo_sample.cfg zoo.cfg 

编辑 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=/home/blockchain/tmp/zookeeper
#dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# 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

其中,
tickTime:zookeeper 服务器之间或客户端与服务器之间心跳的时间间隔。
dataDir:zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
clientPort:zookeeper 服务器监听端口,用来接受客户端的访问请求。
maxClientCnxns:zookeeper能够接收的最大客户端连接数。

dataDir 默认是 /tmp/zookeeper,由于 /tmp 是 Ubuntu 的 临时目录,这个路径下的数据不能长久保存,因此需要指定到别的目录。

启动 Zookeeper

blockchain@Dao:~/zookeeper-3.4.13$ 
blockchain@Dao:~/zookeeper-3.4.13$ ./bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/blockchain/zookeeper-3.4.13/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
blockchain@Dao:~/zookeeper-3.4.13$ 
blockchain@Dao:~/zookeeper-3.4.13$ jps
31392 Jps
25248 QuorumPeerMain
blockchain@Dao:~/zookeeper-3.4.13$ 

使用 status 参数来查看 zookeeper 的状态

blockchain@Dao:~/zookeeper-3.4.13$ ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/blockchain/zookeeper-3.4.13/bin/../conf/zoo.cfg
Mode: standalone
blockchain@Dao:~/zookeeper-3.4.13$ 

可以看出,这个 zookeeper 处于 standalone 状态。

Zookeeper 客户端

./zkCli.sh -server ip:port,默认端口为2181

blockchain@Dao:~/zookeeper-3.4.13$ bin/zkCli.sh -server localhost:2181
Connecting to localhost:2181
2018-08-20 15:37:32,606 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on 06/29/2018 04:05 GMT
2018-08-20 15:37:32,608 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=Dao
2018-08-20 15:37:32,608 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_181
2018-08-20 15:37:32,609 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-08-20 15:37:32,609 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/home/blockchain/jdk1.8.0_181/jre
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/blockchain/zookeeper-3.4.13/bin/../build/classes:/home/blockchain/zookeeper-3.4.13/bin/../build/lib/*.jar:/home/blockchain/zookeeper-3.4.13/bin/../lib/slf4j-log4j12-1.7.25.jar:/home/blockchain/zookeeper-3.4.13/bin/../lib/slf4j-api-1.7.25.jar:/home/blockchain/zookeeper-3.4.13/bin/../lib/netty-3.10.6.Final.jar:/home/blockchain/zookeeper-3.4.13/bin/../lib/log4j-1.2.17.jar:/home/blockchain/zookeeper-3.4.13/bin/../lib/jline-0.9.94.jar:/home/blockchain/zookeeper-3.4.13/bin/../lib/audience-annotations-0.5.0.jar:/home/blockchain/zookeeper-3.4.13/bin/../zookeeper-3.4.13.jar:/home/blockchain/zookeeper-3.4.13/bin/../src/java/lib/*.jar:/home/blockchain/zookeeper-3.4.13/bin/../conf:.:/home/blockchain/jdk1.8.0_181/lib:/home/blockchain/jdk1.8.0_181/jre/lib
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=4.4.0-133-generic
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=blockchain
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/blockchain
2018-08-20 15:37:32,610 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/blockchain/zookeeper-3.4.13
2018-08-20 15:37:32,611 [myid:] - INFO  [main:ZooKeeper@442] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@277050dc
Welcome to ZooKeeper!
2018-08-20 15:37:32,626 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1029] - 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-08-20 15:37:32,677 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@879] - Socket connection established to localhost/127.0.0.1:2181, initiating session
[zk: localhost:2181(CONNECTING) 0] 2018-08-20 15:37:32,700 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1303] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x100003ba51c0001, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: localhost:2181(CONNECTED) 0] 
[zk: localhost:2181(CONNECTED) 0] 
[zk: localhost:2181(CONNECTED) 0] 

至此,zookeeper 单机部署完成,可以满足绝大部分日常开发所需。

猜你喜欢

转载自blog.csdn.net/yitengtongweishi/article/details/81872307