這篇文章主要介紹分布式系統(tǒng)之如何實(shí)現(xiàn)zookeeper安裝,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
在永靖等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專(zhuān)注、極致的服務(wù)理念,為客戶(hù)提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需開(kāi)發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),營(yíng)銷(xiāo)型網(wǎng)站,外貿(mào)網(wǎng)站制作,永靖網(wǎng)站建設(shè)費(fèi)用合理。
ZooKeeper是一個(gè)分布式的,開(kāi)放源碼的分布式應(yīng)用程序協(xié)調(diào)服務(wù),它包含一個(gè)簡(jiǎn)單的原語(yǔ)集,分布式應(yīng)用程序可以基于它實(shí)現(xiàn)同步服務(wù),配置維護(hù)和命名服務(wù)等。
設(shè)計(jì)目的
1.最終一致性:client不論連接到哪個(gè)Server,展示給它都是同一個(gè)視圖,這是zookeeper最重要的性能。
2 .可靠性:具有簡(jiǎn)單、健壯、良好的性能,如果消息m被到一臺(tái)服務(wù)器接受,那么它將被所有的服務(wù)器接受。
3 .實(shí)時(shí)性:Zookeeper保證客戶(hù)端將在一個(gè)時(shí)間間隔范圍內(nèi)獲得服務(wù)器的更新信息,或者服務(wù)器失效的信息。但由于網(wǎng)絡(luò)延時(shí)等原因,Zookeeper不能保證兩個(gè)客戶(hù)端能同時(shí)得到剛更新的數(shù)據(jù),如果需要最新數(shù)據(jù),應(yīng)該在讀數(shù)據(jù)之前調(diào)用sync()接口。
4 .等待無(wú)關(guān)(wait-free):慢的或者失效的client不得干預(yù)快速的client的請(qǐng)求,使得每個(gè)client都能有效的等待。
5.原子性:更新只能成功或者失敗,沒(méi)有中間狀態(tài)。
6 .順序性:包括全局有序和偏序兩種:全局有序是指如果在一臺(tái)服務(wù)器上消息a在消息b前發(fā)布,則在所有Server上消息a都將在消息b前被發(fā)布;偏序是指如果一個(gè)消息b在消息a后被同一個(gè)發(fā)送者發(fā)布,a必將排在b前面。
ZK安裝分為單機(jī)安裝、偽分布安裝和分布式安裝
一、單機(jī)安裝
[root@node1 bin]# wget http://apache.opencas.org/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
[root@node1 zk]# ls
zookeeper-3.4.6.tar.gz
[root@node1 zk]# tar -zxvf zookeeper-3.4.6.tar.gz
[root@node1 zk]# ls
zookeeper-3.4.6 zookeeper-3.4.6.tar.gz
[root@node1 zk]# mv zookeeper-3.4.6 zookeeper
[root@node1 zk]# cd zookeeper
[root@node1 zookeeper]# ls
bin CHANGES.txt contrib docs ivy.xml LICENSE.txt README_packaging.txt recipes zookeeper-3.4.6.jar zookeeper-3.4.6.jar.md5
build.xml conf dist-maven ivysettings.xml lib NOTICE.txt README.txt src zookeeper-3.4.6.jar.asc zookeeper-3.4.6.jar.sha1
[root@node1 zookeeper]# cd conf/
[root@node1 conf]# ls
configuration.xsl log4j.properties zoo_sample.cfg
[root@node1 conf]# cp zoo_sample.cfg zoo.cfg
[root@node1 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=/tmp/zookeeper
# 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
[root@node1 conf]# java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-i386 u45-b15)
OpenJDK Client VM (build 24.45-b08, mixed mode, sharing)
[root@node1 conf]# cd ../
[root@node1 zookeeper]# cd bin/
[root@node1 bin]# ls
README.txt zkCleanup.sh zkCli.cmd zkCli.sh zkEnv.cmd zkEnv.sh zkServer.cmd zkServer.sh
[root@node1 bin]# ./zkServer.sh
JMX enabled by default
Using config: /opt/zk/zookeeper/bin/../conf/zoo.cfg
Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
[root@node1 bin]# ./zkServer.sh start
JMX enabled by default
Using config: /opt/zk/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@node1 bin]# jps
4341 Jps
4325 QuorumPeerMain
二、偽分布式安裝
安裝技巧:注意修改clientPort端口號(hào),建議依次改為2181、2182、2183,寫(xiě)入myId文件,必須和Server.X里面的序號(hào)對(duì)應(yīng)
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
[root@node1 conf]# vi 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=../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
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
~
"zoo.cfg" 33L, 1007C written
[root@node1 conf]# cd ../
[root@node1 zookeeper]# mkdir zkdata
[root@node1 zookeeper]# cd ../
[root@node1 zk]# clear
[root@node1 zk]# ls
zookeeper zookeeper-3.4.6.tar.gz
[root@node1 zk]# cp -R zookeeper zookeeper2
[root@node1 zk]# cp -R zookeeper zookeeper3
[root@node1 zk]# jps
4372 Jps
4325 QuorumPeerMain
[root@node1 zk]# kill -9 4325
[root@node1 zk]# jps
4381 Jps
[root@node1 zk]# echo 1 > zookeeper/zkdata/myid
[root@node1 zk]# echo 2 > zookeeper2/zkdata/myid
[root@node1 zk]# echo 3 > zookeeper3/zkdata/myid
[root@node1 zk]# echo 2 > zookeeper2/zkdata/myid
[root@node1 zk]# cat zookeeper3/zkdata/myid
3
[root@node1 zk]# cat zookeeper2/zkdata/myid
2
[root@node1 zk]# cat zookeeper/zkdata/myid
1
[root@node1 zk]#
啟動(dòng)驗(yàn)證
/opt/zk/zookeeper/bin/zkServer.sh start-foreground
/opt/zk/hadoop/zookeeper2/bin/zkServer.sh start-foreground
/opt/zk/hadoop/zookeeper3/bin/zkServer.sh start-foreground
啟用成功后,輸入 jps 看下進(jìn)程
三、分布式安裝
修改單機(jī)安裝的zoo.cfg文件,如下圖所示,因?yàn)槭欠植际桨惭b,所以下圖表紅色部分,只需要修改對(duì)應(yīng)的IP地址即可[root@node1 conf]# vi 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=../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
server.1=192.168.1.1:2888:3888
server.2=192.168.1.2:2888:3888
server.3=192.168.1.3:2888:3888
~
步驟二、通過(guò)Scp命令分發(fā)文件到其余兩臺(tái)機(jī)器上面
步驟三、修改各自的myid文件,必須和zoo.cfg里面配置的server.1=192.168.1.1數(shù)字和IP對(duì)應(yīng)起來(lái)
[root@node1 zk]# echo 1 > zookeeper/zkdata/myid
步驟四、啟動(dòng)驗(yàn)證/opt/zk/zookeeper/bin/zkServer.sh start-foreground
四、Zookeeper監(jiān)聽(tīng)三個(gè)端口
2181:用來(lái)監(jiān)聽(tīng)zookeeper客戶(hù)端連接
2888:如果是領(lǐng)導(dǎo)者, 用來(lái)監(jiān)聽(tīng)跟隨者連接
3888:用來(lái)在選舉領(lǐng)導(dǎo)者階段, 用來(lái)監(jiān)聽(tīng)其他服務(wù)器的連接.
以上是“分布式系統(tǒng)之如何實(shí)現(xiàn)zookeeper安裝”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!