1、安裝包html
一、下載最新版(3.4.13):https://archive.apache.org/dist/zookeeper/ 下載https://archive.apache.org/dist/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz解壓開便可。本文中解壓到/opt目錄下。apache
2、環境服務器
一、三臺服務器IP分別爲:192.168.1.10四、192.168.1.10五、192.168.1.106tcp
二、三臺的Zookeeper配置文件路徑都是:/opt/zookeeper/zookeeper-3.4.13/conf/zoo.cfgide
3、配置集羣:ui
一、服務器192.168.1.104中:this
(1)修改/opt/zookeeper/zookeeper-3.4.13/conf/zoo.cfg文件內容以下:spa
# 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=/opt/zookeeper/zkdata/data dataLogDir=/opt/zookeeper/zkdata/log # 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.104=0.0.0.0:2888:3888 server.105=192.168.6.105:2888:3888 server.106=192.168.6.106:2888:3888
(2)建立目錄並配置myid。code
I、建立目錄:/opt/zookeeper/zkdata/dataserver
II、建立文件:/opt/zookeeper/zkdata/data/myid ,內容爲"104" ,或者使用命令快速生成:
echo 104>/opt/zookeeper/zkdata/data/myid
二、服務器192.168.1.105中:
(1)修改/opt/zookeeper/zookeeper-3.4.13/conf/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=/opt/zookeeper/zkdata/data dataLogDir=/opt/zookeeper/zkdata/log # 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.104=192.168.6.104:2888:3888 server.105=0.0.0.0:2888:3888 server.106=192.168.6.106:2888:3888
(2)建立目錄並配置myid。
I、建立目錄:/opt/zookeeper/zkdata/data
II、建立文件:/opt/zookeeper/zkdata/data/myid ,內容爲"105" ,或者使用命令快速生成:
echo 105>/opt/zookeeper/zkdata/data/myid
三、服務器192.168.1.106中:
(1)修改/opt/zookeeper/zookeeper-3.4.13/conf/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=/opt/zookeeper/zkdata/data dataLogDir=/opt/zookeeper/zkdata/log # 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.104=192.168.6.104:2888:3888 server.105=192.168.6.105:2888:3888 server.106=0.0.0.0:2888:3888
(2)建立目錄並配置myid。
I、建立目錄:/opt/zookeeper/zkdata/data
II、建立文件:/opt/zookeeper/zkdata/data/myid ,內容爲"106" ,或者使用命令快速生成:
echo 106>/opt/zookeeper/zkdata/data/myid
4、三臺機器中,都爲防火牆中添加218一、288八、3888端口入站。
添加端口: firewall-cmd --zone=public --add-port=2181/tcp --permanent firewall-cmd --zone=public --add-port=2888/tcp --permanent firewall-cmd --zone=public --add-port=3888/tcp --permanent 從新載入: firewall-cmd --reload
5、啓動Zookeeper:三臺機器中依次運行
/opt/zookeeper/zookeeper-3.4.13/bin/zkServer.sh start /opt/zookeeper/zookeeper-3.4.13/conf/zoo.cfg