您的位置:首页 > 其它

zookeeper伪集群搭建

2017-08-01 11:06 148 查看
zookeeper伪集群搭建
由于刚开始做了一些测试,所以只在一台主机上模拟:
zookeeper分为单机模式,集群模式和伪集群模式,集群模式和单机模式略有不同
一、伪集群搭建:
1、首先下载zookeeper安装包,下载地址:http://apache.mirrors.lucidnetworks.net/zookeeper/
我下载的是zookeeper-3.5.2-alpha,,解压放在/home/zookeeper文件夹下,由于要模拟三台主机,所以将解压后的文件夹分别放到三个文件夹中,命名为serverA,serverB,serverC。
漏掉一步:
配置全局环境变量:
>sudo vi /etc/profile
插入以下代码:
#zookeeper
export ZOOKEEPER_HOME=/home/zlp/zookeeper
export PATH= $PATH:$ZOOKEEPER_HOME/bin
2、编辑每个配置文件,以serverA为例:
复制/conf/zoo_sample.cfg文件,重命名为zoo.cfg(在同一个文件夹下进行操作)
编辑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=/home/zlp/zookeeper/zk-data/serverA/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

# administrato
9bbe
r 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
server.1=192.168.169.128:2181:3888
server.2=192.168.169.128:2182:3889
server.3=192.168.169.128:2183:3890

(后面有两个IP端口号,第一个是进行数据通信的,第二个是进行Master选举的)
其他两个也如上配置,但是clientPort不同,默认都为2181
dataDir是存放数据的位置,需要自己新建文件夹放入
3、该步与单机配置不同,集群配置需要创建myid文件,在zk-data文件夹下新建三个文件夹,分别为serverA ,serverB,serverC,其下都放着对应的data/myid文件,每个myid文件的内容为server.X的X数字,比如serverA/data/myid中的内容为1
4、在配置文件中也可写入dataLogDir,与dataDir在同一个文件夹中
5、启动zookeeper伪集群中的所有服务器,分别进入三个服务器的zookeeper/bin目录下,启动服务:./zkServer.sh start
启动完后。查看服务器的状态
6、此步可以省略,启动客户端:
进入三个服务器的zookeeper/bin目录下,启动:./zkCli.sh -server 192.168.169.128:2181
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: