zookeeper 安裝模式有三種:單機模式:單機單 server;集群模式:多機多 server,形成集群;偽集群模式:單機多 server,形成偽集群。
~
本篇內容包括:Zookeeper 官網下載、Zookeeper 單機模式部署、Zookeeper 集群安裝、Zookeeper 集群安裝
文章目錄
- 一、Zookeeper 官網下載
- 二、Zookeeper 單機模式部署
- 1、安裝 JDK
- 2、安裝 Zookeeper
- 3、修改 Zookpeeper 配置
- 4、運行 Zookeeper
- 三、Zookeeper 集群安裝
- 1、安裝JDK(每一臺服務器);
- 2、安裝 Zookeeper
- 3、修改 Zookpeeper 配置
- 4、運行 Zookeeper
- 四、Zookeeper 集群啟動停止腳本
一、Zookeeper 官網下載
進入官網下載 Zookeeper,這里我們使用的版本為 Zookeeper-3.5.7
Zookeeper 官網地址: http://zookeeper.apache.org/
zookeeper 安裝模式有三種:單機模式:單機單 server;集群模式:多機多 server,形成集群;偽集群模式:單機多 server,形成偽集群。
二、Zookeeper 單機模式部署
1、安裝 JDK
# 安裝JDK
可以參照:Java基礎:Java程序設計環境
2、安裝 Zookeeper
# 官網下載
# 拷貝 apache-zookeeper-3.5.7-bin.tar.gz
到 Linux系統下
# 解壓到指定目錄:
tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/
# 改名
mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7
3、修改 Zookpeeper 配置
# 進入conf目錄
# mv zoo_sample.cfg zoo.cfg
# mkdir /opt/module/zookeeper-3.5.7/zkData
# vi 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/module/zookeeper-3.5.7/zkData
# 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
4、運行 Zookeeper
# 啟動Zookeeper:bin/zkServer.sh start
# 查看進程:jps
# 客戶端訪問:bin/zkCli.sh
三、Zookeeper 集群安裝
1、安裝JDK(每一臺服務器);
# 安裝JDK
可以參照:Java基礎:Java程序設計環境
2、安裝 Zookeeper
# 拷貝 apache-zookeeper-3.5.7-bin.tar.gz
到 Linux系統下(每一臺服務器)
# 解壓到指定目錄(每一臺服務器):
tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/
# 改名(每一臺服務器)
mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7
3、修改 Zookpeeper 配置
# 進入conf目錄(每一臺服務器)
# mv zoo_sample.cfg zoo.cfg
(每一臺服務器)
# mkdir /opt/module/zookeeper-3.5.7/zkData
(每一臺服務器)
# vi /opt/module/zookeeper-3.5.7/zkData/myid
,填寫每天服務器對應的 ID
# vi 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/module/zookeeper-3.5.7/zkData
# 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=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
4、運行 Zookeeper
# 啟動服務:每臺機器執行:bin/zkServer.sh start
# 查看每個節點狀態:bin/zkServer.sh status
四、Zookeeper 集群啟動停止腳本
#!/bin/bashcase $1 in
"start"){for i in master slave1 slave2doecho ----- zookeeper $i 啟動-----ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh start"done
}
;;
"stop"){for i in master slave1 slave2doecho ----- zookeeper $i 停止-----ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh stop"done
}
;;
"status"){for i in master slave1 slave2doecho ----- zookeeper $i 狀態-----ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh status"done
}
;;
esac