zookeeper集群的搭建

来源:互联网 发布:阿里云注册域名手机号 编辑:程序博客网 时间:2024/05/16 10:06

今天我们来配置zookeeper的架构:3台服务器

1.下载zookeeper-3.4.5.tar.gz,解压到目录/home/wangjing/hadoop里面,得到文件夹zookeeper-3.4.5,之后进入/zookeeper-3.4.5/conf/,修改该配置文件的名称:
zoo_sample.cfg ==> zoo.cfg


2.修改里面的配置文件
# 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=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
#
# 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

在这个后面加上:
# 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/wangjing/hadoop/zkdata           #这一行也修改了,
# the port at which the clients will connect
clientPort=2181
#
# 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
#########################################
weekday01:代表的是另外一台主机hostname
2888:则是zookeeper中leader与follower之间通信的端口,
3888: 则是选举的端口
#########################################
server.1=weekday01:2888.3888
server.2=weekday02:2888.3888
server.3=weekday03:2888.3888


3.刚才在上述修改的,zookeeper这些数据真实存放的地方dataDir=/home/wangjing/hadoop/zkdata
1.创建这个目录 mkdir  /home/wangjing/hadoop/zkdata
2.由于当前的主机名是hostname=weekday01,由于在zoo.cfg中server.1=weekday01:2888.3888,所以我们要在zkdata的目录写入1
cd /home/wangjing/hadoop/zkdata
echo 1 > zkdata


4.copy到另外的主机上面
scp -r /home/wangjing/hadoop/zkdata/ /home/wangjing/hadoop/zookeeper-3.4.5/ wangjing@weekday02:/home/wangjing/hadoop
上面的语句的意思是:把当前的文件夹目录/home/wangjing/hadoop/zkdata/,/home/wangjing/hadoop/zookeeper-3.4.5/两个文件夹
copy到hostname位weekday02的主机,并且用户为wangjing,将其两个文件夹copy到/home/wangjing/hadoop的目录下,并且之后,把copy
到这个新目录下面zkdata/myid改为2,之后的操作一样,对于主机名为weekday03
5.启动zookeeper,进入到我们前面的路径,安装zookeeper的路径:/home/wangjing/hadoop/zookeeper-3.4.5/bin,执行操作zkServer.sh,即可启动zookeeper服务
bin/zkServer.sh start,则可以启动,注意如果是shell编程,则一定要写上一层的目录,要加上bin,如果不加bin,执行不成功。
bin/zkServer.sh status 查看当前zookeeper状态
bin/zkServer.sh stop    停止zookeeper的状态

0 0