zookeeper3.4.8伪集群安装

zookeeper3.4.8伪集群安装

软件包:zookeeper-3.4.8.tar.gz

Java包:jdk-8u77-linux-x64.gz

平台:centos6.2  64

在一台机器上安装3个伪zookeeper集群

server.1=localhost:2287:3390

server.2=localhost:2288:3388

server.3=localhost:2289:3389

安装过程:

首先安装jdk8

# mkdir /usr/lib/jdk(创建jdk安装目录)

# tar xf jdk-8u77-linux-x64.gz -C /usr/lib/jdk(解压jdk包)

# vim /etc/profile(设置环境变量)

profile末尾添加下面环境变量

export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_77

export JRE_HOME=/usr/lib/jdk/jdk1.8.0_77/jre

export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

# source /etc/profile(让环境变量生效)

# java -version(查看java版本)

java version "1.8.0_77"

Java(TM) SE Runtime Environment (build 1.8.0_77-b03)

Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

Jdk8安装成功后安装zookeeper

此处在同一台机器上模拟三个zookeeper集群节点,即叫伪集群

在真实环境部署时,只用把zoo.cfg中的localhost替换成真实节点的ip地址即可。

# mkdir -pv /home/hadoop/{zookeeper-1,zookeeper-2,zookeeper-3} (创建目录)

# mkdir -pv /home/hadoop/tmp/{zk1/data,zk1/log,zk2/data,zk2/log,zk3/data,zk3/log} (创建目录)

 #tar xf zookeeper-3.4.8.tar.gz (解压zookeeper包)

把解压的文件复制到不同的目录中

#cp -r zookeeper-3.4.8/* /home/hadoop/zookeeper-1/

#cp -r zookeeper-3.4.8/* /home/hadoop/zookeeper-1/

#cp -r zookeeper-3.4.8/* /home/hadoop/zookeeper-1/

# cd /home/hadoop/zookeeper-1/conf/

#vim zoo.cfg (创建配置文件)

在zoo.cfg添加如下内容

clientPort=2181 (客户端连接服务器的端口号)

tickTime=2000 (服务器心跳时间ms)

initLimit=10 (投票选举新leader的初始化时间)

syncLimit=5 (leader与follower最大响应时间)

dataDir=/home/hadoop/tmp/zk1/data (数据存放目录)

dataLogDir=/home/hadoop/tmp/zk1/log (日志存放目录)

server.1=localhost:2287:3390

server.2=localhost:2288:3388

server.3=localhost:2289:3389

# cd /home/hadoop/zookeeper-2/conf/

#vim zoo.cfg

clientPort=2182

tickTime=2000

initLimit=10

syncLimit=5

dataDir=/home/hadoop/tmp/zk2/data

dataLogDir=/home/hadoop/tmp/zk2/log

server.1=localhost:2287:3390

server.2=localhost:2288:3388

server.3=localhost:2289:3389

# cd /home/hadoop/zookeeper-3/conf/

#mv zoo_sample.cfg zoo.cfg

#vim zoo.cfg

clientPort=2183

tickTime=2000

initLimit=10

syncLimit=5

dataDir=/home/hadoop/tmp/zk3/data

dataLogDir=/home/hadoop/tmp/zk3/log

server.1=localhost:2287:3390

server.2=localhost:2288:3388

server.3=localhost:2289:3389

分别在zookeeper的数据目录创建myid,myid的内容为zoo.cfg配置文件中server.1中的1,2,或3

#echo “1” > /home/hadoop/tmp/zk1/data/myid
#echo “2” > /home/hadoop/tmp/zk2/data/myid

#echo “3” > /home/hadoop/tmp/zk3/data/myid

#/home/hadoop/zookeeper-1/bin/zkServer.sh start (启动zookeeper)

#/home/hadoop/zookeeper-2/bin/zkServer.sh start

#/home/hadoop/zookeeper-3/bin/zkServer.sh start

# ss -tnl

    

0      50                                   *:2181                                *:*     

0      50                                   *:2182                                *:*     

0      50                                   *:2183                                *:*    

 测试连接zookeeper

#/home/hadoop/zookeeper-1/bin/zkCli.sh -server localhost:2181

 

Connecting to localhost:2181

2016-04-07 12:29:35,556 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT

2016-04-07 12:29:35,564 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=pc0.zz.ha.cn

2016-04-07 12:29:35,564 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_77

2016-04-07 12:29:35,568 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation

2016-04-07 12:29:35,568 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jdk/jdk1.8.0_77/jre

2016-04-07 12:29:35,568 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/hadoop/zookeeper-3/bin/../build/classes:/home/hadoop/zookeeper-3/bin/../build/lib/*.jar:/home/hadoop/zookeeper-3/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/hadoop/zookeeper-3/bin/../lib/slf4j-api-1.6.1.jar:/home/hadoop/zookeeper-3/bin/../lib/netty-3.7.0.Final.jar:/home/hadoop/zookeeper-3/bin/../lib/log4j-1.2.16.jar:/home/hadoop/zookeeper-3/bin/../lib/jline-0.9.94.jar:/home/hadoop/zookeeper-3/bin/../zookeeper-3.4.8.jar:/home/hadoop/zookeeper-3/bin/../src/java/lib/*.jar:/home/hadoop/zookeeper-3/bin/../conf::.:/usr/lib/jdk/jdk1.8.0_77/lib:/usr/lib/jdk/jdk1.8.0_77/jre/lib

2016-04-07 12:29:35,568 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

2016-04-07 12:29:35,569 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp

2016-04-07 12:29:35,569 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>

2016-04-07 12:29:35,569 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux

2016-04-07 12:29:35,569 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64

2016-04-07 12:29:35,569 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=2.6.32-220.4.1.el6.centos.plus.x86_64

2016-04-07 12:29:35,569 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root

2016-04-07 12:29:35,569 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root

2016-04-07 12:29:35,570 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/hadoop/tmp/zk1/data

2016-04-07 12:29:35,572 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@67424e82

Welcome to ZooKeeper!

2016-04-07 12:29:35,624 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)

JLine support is enabled

2016-04-07 12:29:35,746 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session

[zk: localhost:2181(CONNECTING) 0] 2016-04-07 12:29:35,812 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x153eededdb50001, negotiated timeout = 30000

 

WATCHER::

 

WatchedEvent state:SyncConnected type:None path:null

 

[zk: localhost:2181(CONNECTED) 0] 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: localhost:2181(CONNECTED) 1]

到此zookeeper安装成功。

查看zookeeper状态

# zookeeper-1/bin/zkServer.sh status

JMX enabled by default

Using config: /home/hadoop/zookeeper-1/bin/../conf/zoo.cfg

Mode: follower

# zookeeper-2/bin/zkServer.sh status

JMX enabled by default

Using config: /home/hadoop/zookeeper-2/bin/../conf/zoo.cfg

Mode: leader

# zookeeper-3/bin/zkServer.sh status

JMX enabled by default

Using config: /home/hadoop/zookeeper-3/bin/../conf/zoo.cfg

Mode: follower

 

 

 


你可能感兴趣的:(安装,zookeeper,配置)