Zookeeper单机模式安装与配置

Zookeeper单机模式适合自己学习用,下面介绍CentOS6下安装过程

配置JDK

检查JAVA环境是否配置,配置好的如下:
[root@localhost bin]# java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)

配置JAVA环境
ORACLE官网下载jdk执行文件jdk-6u45-linux-i586.bin

复制至自己的目录
[root@localhost bin]# cp jdk-6u45-linux-i586.bin /usr/lib/jvm

赋予执行权限
[root@localhost bin]# chmod 755 jdk-6u45-linux-i586.bin

执行
[root@localhost bin]# ./jdk-6u45-linux-i586.bin

执行成功
Creating jdk1.6.0_45/jre/lib/jsse.jar
Creating jdk1.6.0_45/jre/lib/charsets.jar
Creating jdk1.6.0_45/lib/tools.jar
Creating jdk1.6.0_45/jre/lib/ext/localedata.jar
Creating jdk1.6.0_45/jre/lib/plugin.jar
Creating jdk1.6.0_45/jre/lib/javaws.jar
Creating jdk1.6.0_45/jre/lib/deploy.jar
 
Done.
[root@localhost jvm]# ls

配置环境变量
[root@localhost bin]# vim /etc/profile

在最后加上
# set java environment
export PATH=/usr/lib/jvm/jdk1.6.0_45/bin:$PATH
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_45

保存

使配置生效
[root@localhost bin]# source /etc/profile

检查JDK,这样就成功了
[root@localhost bin]# java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)

下载zookeeper压缩包

从Zookeeper的官方网站下载最新的安装包http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

解压至指定目录

# tar zxvf zookeeper-3.4.6.tar.gz -C /opt

复制zookeeper下conf目录下zoo_sample.cfg为zoo.cfg

# cp zoo_sample.cfg zoo.cfg
编辑zoo.cfg

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/zookeeper-3.4.6/data
# logs
dataLogDir=/opt/zookeeper-3.4.6/data/logs
clientPort=2181
tickTime:Zookeeper 心跳时间间隔。
dataDir:Zookeeper 保存数据的目录。

dataLogDir:Zookeeper 日志文件目录。

clientPort:Zookeeper 服务器监听端口。

可以启动zookeeper服务了,进入Zookeeper/bin目录,执行

# ./zkServer.sh start

查看zookeeper运行状态

# ./zkServer.sh status
启动后就可以用客户端连接了

# ./zkCli.sh

可以用help查看命令

[zk: localhost:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
	connect host:port
	get path [watch]
	ls path [watch]
	set path data [version]
	rmr path
	delquota [-n|-b] path
	quit 
	printwatches on|off
	create [-s] [-e] path data acl
	stat path [watch]
	close 
	ls2 path [watch]
	history 
	listquota path
	setAcl path acl
	getAcl path
	sync path
	redo cmdno
	addauth scheme auth
	delete path [version]
	setquota -n|-b val path

退出客户端

[zk: localhost:2181(CONNECTED) 1] quit
停止zookeeper服务

[root@localhost bin]# ./zkServer.sh stop
JMX enabled by default
Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@localhost bin]# 

好了这是基本的zookeeper单机模式的入门配置教程,单机模式只适合学习和Demo

你可能感兴趣的:(Zookeeper,Zookeeper)