zookeeper集群安装部署



1.下载安装zookeeper

#下载地址http://www.apache.org/dyn/closer.cgi/zookeeper

wget http://labs.mop.com/apache-mirror/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz

tar zxvf zookeeper-3.4.5.tar.gz -C  /usr/local/

mv zookeeper-3.4.5 zookeeper



2.配置zookeeper,以下操作在三台server上执行

#创建配置文件

cd /usr/local/zookeeper

cp zoo_sample.cfg zoo.cfg

vi zoo.cfg


tickTime=2000

initLimit=10

syncLimit=5

dataDir=/tmp/zookeeper

clientPort=2181

server.1=cc-monitor:2888:3888

server.2=cc-staging-front2:2888:3888

server.3=cc-staging-session:2888:3888


#创建数据目录

mkdir -p /tmp/zookeeper


#配置myid文件

dataDir目录下新建myid文件并设置id

id号即为zoo.cfg文件中server.后的数字,如server.1=cc-monitor:2888:3888即表示cc-monitor机器中的myid号为1

#分别在三台server设置对应的id

echo 1 > /tmp/zookeeper/myid

echo 2 > /tmp/zookeeper/myid

echo 3 > /tmp/zookeeper/myid


#添加环境变量

vi /etc/profile

export   ZOOKEEPER_HOME=/usr/local/zookeeper

export   PATH=$PATH:$ZOOKEEPER_HOME/bin


source /etc/profile



3.启动服务

# 启动zkserver,不报错就行

#$ZOOKEEPER_HOME/bin/zkServer.sh  start

JMX enabled by default

Using config:  /usr/local/zookeeper/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED


#查看三台zkserver的状态,1leader2follower

[root@cc-monitor conf]#  $ZOOKEEPER_HOME/bin/zkServer.sh status

JMX enabled by default

Using config:  /usr/local/zookeeper/bin/../conf/zoo.cfg

Mode: follower


[root@cc-staging-front2 conf]# $ZOOKEEPER_HOME/bin/zkServer.sh  status

JMX enabled by default

Using config:  /usr/local/zookeeper/bin/../conf/zoo.cfg

Mode: leader


[root@cc-staging-session conf]#  $ZOOKEEPER_HOME/bin/zkServer.sh status

JMX enabled by default

Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg

Mode: follower



4.进行同步测试

#在其中1台上创建文件

zkCli.sh -server  127.0.0.1:2181

create /mytest test


#在另外2台上进行查询,是否同步

[zk: 127.0.0.1:2181(CONNECTED) 0] ls /

[mytest, zookeeper]


[zk: 127.0.0.1:2181(CONNECTED) 2] get  /mytest

test

cZxid = 0x100000002

ctime = Wed Apr 24 22:45:04 PDT 2013

mZxid = 0x100000002

mtime = Wed Apr 24 22:45:04 PDT 2013

pZxid = 0x100000002

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 4

numChildren = 0

#




你可能感兴趣的:(zookeeper)