1、在做zookeeper集群之前需要有至少三台centos机器或虚拟机
2、去zookeeper官网下载对应的压缩包,我下载的是目前最新的zookeeper-3.5.2-alpha.tar.gz,将该压缩包放到usr目 录下,用
tar -zxf zookeeper-3.5.2-alpha.tar.gz
命令将该压缩包解压到当前目录下
3、在解压后的目录下新建两个新目录,分别是data和log,等下在下一步中需要用到
4、将解压后的目录下的conf目录中的zoo_sample.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=/usr/zookeeper-3.5.2-alpha/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
dataLogDir=/usr/zookeeper-3.5.2-alpha/log
server.1=192.168.202.66:2888:3888
server.2=192.168.202.67:2888:3888
server.3=192.168.202.68:2888:3888
# 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
5、在第3步中新建的data目录中新建名为myid的文件,文件内容是上面配置文件中server.x的x,也即是1、2、3这样 的一个数字,这个文件3台机器里面都需要新建,所以需要根据配置上的内容分别存入1 2 3 ,不能弄错了
6、将zookeeper加入到path路径中,在/etc/profile中加入
export PATH=$PATH:/usr/zookeeper-3.5.2-alpha/bin
再用
source /etc/profile
刷新配置文件
这样就可以在任何位置使用zookeeper的命名
7、到目前为止需要做的事情已经做好了,可以来分别启动3台机器中的zookeeper了,用如下命令来启动
1)如果没有配置第6步的内容,则需要进去到zookeeper目录下的bin目录中 ,用
./zkServer.sh start
来启动zookeeper
2)如果配置了第6步的内容,则可以在任何位置使用
zkServer.sh start
来启动zookeeper
8、启动zookeeper之后,可以进去到zookeeper的logs目录下,用
tail -f zookeeper-root-server-localhost.localdomain.out
来查看日志,zookeeper-root-server-localhost.localdomain.out是logs目录的输出日志文件,不知道各个版本的 zookeeper是不是都叫这个名字。
9、最后可以使用 zkServer.sh status 命令来查看zookeeper服务的状态,如果现实如下内容,则说明zookeeper已经 启动成功
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
10、如果在启动zookeeper后发现输出的日志中有报错,那么可能有这么两个原因
1)可能是防火墙没关,或者没有将zookeeper的需要用到的相关的端口号从防火墙中排出,可以使用下面的命令 来关闭防火墙
systemctl status firewalld.service #检查防火墙状态
systemctl stop firewalld.service #关闭防火墙
systemctl disable firewalld.service #禁止开机启动防火墙