Zookeeper伪分布集群搭建及简单使用演示
按理说zookeeper至少要有三台主机才能玩,奈何我没用虚拟机也没有那么多主机,只能用伪分布式玩玩了。
要搭建Zookeeper完全分布式集群请戳这
第一步,下载Zookeeper稳定版
去官网下就可以了,http://mirrors.cnnic.cn/apache/zookeeper/stable/
我先科普一下
很多软件在正式发布前都会发布一些预览版或者测试版,一般都叫“beta版”或者 “rc版”,特别是开源软件,甚至有“alpha版”,下面来解释一下各个版本的意思。
alpha版:内部测试版。α是希腊字母的第一个,表示最早的版本,一般用户不要下载这个版本,这个版本包含很多BUG,功能也不全,主要是给开发人员和 测试人员测试和找BUG用的。
beta版:公开测试版。β是希腊字母的第二个,顾名思义,这个版本比alpha版发布得晚一些,主要是给“部落”用户和忠实用户测试用的,该版本任然存 在很多BUG,但是相对alpha版要稳定一些。这个阶段版本的软件还会不断增加新功能。如果你是发烧友,可以下载这个版本。
rc版:全写:Release Candidate(候选版本),该版本又较beta版更进一步了,该版本功能不再增加,和最终发布版功能一样。这个版本有点像最终发行版之前的一个类似 预览版,这个的发布就标明离最终发行版不远了。作为普通用户,如果你很急着用这个软件的话,也可以下载这个版本。
stable版:稳定版。在开源软件中,都有stable版,这个就是开源软件的最终发行版,用户可以放心大胆的用了。
商业软件
RTM版:全称为Release to Manufacture。工厂版。改版程序已经固定,就差工厂包装、光盘印图案等工作了。
OEM版:厂商定制版。
EVAL版:评估版。就是有30或者60天等使用期限的版本。
RTL版:Retail.(零售版),这个版本就是真正发售的版本,有漂亮的包装、光盘、说明书等东西和高昂的价格。
guo@guo:/opt$ sudo tar -zxf zookeeper-3.4.8.tar.gz zookeeper-3.4.8/
guo@guo:/opt$ cd ./zookeeper-3.4.8/
guo@guo:/opt/zookeeper-3.4.8$ ll
总用量 1588
drwxr-xr-x 10 guo guo 4096 2月 6 11:50 ./
drwxr-xr-x 6 root root 4096 3月 20 19:01 ../
drwxr-xr-x 2 guo guo 4096 2月 6 11:49 bin/
-rw-rw-r-- 1 guo guo 83235 2月 6 11:46 build.xml
-rw-rw-r-- 1 guo guo 88625 2月 6 11:46 CHANGES.txt
drwxr-xr-x 2 guo guo 4096 2月 6 11:49 conf/
drwxr-xr-x 10 guo guo 4096 2月 6 11:46 contrib/
drwxr-xr-x 2 guo guo 4096 2月 6 11:50 dist-maven/
drwxr-xr-x 6 guo guo 4096 2月 6 11:49 docs/
-rw-rw-r-- 1 guo guo 1953 2月 6 11:46 ivysettings.xml
-rw-rw-r-- 1 guo guo 3498 2月 6 11:46 ivy.xml
drwxr-xr-x 4 guo guo 4096 2月 6 11:49 lib/
-rw-rw-r-- 1 guo guo 11938 2月 6 11:46 LICENSE.txt
-rw-rw-r-- 1 guo guo 171 2月 6 11:46 NOTICE.txt
-rw-rw-r-- 1 guo guo 1770 2月 6 11:46 README_packaging.txt
-rw-rw-r-- 1 guo guo 1585 2月 6 11:46 README.txt
drwxr-xr-x 5 guo guo 4096 2月 6 11:46 recipes/
drwxr-xr-x 8 guo guo 4096 2月 6 11:49 src/
-rw-rw-r-- 1 guo guo 1360961 2月 6 11:46 zookeeper-3.4.8.jar
-rw-rw-r-- 1 guo guo 819 2月 6 11:50 zookeeper-3.4.8.jar.asc
-rw-rw-r-- 1 guo guo 33 2月 6 11:46 zookeeper-3.4.8.jar.md5
-rw-rw-r-- 1 guo guo 41 2月 6 11:46 zookeeper-3.4.8.jar.sha1
guo@guo:/opt/zookeeper-3.4.8$ cd conf/
guo@guo:/opt/zookeeper-3.4.8/conf$ ll
总用量 20
drwxr-xr-x 2 guo guo 4096 2月 6 11:49 ./
drwxr-xr-x 10 guo guo 4096 2月 6 11:50 ../
-rw-rw-r-- 1 guo guo 535 2月 6 11:46 configuration.xsl
-rw-rw-r-- 1 guo guo 2161 2月 6 11:46 log4j.properties
-rw-rw-r-- 1 guo guo 922 2月 6 11:46 zoo_sample.cfg
guo@guo:/opt/zookeeper-3.4.8/conf$ cp zoo_sample.cfg zoo.cfg
guo@guo:/opt/zookeeper-3.4.8/conf$ gedit zoo.cfg
zoo.cfg文件
# The number of milliseconds of each tick
#心跳多长时间2000毫秒(2s)
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.
#不要放在/tmp下,自己建一个
dataDir=/opt/zookeeper-3.4.8/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
如果是完全分布,要在文件最后加xx,看这里:
完全分布
第三步,配置环境变量(加上之后别忘了source)
guo@guo:~$ sudo gedit /etc/profile
[sudo] guo 的密码:
(gedit:7298): IBUS-WARNING **: The owner of /home/guo/.config/ibus/bus is not root!
(gedit:7298): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
guo@guo:~$ source /etc/profile
profile文件
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "$PS1" ]; then
if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
#java
export JAVA_HOME=/opt/Java/jdk1.8.0_73
export JRE_HOME=/opt/Java/jdk1.8.0_73/jre
export CLASSPATH=$JAVA_HOME/lib
export PATH=:$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
#hadoop
export HADOOP_HOME=/opt/Hadoop/hadoop-2.7.2
export PATH=$PATH:$HADOOP_HOME/sbin
export PATH=$PATH:$HADOOP_HOME/bin
#zookeeper
export ZOOKEEPER_HOME=/opt/zookeeper-3.4.8
export PATH=$PATH:$ZOOKEEPER_HOME/bin
第四步,启动!开始玩吧
guo@guo:~$ zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
guo@guo:~$ jps
3648 SecondaryNameNode
2130 org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
7429 Jps
3273 NameNode
4058 NodeManager
7403 QuorumPeerMain
3819 ResourceManager
3438 DataNode
guo@guo:~$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.8/bin/../conf/zoo.cfg
Mode: standalone
guo@guo:~$ zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2016-03-20 19:31:12,033 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT
2016-03-20 19:31:12,035 [myid:] - INFO [main:Environment@100] - Client environment:host.name=guo
2016-03-20 19:31:12,035 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_73
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/opt/Java/jdk1.8.0_73/jre
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/zookeeper-3.4.8/bin/../build/classes:/opt/zookeeper-3.4.8/bin/../build/lib/*.jar:/opt/zookeeper-3.4.8/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper-3.4.8/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper-3.4.8/bin/../lib/netty-3.7.0.Final.jar:/opt/zookeeper-3.4.8/bin/../lib/log4j-1.2.16.jar:/opt/zookeeper-3.4.8/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.8/bin/../zookeeper-3.4.8.jar:/opt/zookeeper-3.4.8/bin/../src/java/lib/*.jar:/opt/zookeeper-3.4.8/bin/../conf:/opt/Java/jdk1.8.0_73/lib
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:os.version=4.2.0-16-generic
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:user.name=guo
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/guo
2016-03-20 19:31:12,037 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/home/guo
2016-03-20 19:31:12,038 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@67424e82
Welcome to ZooKeeper!
2016-03-20 19:31:12,071 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2016-03-20 19:31:12,111 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@876] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
[zk: 127.0.0.1:2181(CONNECTING) 0] 2016-03-20 19:31:12,223 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x15393c6a9880000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 1] help
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port
[zk: 127.0.0.1:2181(CONNECTED) 2] ls /
[zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 3] create /guo hello
Created /guo
[zk: 127.0.0.1:2181(CONNECTED) 4] get /guo
hello
cZxid = 0x2
ctime = Sun Mar 20 19:36:01 CST 2016
mZxid = 0x2
mtime = Sun Mar 20 19:36:01 CST 2016
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 5
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 5] ls /
[guo, zookeeper]
更多推荐
所有评论(0)