1. 程式人生 > >ZooKeeper 完全分布式集群環境搭建

ZooKeeper 完全分布式集群環境搭建

exp lan def pac echo 好的 scp height 查詢

1、 搭建前準備

示例共三臺主機,主機IP映射信息如下:

192.168.32.101 s1
192.168.32.102 s2
192.168.32.103 s3

2、下載ZooKeeper, 以 zookeeper-3.4.14 為例,下載地址如下:

https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/stable/zookeeper-3.4.14.tar.gz

3、復制下載好的zookeeper-3.4.14.tar.gzs1主機上,並解壓到/opt 下

tar -zxvf zookeeper-3.4
.14.tar.gz -C /opt/

4、配置

s1 上創建data目錄和myid文件

mkdir /opt/zookeeper-3.4.14/data
echo 1 > /opt/zookeeper-3.4.14/data/myid

創建conf/zoo.cfg

cd /opt/zookeeper-3.4.14/conf
touch zoo.cfg

zoo.cfg 內容如下

tickTime=2000
initLimit=5
syncLimit=2
dataDir=/opt/zookeeper-3.4.14/data
dataLogDir=/opt/zookeeper-3.4
.14/logs clientPort=2181 server.1=s1:2888:3888 server.2=s2:2888:3888 server.3=s3:2888:3888

5、遠程復制zookeeper到另外兩臺主機 s2、s3 上

scp -r /opt/zookeeper-3.4.14 [email protected]:/opt/
scp -r /opt/zookeeper-3.4.14 [email protected]:/opt/

登錄主機s2 ,修改 myid 文件

ssh s2
echo 2 > /opt/zookeeper-3.4
.14/data/myid

登錄主機s3 ,修改 myid 文件

ssh s3
echo 3 > /opt/zookeeper-3.4.14/data/myid

6、配置三臺主機環境變量

vi /etc/profile

添加內容如下:

export ZOOKEEPER_HOME=/opt/zookeeper-3.4.14
export PATH=$PATH:$ZOOKEEPER_HOME/bin

使用source命令使配置立即生效

source /etc/profile

7、啟動

在三臺主機上分別執行如下命令

zkServer.sh start

查詢運行狀態

zkServer.sh status

三臺主機顯示信息如下:

[[email protected] conf]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower
[[email protected] opt]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: leader
[[email protected] opt]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.14/bin/../conf/zoo.cfg
Mode: follower

leader:s2

follower:s1、s3

重啟命令

zkServer.sh restart

停止命令

zkServer.sh stop

8、客戶端連接

/opt/zookeeper-3.4.14/bin/zkCli.sh -server s1:2181

輸入 h 查看所有幫助命令

查看節點命令

ls /

ZooKeeper 完全分布式集群環境搭建

.

ZooKeeper 完全分布式集群環境搭建