1.安装jdk:https://my.oschina.net/u/3316387/blog/1615301\html
2.下载ZooKeeper:https://archive.apache.org/dist/zookeeper/,而后早/opt下建立一个目录zookeeper,将下载好的文件解压到这个目录。apache
3.在zookeeper目录下建立data,dataLog两个目录jvm
4.在data下建立文件myid,并写入1,其余的机器分别写上2,3......能够随便定义。ide
5.进入/opt/zookeeper/zookeeper-3.4.10/conf/,建立文件zoo.cfg,写入如下代码:ui
# 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
# 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=1this
dataDir=/opt/zookeeper/data
dataLogDir=/opt/zookeeper/dataLog
server.1=192.168.1.201:2888:3888spa
server.2=192.168.1.202:2888:3888.net
server.3=192.168.1.203:2888:3888server
说明:dataDir和dataLogDir须要本身建立,目录能够本身制定,对应便可。server.1中的这个1须要和192.168.1.201这个机器上的dataDir目录中的myid文件中的数值对应。server.2中的这个2须要和192.168.1.202这个机器上的dataDir目录中的myid文件中的数值对应。固然,数值你能够随便用,只要对应便可。2888和3888的端口号也能够随便用,由于在不一样机器上,用成同样也无所谓。htm
6.进入/opt/zookeeper/zookeeper-3.4.10/bin/,编辑zkServer.sh 在程序的开头添加上:
export JAVA_HOME=/usr/lib/jvm/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
不添加会出现如下错误:
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
7.最后启动zookeeper
sudo /opt/zookeeper/zookeeper-3.4.10/bin/zkServer.sh start
查看状态
sudo /opt/zookeeper/zookeeper-3.4.10/bin/zkServer.sh status