zookeeper單機部署及集羣(單機僞集羣)部署

1、單機部署java

下載源碼apache

wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz vim

解壓ide

tar -xvzf  zookeeper-3.4.9.tar.gz -C /usr/local/測試

軟鏈接spa

cd /usr/local/日誌

ln -s zookeeper-3.4.9  zookeeperorm

修改配置文件server

cd /usr/local/zookeeper/conf進程

cp  zoo_sample.cfg  zoo.cfg

vim zoo.cfg

暫時只須要修改數據和日誌目錄

dataDir=/data/zookeeper

啓動程序

/usr/local/zookeeper/bin/zkServer.sh start

期間出現啓動的問題,報錯啓動失敗 nohup: 沒法運行命令"java",可修改zkServer.sh第140行的

nohup "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \

--$JAVA將此變量修改成適合本身主機的便可,如修改成$JAVA_HOME/bin/java 

啓動成功後進行鏈接測試

/usr/local/zookeeper/bin/zkCli.sh -server 127.0.0.1:2181

Connecting to 127.0.0.1:2181

...

[zk: 127.0.0.1:2181(CONNECTED) 0]

表明服務連接成功



2、集羣(單機多進程僞集羣)

建立目錄

mkdir zookeeper-3181 zookeeper-3182 zookeeper-3183

#zookeeper-3181的配置爲

tickTime=2000

initLimit=10

syncLimit=5

dataDir=/path/zookeeper/log/zookeeper-3181 #其餘兩個目錄自定義

clientPort=3181 #其餘兩個目錄端口分別設置爲3182和3183

autopurge.snapRetainCount=3

autopurge.purgeInterval=72

server.1=localhost:2287:3387

server.2=localhost:2288:3388

server.3=localhost:2289:3389

#啓動zookeeper-3181

sh  zookeeper-3181/bin/zkServer.sh start 

啓動過程當中,查看zookeeper.out ,報錯以下:

e.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /path/zookeeper/zookeeper-3181/bin/../conf/zoo.cfg

        at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:144)

        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:101)

        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)

Caused by: java.lang.IllegalArgumentException: /path/zookeeper/log/zookeeper-3181/myid file is missing

        at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:362)

        at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:140)

/path/zookeeper/log/zookeeper-3181/myid file is missing 這個文件沒有存在,解決以下:

echo 1 >/path/zookeeper/log/zookeeper-3181/myid

echo 2 >/path/zookeeper/log/zookeeper-3182/myid

echo 3 >/path/zookeeper/log/zookeeper-3183/myid

執行完成後,從新啓動

sh  zookeeper-3181/bin/zkServer.sh start 

sh  zookeeper-3182/bin/zkServer.sh start 

sh  zookeeper-3183/bin/zkServer.sh start 

集羣測試

登陸到3183端口

sh zookeeper-3183/bin/zkCli.sh  -server 127.0.0.1:3183

#設置

[zk: 127.0.0.1:3183(CONNECTED) 0] create /testpro  zookeeptest

Created /testpro

[zk: 127.0.0.1:3183(CONNECTED) 1] get /testpro

zookeeptest

cZxid = 0x100000002

ctime = Fri Mar 17 10:05:03 CST 2017

mZxid = 0x100000002

mtime = Fri Mar 17 10:05:03 CST 2017

pZxid = 0x100000002

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 11

numChildren = 0

[zk: 127.0.0.1:3183(CONNECTED) 2]

登陸到3182端口檢查同步狀況

sh zookeeper-3183/bin/zkCli.sh  -server 127.0.0.1:3182

[zk: 127.0.0.1:3182(CONNECTED) 0] get /testpro

zookeeptest

cZxid = 0x100000002

ctime = Fri Mar 17 10:05:03 CST 2017

mZxid = 0x100000002

mtime = Fri Mar 17 10:05:03 CST 2017

pZxid = 0x100000002

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 11

numChildren = 0

[zk: 127.0.0.1:3182(CONNECTED) 1] 


3、節點接管測試

目前狀況爲3182端口爲主節點,測試此端口掛掉後,其餘從節點是否正常升級爲主節點

--檢查

 sh zookeeper-3182/bin/zkServer.sh status 

ZooKeeper JMX enabled by default

Using config: /home/gdiex/zookeeper/zookeeper-3182/bin/../conf/zoo.cfg

Mode: leader

--中止

sh zookeeper-3182/bin/zkServer.sh  stop

ZooKeeper JMX enabled by default

Using config: /home/gdiex/zookeeper/zookeeper-3182/bin/../conf/zoo.cfg

Stopping zookeeper ... STOPPED

#檢查,發現3183升級爲主節點

sh zookeeper-3183/bin/zkServer.sh status 

ZooKeeper JMX enabled by default

Using config: /home/gdiex/zookeeper/zookeeper-3183/bin/../conf/zoo.cfg

Mode: leader

#-----------華麗OVER線-----------#

相關文章
相關標籤/搜索