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