zookeeper 安裝

下載

下載地址:https://downloads.apache.org/zookeeper/
下載時(shí),文件名帶bin的是已經(jīng)編譯安裝好的,請(qǐng)下載帶有bin的壓縮文件。

安裝

將壓縮包上傳到服務(wù)器,然后解壓縮。

tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz -C /opt/

進(jìn)入解壓后的目錄,復(fù)制并重命名一份簡(jiǎn)單的配置文件

cd /opt/zookeeper-3.8.0/conf
cp zoo_sample.cfg zoo.cfg

修改配置文件內(nèi)容

[root@hadoop101 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=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
# the port at which the clients will connect
clientPort=10086
# 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.
#
# https://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

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

#servers
server.1=192.168.163.101:10087:10088
server.2=192.168.163.102:10087:10088
server.3=192.168.163.103:10087:10088

#open commands
4lw.commands.whitelist=*

主要配置解釋

配置項(xiàng) 值與釋義
dataDir ZK數(shù)據(jù)存放位置,可以任意指定
dataLogDir ZK數(shù)據(jù)操作的日志,可以任意指定。這個(gè)不是ZK的啟動(dòng)日志,是對(duì)數(shù)據(jù)操作的記錄日志
clientPort 連接ZK所使用的端口
server 每一個(gè)server代表一個(gè)ZK,后面的數(shù)字需要是myid的值,等號(hào)后面填寫IP和兩個(gè)隨意指定的端口,這兩個(gè)端口用于ZK集群內(nèi)部通信,外部無(wú)法連接。
4lw.commands.whitelist 白名單的命令,如果不限制外部命令則填*

這里我以安裝三節(jié)點(diǎn)為例,如果只安裝單節(jié)點(diǎn)的ZK,則配置文件末尾的#servers段無(wú)需配置。
配置文件最后的4lw.commands.whitelist是為了開放命令權(quán)限,方便外部訪問和執(zhí)行命令,比如從外部檢測(cè)zk的版本號(hào)等,如果不需要?jiǎng)t可以不配置。
最后在dataDir路徑下創(chuàng)建一個(gè)myid文件,如果不做集群配置,這一步可以省略。

touch /data/zookeeper/data/myid
echo '1' > /data/zookeeper/data/myid

另外兩臺(tái)主機(jī)如法炮制,上傳壓縮包——>解壓——>修改配置文件——>創(chuàng)建myid文件,或者直接從第一臺(tái)主機(jī)上把所有東西都scp過去,無(wú)論怎么做都行,但一定記得不同主機(jī)的myid配置是不同的,101的myid一定是1,102的一定是2,這不是因?yàn)?01是在第一個(gè),而是因?yàn)榕渲梦募?01主機(jī)是server.1,如果配置文件改成server.99,則101主機(jī)的myid要改成99。
最后在各個(gè)主機(jī)上,以任意順序執(zhí)行啟動(dòng)命令即可

/opt/zookeeper-3.8.0/bin/zkServer.sh start

遠(yuǎn)程查看節(jié)點(diǎn)狀態(tài)

使用下面的nc命令查看ZK節(jié)點(diǎn)狀態(tài),如果沒有配置4lw.commands.whitelist,則這一步會(huì)報(bào)錯(cuò)。

echo stat | nc 192.168.163.101 10086

如果沒有nc命令,則下載yum install nc -y

查看ZK狀態(tài).png

如上圖,該命令會(huì)展示ZK的版本號(hào)與節(jié)點(diǎn)的運(yùn)行mode,可以看到這是一個(gè)follower節(jié)點(diǎn)。

使用

連接ZK
/opt/zookeeper-3.8.0/bin/zkCli.sh -server 192.168.163.101:10086

查看節(jié)點(diǎn)

[zk: 192.168.163.101:10086(CONNECTED) 0] ls /
[zookeeper]

創(chuàng)建節(jié)點(diǎn)并賦值

[zk: 192.168.163.101:10086(CONNECTED) 1] create /ovo
Created /ovo
[zk: 192.168.163.101:10086(CONNECTED) 3] create /ovo/north "I 最討厭起網(wǎng)名了,總是被占用。"
Created /ovo/north

獲取節(jié)點(diǎn)的值

[zk: 192.168.163.101:10086(CONNECTED) 9] get /ovo/north 
I 最討厭起網(wǎng)名了,總是被占用。

修改節(jié)點(diǎn)的值(也可用于賦值)

[zk: 192.168.163.101:10086(CONNECTED) 10] set /ovo/north "New Player"
[zk: 192.168.163.101:10086(CONNECTED) 11] get /ovo/north 
New Player

刪除節(jié)點(diǎn)

[zk: 192.168.163.101:10086(CONNECTED) 12] delete /ovo/north

無(wú)法刪除非空的節(jié)點(diǎn)

[zk: 192.168.163.101:10086(CONNECTED) 13] create /ovo/north
Created /ovo/north
[zk: 192.168.163.101:10086(CONNECTED) 14] delete /ovo
Node not empty: /ovo
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1 安裝單機(jī) Zookeeper 1.1 準(zhǔn)備工作 (1) 下載 Zookeeper 安裝包在 http://zo...
    MiniSoulBigBang閱讀 534評(píng)論 0 0
  • zookeeper安裝部署 下載 解壓 解壓完成后進(jìn)入zookeeper-3.4.12 目錄結(jié)構(gòu)如下: ├── b...
    volkin閱讀 767評(píng)論 1 1
  • Zookeeper有三種運(yùn)行模式:?jiǎn)螜C(jī)模式、偽集群模式和集群模式。注意的是一般zookeeper集群由3~5臺(tái)服務(wù)...
    陽(yáng)光_8af8閱讀 1,514評(píng)論 0 1
  • zookeeper有單機(jī)、偽集群、集群三種部署方式,可根據(jù)自己對(duì)可靠性的需求選擇合適的部署方式。下邊對(duì)這三種部署方...
    額嗬閱讀 374評(píng)論 0 0
  • 1、下載Zookeeper安裝包 https://mirrors.tuna.tsinghua.edu.cn/apa...
    neimengguzn閱讀 799評(píng)論 0 51

友情鏈接更多精彩內(nèi)容