首頁技術文章正文

Zookeeper集群配置怎樣操作?

更新時間:2021-04-02 來源:黑馬程序員 瀏覽量:

1577370495235_學IT就到黑馬程序員.gif


在上一小節(jié)中,我們已經把Zookeeper的安裝包成功解壓至/export/servers目錄下。接下來,我們開始配置Zookeeper集群。

1.修改Zookeeper的配置文件

首先,進入Zookeeper解壓目錄下的conf目錄,復制配置文件zoo_sample.cfg并重命名為zoo.cfg,具體命令如下:

$ cp zoo_sample.cfg zoo.cfg
其次,修改配置文件zoo.cfg,分別設置dataDir目錄,配置服務器編號與主機名映射關系,設置與主機連接的心跳端口和選舉端口,具體配置內容如下:
# 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/data/zookeeper/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

**#** **配置ZK集群的服務器編號以及對應的主機名、通信端口號(心跳端口號)、選舉端口號**

**server.1=hadoop01:2888:3888**

**server.2=hadoop02:2888:3888**

**server.3=hadoop03:2888:3888**


2.創(chuàng)建myid文件

首先,根據配置文件zoo.cfg中設置的dataDir目錄,創(chuàng)建zkdata文件夾,具體命令如下:

$ mkdir -p /export/data/zookeeper/zkdata
其次,在zkdata文件夾下創(chuàng)建myid文件,該文件里面的內容就是服務器編號(hadoop01服務器對應編號1,hadoop02服務器對應編號2,hadoop03服務器對應編號3),具體命令如下:
$ cd /export/data/zookeeper/zkdata

$ echo 1 > myid


3.配置環(huán)境變量

Linux系統(tǒng)目錄/etc下的文件profile里面的內容都是與Linux環(huán)境變量相關的。所以,我們一般配置環(huán)境變量都是在profile文件里面。執(zhí)行命令vi /etc/profile對profile文件進行修改,添加Zookeeper的環(huán)境變量,具體命令如下:

export ZK_HOME=/export/servers/zookeeper-3.4.10

export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZK_HOME/bin



4.分發(fā)Zookeeper相關文件至其他服務器

首先,將Zookeeper安裝目錄分發(fā)至hadoop02、hadoop03服務器上。具體命令如下:

$ scp -r /export/servers/zookeeper-3.4.10/ hadoop02:/export/servers/

$ scp -r /export/servers/zookeeper-3.4.10/ hadoop03:/export/servers/

其次,將myid文件分發(fā)至hadoop02、hadoop03服務器上,并且修改myid的文件內容,依次對應服務器號進行設置,分別為2、3。具體命令如下:

$ scp -r /export/data/zookeeper/ hadoop02:/export/data/

$ scp -r /export/data/zookeeper/ hadoop03:/export/data/

最后,將profile文件也分發(fā)至hadoop02、hadoop03服務器上。具體命令如下:

$ scp /etc/profile hadoop02:/etc/profile

$ scp /etc/profile hadoop03:/etc/profile


5.環(huán)境變量生效

分別在hadoop01、hadoop02、hadoop03服務器上刷新profile配置文件,使環(huán)境變量生效。具體命令如下:

$ source /etc/profile




猜你喜歡:

Zookeeper怎么選取主leader?【黑馬程序員】

Zookeeper集群中的三種角色簡單介紹

什么是Master選舉?ZooKeeper在集群Master選舉中應用    

Zookeeper命名服務|Name Service使用方法    
黑馬程序員大數據培訓

分享到:
在線咨詢 我要報名
和我們在線交談!