伪分布式系列 - 第七篇 - zookeeper-环境搭建

目录

  • zookeeper架构
  • 环境准备
    • zookeeper下载
    • jvm安装
  • zookeeper配置
    • 目录
    • 配置
  • zk启动测试

zookeeper架构

  • zk分布式情况是master-slave架构,leader和follower,单节点的情况就是只有leader节点
    伪分布式系列 - 第七篇 - zookeeper-环境搭建_第1张图片

环境准备

zookeeper下载

  • 地址:http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.5.5/apache-zookeeper-3.5.5-bin.tar.gz
  • 解压: tar -zxvf apache-zookeeper-3.5.5-bin.tar.gz -C ./

jvm安装

  • 参考前文hadoop安装

zookeeper配置

目录

[root@ecs-6531-0002 default]# cd conf
[root@ecs-6531-0002 conf]# ll
总用量 12
-rw-r--r-- 1 2002 2002  535 2月  15 20:55 configuration.xsl
-rw-r--r-- 1 2002 2002 2712 4月   2 21:05 log4j.properties
-rw-r--r-- 1 2002 2002  922 2月  15 20:55 zoo_sample.cfg

配置

  • cp zoo_sample.cfg zoo.cfg
  • 创建zk存储目录
mkdir -p /data/zookeeper/data
  • vim 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=/data/zookeeper/data
# 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

#1 表示当前服务的id
# 2888端口号是zookeeper服务之间通信的端口。
# 3888端口是zookeeper与其他应用程序通信的端口。
server.1=localhost:2888:3888

zk启动测试

  • 启动zk服务进程 sh bin/zkServer.sh start
[root@ecs-6531-0002 default]# sh bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/zookeeper/default/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

[root@ecs-6531-0002 default]# jps
15728 SecondaryNameNode
12212 ResourceManager
12325 NodeManager
12710 JobHistoryServer
26858 QuorumPeerMain -- zk进程
5198 RunJar
26927 Jps

[root@ecs-6531-0002 default]# ./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/bigdata/zookeeper/default/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: standalone
  • 测试 启动zk客户端 sh bin/zkCli.sh
