您好,登錄后才能下訂單哦!
這篇文章主要介紹分布式系統之如何實現zookeeper安裝,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
ZooKeeper是一個分布式的,開放源碼的分布式應用程序協調服務,它包含一個簡單的原語集,分布式應用程序可以基于它實現同步服務,配置維護和命名服務等。
設計目的
1.最終一致性:client不論連接到哪個Server,展示給它都是同一個視圖,這是zookeeper最重要的性能。
2 .可靠性:具有簡單、健壯、良好的性能,如果消息m被到一臺服務器接受,那么它將被所有的服務器接受。
3 .實時性:Zookeeper保證客戶端將在一個時間間隔范圍內獲得服務器的更新信息,或者服務器失效的信息。但由于網絡延時等原因,Zookeeper不能保證兩個客戶端能同時得到剛更新的數據,如果需要最新數據,應該在讀數據之前調用sync()接口。
4 .等待無關(wait-free):慢的或者失效的client不得干預快速的client的請求,使得每個client都能有效的等待。
5.原子性:更新只能成功或者失敗,沒有中間狀態。
6 .順序性:包括全局有序和偏序兩種:全局有序是指如果在一臺服務器上消息a在消息b前發布,則在所有Server上消息a都將在消息b前被發布;偏序是指如果一個消息b在消息a后被同一個發送者發布,a必將排在b前面。
ZK安裝分為單機安裝、偽分布安裝和分布式安裝
一、單機安裝
[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端口號,建議依次改為2181、2182、2183,寫入myId文件,必須和Server.X里面的序號對應
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]#
啟動驗證
/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 看下進程
三、分布式安裝
修改單機安裝的zoo.cfg文件,如下圖所示,因為是分布式安裝,所以下圖表紅色部分,只需要修改對應的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
~
步驟二、通過Scp命令分發文件到其余兩臺機器上面
步驟三、修改各自的myid文件,必須和zoo.cfg里面配置的server.1=192.168.1.1數字和IP對應起來
[root@node1 zk]# echo 1 > zookeeper/zkdata/myid
步驟四、啟動驗證/opt/zk/zookeeper/bin/zkServer.sh start-foreground
四、Zookeeper監聽三個端口
2181:用來監聽zookeeper客戶端連接
2888:如果是領導者, 用來監聽跟隨者連接
3888:用來在選舉領導者階段, 用來監聽其他服務器的連接.
以上是“分布式系統之如何實現zookeeper安裝”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。