zookeeper(1)利用3個機器,搭建zk集羣模式

背景

最近打算好好學習一下zookeeper,那麼第一步就是要搭建一個環境。
單機版的比較簡單,這裏就不介紹了。
集羣版本的,看網上的教程也蠻簡單的,可是本身動起手來仍是會遇到各類問題,這裏作一下記錄。html

環境介紹

一、3個阿里雲服務器,其中2個ECS,1個輕量服務器。
二、zookeeper使用最新版本 https://archive.apache.org/dist/zookeeper/stable/apache-zookeeper-3.5.5-bin.tar.gz
三、3臺雲主機的Java使用jdk1.8版本。apache

步驟

一、檢查各個主機的Java環境是否正常
zookeeper(1)利用3個機器,搭建zk集羣模式
二、下載最新版本zookeeper,並解壓,3臺機器最好採用統一的目錄,我採用的目錄windows

/enzi/zk/apache-zookeeper-3.5.5-bin

三、3個機器,分別建立zookeeper的數據目錄和日誌目錄安全

/enzi/zk/data
/enzi/zk/log

四、進入程序目錄下,3個機器操做都同樣服務器

/enzi/zk/apache-zookeeper-3.5.5-bin/conf

複製zoo_sample.cfg爲zoo.cfg,並修改zoo.cfg內容以下:ide

# 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=/enzi/zk/data
dataLogDir=/enzi/zk/log
# the port at which the clients will connect
clientPort=2181
#admin.serverPort=8089
# 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.1=ip1:2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888

quorumListenOnAllIPs=true

五、建立myid文件
分別在對應的data目錄下,爲本身的服務指定myid,內容就是zoo.cfg裏面server.後面的序號,分別是1,2,3,ip1機器下myid內容爲1,依次類推。學習

zookeeper(1)利用3個機器,搭建zk集羣模式

六、依次啓動3個機器zookeeper服務ui

bin/zkServer.sh start

若是想看有沒有什麼錯誤信息可使用以下命令,在調試階段建議使用這個命令。this

bin/zkServer.sh start-foreground

七、查看是否啓動成功
zookeeper(1)利用3個機器,搭建zk集羣模式
mode:follower,表明這個服務是follower節點。
這裏server.1是leader節點。阿里雲

八、使用客戶端進行鏈接,這裏採用的windows的客戶端

zkCli.cmd -server ip1:2181,ip2:2181,ip3:2181

使用命令,建立臨時節點以下
zookeeper(1)利用3個機器,搭建zk集羣模式

注意:對於阿里雲,由於防火牆或者ECS的安全策略來講,會致使集羣之間的接口鏈接失敗。

一、輕量服務器來講須要把2181,2888,3888增長到防火牆上。

二、對於ESC須要把2181,2888,3888的安全規則,入口和出口都設置爲容許。

zookeeper(1)利用3個機器,搭建zk集羣模式

相關文章
相關標籤/搜索