zookeeper 入门(二)
上一篇教程中重点讲解了如何部署启动一台zookeeper服务
本章中我们会重点讲解下如何 部署一套zookeeper的集群环境
基于paxos 算法,部署一套集群环境要求 至少 要有3个节点 并且节点的个数一定为奇数
1 在本机中模拟 3个节点
准备工作
cp -r /usr/local/zookeeper-3.4.6 /srv/zookeeper01
打开配置文件
vi /srv/zookeeper01/conf/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=/srv/zookeeper01/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 server.1=localhost:2888:3888 server.2=localhost:2888:3888 server.3=localhost:2888:3888
其中server.X代表组成整个服务的机器,当服务启动时,会在数据目录下查找这个文件myid,这个文件中存有服务器的号码。
创建myid文件
touch /srv/zookeeper01/data/myid echo 1 > /srv/zookeeper01/data/myid
创建另外2台zookeeper 节点
cd /srv cp -r zookeeper01/ zookeeper02/ #修改dataDir=/srv/zookeeper02/data vi zookeeper02/conf/zoo.cfg #修改myid echo 2 > /srv/zookeeper02/data/myid cp -r zookeeper01/ zookeeper03/ #修改dataDir=/srv/zookeeper03/data vi zookeeper03/conf/zoo.cfg #修改myid echo 3 > /srv/zookeeper03/data/myid
启动3台服务
/srv/zookeeper01/bin/zkServer.sh start /srv/zookeeper02/bin/zkServer.sh start /srv/zookeeper03/bin/zkServer.sh start