1. 程式人生 > >zookeeper 集群安裝

zookeeper 集群安裝

end color 集群安裝 下載 pac getting lis ntp knowledge

1、【下載】到官網下在安裝包:http://zookeeper.apache.org/,如:zookeeper-3.4.10.tar.gz,下載後上傳到linux系統

2、【解壓】執行 #tar -zxvf zookeeper-3.4.10.tar.gz -C [path]

3、【修改配置】修改 zoo.cfg ,在zoo.cfg 的 dataDir 設置的目錄中 新建myid文件,在myid文件中寫入,在zoo.cfg 的 server.x=zk01:2888:3888 填寫對應的 x;如在zk01機器上的myid文件 填1,在zk02機器上的myid文件 填2,具體看配置

[root@zk03 conf]# cat 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=/export/servers/zookeeper-3.4.10/data #服務信息
dataLogDir=/export/servers/zookeeper-3.4.10/logs #數據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.1=zk01:2888:3888
server.2=zk02:2888:3888
server.3=zk03:2888:3888

4、【分發安裝目錄】 把配置好的安裝目錄scp到其他機器上,然後修改對應的myid的值

5、【啟動服務】 在每臺機器上都開啟zk服務,執行 #./bin/zkServer start 註意:只開一條機器,集群是開不起來的,因為要過半的節點正常,集群才正常;本例有3個節點:

server.1=zk01:2888:3888

server.2=zk02:2888:3888

server.3=zk03:2888:3888

只開啟一個節點,1/3,沒有過半,所以集群不能正常運行,雖然jps,可以看到QuorumpeerMain進程,看日誌,會看到鏈接其他兩個節點,一直報錯:拒絕連接

用 執行 #./bin/zkServer status 看節點狀態,會提示:

ZooKeeper JMX enabled by default
Using config: /export/servers/zookeeper-3.4.10/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.

如果在開一個節點,等一會,就會正常了,因為2/3過半了,雖然第3個節點拒接節點;這就是HA(集群高可用)

此時,執行 #./bin/zkServer status ,會提示節點狀態:Mode: leader或者Mode: follower,具體誰是leader,有選舉算法,這個可以進一步了解

在此情況下,再開啟第3個節點,前面2節點狀態不變,3節點是Mode: follower

zookeeper 集群安裝