首頁技術(shù)文章正文

Zookeeper集群配置怎樣操作?

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

1577370495235_學(xué)IT就到黑馬程序員.gif


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

1.修改Zookeeper的配置文件

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

$ cp zoo_sample.cfg zoo.cfg
其次,修改配置文件zoo.cfg,分別設(shè)置dataDir目錄,配置服務(wù)器編號(hào)與主機(jī)名映射關(guān)系,設(shè)置與主機(jī)連接的心跳端口和選舉端口,具體配置內(nèi)容如下:
# The number of milliseconds of each tick

\# 設(shè)置通信心跳數(shù)

tickTime=2000

\# The number of ticks that the initial 

\# synchronization phase can take

\# 設(shè)置初始通信時(shí)限

initLimit=10

\# The number of ticks that can pass between 

\# sending a request and getting an acknowledgement

\# 設(shè)置同步通信時(shí)限

syncLimit=5

\# the directory where the snapshot is stored.

\# do not use /tmp for storage, /tmp here is just 

\# example sakes.

**#** **設(shè)置數(shù)據(jù)文件目錄+****數(shù)據(jù)持久化路徑**

**dataDir=/export/data/zookeeper/zkdata**

\# the port at which the clients will connect

\# 設(shè)置客戶端連接的端口號(hào)

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集群的服務(wù)器編號(hào)以及對(duì)應(yīng)的主機(jī)名、通信端口號(hào)(心跳端口號(hào))、選舉端口號(hào)**

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

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

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


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

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

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

$ echo 1 > myid


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

Linux系統(tǒng)目錄/etc下的文件profile里面的內(nèi)容都是與Linux環(huán)境變量相關(guān)的。所以,我們一般配置環(huán)境變量都是在profile文件里面。執(zhí)行命令vi /etc/profile對(duì)profile文件進(jìn)行修改,添加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相關(guān)文件至其他服務(wù)器

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

$ 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服務(wù)器上,并且修改myid的文件內(nèi)容,依次對(duì)應(yīng)服務(wù)器號(hào)進(jìn)行設(shè)置,分別為2、3。具體命令如下:

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

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

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

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

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


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

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

$ source /etc/profile




猜你喜歡:

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

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

什么是Master選舉?ZooKeeper在集群Master選舉中應(yīng)用    

Zookeeper命名服務(wù)|Name Service使用方法    
黑馬程序員大數(shù)據(jù)培訓(xùn)

分享到:
在線咨詢 我要報(bào)名
和我們?cè)诰€交談!