天天看点

zookeeper集群安装部署一、准备工作二、安装zookeeper集群

一、准备工作

1.三台服务器:master、slave1、slave2

2.三台服务器安装了java环境

3.在官网下载zookeeper-3.4.10.tar.gz

二、安装zookeeper集群

1.分别修改三台服务器的hosts文件:

[[email protected] ~]# vim /etc/hosts
           

添加如下内容:

192.168.100.1     master
192.168.100.2     slave1
192.168.100.3     slave2
           

保存退出,并重启三台服务器。

2.解压zookeeper

[[email protected] ~]# tar -zxvf zookeeper-3.4.10.tar.gz -C /home
           

3.修改相应配置

①进入解压后的文件夹下,并创建data和logs两个文件夹

[[email protected] ~]# cd /home/zookeeper-3.4.10
[[email protected] zookeeper-3.4.10]# mkdir data
[[email protected] zookeeper-3.4.10]# mkdir logs
           

②进入conf目录下,将zoo_sample.cfg复制并重命名为zoo.cfg

[[email protected] zookeeper-3.4.10]# cd conf
[[email protected] conf]# cp zoo_sample.cfg zoo.cfg
           

③修改zoo.cfg文件配置

[[email protected] conf]# vim 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/zookeeper-3.4.10/data
dataLogDir=/home/zookeeper-3.4.10/logs
# 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.0=master:2888:3888
server.1=slave1:2888:3888
server.2=slave2:2888:3888
           

④创建myid文件并修改

进入刚刚创建的data文件夹下,创建myid文件,并添加内容

[[email protected] conf]# cd /home/zookeeper-3.4.10/data

[[email protected] conf]# vim myid
           

添加如下内容:

4.在另外两台机器上也同样进行1、2、3的步骤,但是每个机器上myid的内容必须不一样。我的设置为:master的myid为0;slave1的myid为1;slave2的myid为2。

5.修改profile文件

[[email protected] conf]# vim /etc/profile
           

添加如下内容:

#zookeeper
export ZK_HOME=/home/zookeeper-3.4.10
export PATH=$ZK_HOME/bin:$PATH
           

使修改生效:

[[email protected] conf]# source /etc/profile
           

6.启动zookeeper以及查看状态

进入到zookeeper的bin目录下

启动(需要在三个节点分别启动):

[[email protected] bin]# ./zkServer.sh start
           

查看状态:

[[email protected] bin]# ./zkServer.sh status
           

继续阅读