[root@ecs-6531-0002 default]# sh bin/zkCli.sh 
Connecting to localhost:2181
2019-08-04 19:05:45,189 [myid:] - INFO  [main:Environment@109] - Client environment:zookeeper.version=3.5.5-390fe37ea45dee01bf87dc1c042b5e3dcce88653, built on 05/03/2019 12:07 GMT
2019-08-04 19:05:45,193 [myid:] - INFO  [main:Environment@109] - Client environment:host.name=ecs-6531-0002.novalocal
2019-08-04 19:05:45,193 [myid:] - INFO  [main:Environment@109] - Client environment:java.version=1.8.0_121
2019-08-04 19:05:45,196 [myid:] - INFO  [main:Environment@109] - Client environment:java.vendor=Oracle Corporation
2019-08-04 19:05:45,196 [myid:] - INFO  [main:Environment@109] - Client environment:java.home=/usr/local/java_1.8.0_121/jre
2019-08-04 19:05:45,196 [myid:] - INFO  [main:Environment@109] - Client environment:java.class.path=/opt/bigdata/zookeeper/default/bin/../zookeeper-server/target/classes:/opt/bigdata/zookeeper/default/bin/../build/classes:/opt/bigdata/zookeeper/default/bin/../zookeeper-server/target/lib/*.jar:/opt/bigdata/zookeeper/default/bin/../build/lib/*.jar:/opt/bigdata/zookeeper/default/bin/../lib/zookeeper-jute-3.5.5.jar:/opt/bigdata/zookeeper/default/bin/../lib/zookeeper-3.5.5.jar:/opt/bigdata/zookeeper/default/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/bigdata/zookeeper/default/bin/../lib/slf4j-api-1.7.25.jar:/opt/bigdata/zookeeper/default/bin/../lib/netty-all-4.1.29.Final.jar:/opt/bigdata/zookeeper/default/bin/../lib/log4j-1.2.17.jar:/opt/bigdata/zookeeper/default/bin/../lib/json-simple-1.1.1.jar:/opt/bigdata/zookeeper/default/bin/../lib/jline-2.11.jar:/opt/bigdata/zookeeper/default/bin/../lib/jetty-util-9.4.17.v20190418.jar:/opt/bigdata/zookeeper/default/bin/../lib/jetty-servlet-9.4.17.v20190418.jar:/opt/bigdata/zookeeper/default/bin/../lib/jetty-server-9.4.17.v20190418.jar:/opt/bigdata/zookeeper/default/bin/../lib/jetty-security-9.4.17.v20190418.jar:/opt/bigdata/zookeeper/default/bin/../lib/jetty-io-9.4.17.v20190418.jar:/opt/bigdata/zookeeper/default/bin/../lib/jetty-http-9.4.17.v20190418.jar:/opt/bigdata/zookeeper/default/bin/../lib/javax.servlet-api-3.1.0.jar:/opt/bigdata/zookeeper/default/bin/../lib/jackson-databind-2.9.8.jar:/opt/bigdata/zookeeper/default/bin/../lib/jackson-core-2.9.8.jar:/opt/bigdata/zookeeper/default/bin/../lib/jackson-annotations-2.9.0.jar:/opt/bigdata/zookeeper/default/bin/../lib/commons-cli-1.2.jar:/opt/bigdata/zookeeper/default/bin/../lib/audience-annotations-0.5.0.jar:/opt/bigdata/zookeeper/default/bin/../zookeeper-*.jar:/opt/bigdata/zookeeper/default/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/bigdata/zookeeper/default/bin/../conf:.:/usr/local/java_1.8.0_121/lib/tools.jar:/usr/local/java_1.8.0_121/lib/dt.jar:.:/opt/bigdata/hive/default/lib
2019-08-04 19:05:45,196 [myid:] - INFO  [main:Environment@109] - Client environment:java.library.path=/opt/bigdata/hadoop/default/lib/native:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2019-08-04 19:05:45,196 [myid:] - INFO  [main:Environment@109] - Client environment:java.io.tmpdir=/tmp
2019-08-04 19:05:45,196 [myid:] - INFO  [main:Environment@109] - Client environment:java.compiler=<NA>
2019-08-04 19:05:45,197 [myid:] - INFO  [main:Environment@109] - Client environment:os.name=Linux
2019-08-04 19:05:45,197 [myid:] - INFO  [main:Environment@109] - Client environment:os.arch=amd64
2019-08-04 19:05:45,197 [myid:] - INFO  [main:Environment@109] - Client environment:os.version=3.10.0-862.9.1.el7.x86_64
2019-08-04 19:05:45,197 [myid:] - INFO  [main:Environment@109] - Client environment:user.name=root
2019-08-04 19:05:45,197 [myid:] - INFO  [main:Environment@109] - Client environment:user.home=/root
2019-08-04 19:05:45,197 [myid:] - INFO  [main:Environment@109] - Client environment:user.dir=/opt/bigdata/zookeeper/apache-zookeeper-3.5.5-bin
2019-08-04 19:05:45,197 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.free=235MB
2019-08-04 19:05:45,199 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.max=245MB
2019-08-04 19:05:45,199 [myid:] - INFO  [main:Environment@109] - Client environment:os.memory.total=245MB
2019-08-04 19:05:45,202 [myid:] - INFO  [main:ZooKeeper@868] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7e774085
2019-08-04 19:05:45,209 [myid:] - INFO  [main:X509Util@79] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2019-08-04 19:05:45,218 [myid:] - INFO  [main:ClientCnxnSocket@237] - jute.maxbuffer value is 4194304 Bytes
2019-08-04 19:05:45,226 [myid:] - INFO  [main:ClientCnxn@1653] - zookeeper.request.timeout value is 0. feature enabled=
Welcome to ZooKeeper!
2019-08-04 19:05:45,233 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1112] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2019-08-04 19:05:45,312 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@959] - Socket connection established, initiating session, client: /0:0:0:0:0:0:0:1:39538, server: localhost/0:0:0:0:0:0:0:1:2181
2019-08-04 19:05:45,334 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1394] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x107690b1fd20000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: localhost:2181(CONNECTING) 0] help
ZooKeeper -server host:port cmd args
	addauth scheme auth
	close 
	config [-c] [-w] [-s]
	connect host:port
	create [-s] [-e] [-c] [-t ttl] path [data] [acl]
	delete [-v version] path
	deleteall path
	delquota [-n|-b] path
	get [-s] [-w] path
	getAcl [-s] path
	history 
	listquota path
	ls [-s] [-w] [-R] path
	ls2 path [watch]
	printwatches on|off
	quit 
	reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
	redo cmdno
	removewatches path [-c|-d|-a] [-l]
	rmr path
	set [-s] [-v version] path data
	setAcl [-s] [-v version] [-R] path acl
	setquota -n|-b val path
	stat [-w] path
	sync path
Command not found: Command not found help

# 创建目录
[zk: localhost:2181(CONNECTED) 1] create /test
Created /test

[zk: localhost:2181(CONNECTED) 3] create /test/test01
Created /test/test01

# 设置目录值
[zk: localhost:2181(CONNECTED) 4] set /test/test01 "rolin"

# 获取目录值
[zk: localhost:2181(CONNECTED) 5] get /test/test01
rolin

#列出目录下文件
[zk: localhost:2181(CONNECTED) 6] ls /test
[test01]


[zk: localhost:2181(CONNECTED) 7] 

你可能感兴趣的:(zookeeper,大数据生态搭建系列,zookeeper)