linux环境下zookeeper部署
生活随笔
收集整理的這篇文章主要介紹了
linux环境下zookeeper部署
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
- zookeeper下載地址(http://apache.fayea.com/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz)
- Linux命令行直接下載: wget http://apache.fayea.com/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz
?
如果沒有權(quán)限,可以切換到root用戶。或者用sudo chmod 777 命令修改hosts的讀寫權(quán)限
- cd?/home/longload/zookeeper-3.4.8/conf/
- cp zoo_sample.cfg zoo.cfg(拷貝?zoo_sample.cfg 文件,命名為為zoo.cfg)
- 修改配置: 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=/home/longload/zookeeper-3.4.8/data
dataLogDir=/home/longload/zookeeper-3.4.8/logs
# 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=1server.1=zjpt-provider-01:2888:3888
- 2888 端口號(hào)是 zookeeper 服務(wù)之間通信的端口。
3888 是 zookeeper 與其他應(yīng)用程序通信的端口。
zjpt-provider-01 是在 hosts 中已映射了 IP 的主機(jī)名。 - 單機(jī)模式
- tickTime:這個(gè)時(shí)間是作為 Zookeeper 服務(wù)器之間或客戶端與服務(wù)器之間維持心跳的時(shí)間間隔,也就是每個(gè) tickTime 時(shí)間就會(huì)發(fā)送一個(gè)心跳。
- dataDir:顧名思義就是 Zookeeper 保存數(shù)據(jù)的目錄,默認(rèn)情況下,Zookeeper 將寫數(shù)據(jù)的日志文件也保存在這個(gè)目錄里。
- dataLogDir:顧名思義就是 Zookeeper 保存日志文件的目錄
- clientPort:這個(gè)端口就是客戶端連接 Zookeeper 服務(wù)器的端口,Zookeeper 會(huì)監(jiān)聽這個(gè)端口,接受客戶端的訪問請求。
- 集群模式 ? initLimit=5
syncLimit=2
server.1=192.168.211.1:2888:3888 #或者h(yuǎn)osts中配置的主機(jī)映射名
server.2=192.168.211.2:2888:3888 Zookeeper 不僅可以單機(jī)提供服務(wù),同時(shí)也支持多機(jī)組成集群來提供服務(wù)。實(shí)際上 Zookeeper 還支持另外一種偽集群的方式,也就是可以在一臺(tái)物理機(jī)上運(yùn)行多個(gè) Zookeeper 實(shí)例,修改上面三個(gè)配置即可。
- initLimit:這個(gè)配置項(xiàng)是用來配置 Zookeeper 接受客戶端(這里所說的客戶端不是用戶連接 Zookeeper 服務(wù)器的客戶端,而是 Zookeeper 服務(wù)器集群中連接到 Leader 的 Follower 服務(wù)器)初始化連接時(shí)最長能忍受多少個(gè)心跳時(shí)間間隔數(shù)。當(dāng)已經(jīng)超過 10 個(gè)心跳的時(shí)間(也就是 tickTime)長度后 Zookeeper 服務(wù)器還沒有收到客戶端的返回信息,那么表明這個(gè)客戶端連接失敗。總的時(shí)間長度就是 5*2000=10 秒
- syncLimit:這個(gè)配置項(xiàng)標(biāo)識(shí) Leader 與 Follower 之間發(fā)送消息,請求和應(yīng)答時(shí)間長度,最長不能超過多少個(gè) tickTime 的時(shí)間長度,總的時(shí)間長度就是 2*2000=4 秒。當(dāng)zookeeper過半的時(shí)候,就會(huì)算法選擇leader
- server.A=B:C:D:其中 A 是一個(gè)數(shù)字,表示這個(gè)是第幾號(hào)服務(wù)器;B 是這個(gè)服務(wù)器的 ip 地址;C 表示的是這個(gè)服務(wù)器與集群中的 Leader 服務(wù)器交換信息的端口;D 表示的是萬一集群中的 Leader 服務(wù)器掛了,需要一個(gè)端口來重新進(jìn)行選舉,選出一個(gè)新的 Leader,而這個(gè)端口就是用來執(zhí)行選舉時(shí)服務(wù)器相互通信的端口。如果是偽集群的配置方式,由于 B 都是一樣,所以不同的 Zookeeper 實(shí)例通信端口號(hào)不能一樣,所以要給它們分配不同的端口號(hào)。
- 除了修改 zoo.cfg 配置文件,集群模式下還要配置一個(gè)文件 myid,這個(gè)文件在 dataDir 目錄下,這個(gè)文件里面就有一個(gè)數(shù)據(jù)就是 A 的值,Zookeeper 啟動(dòng)時(shí)會(huì)讀取這個(gè)文件,拿到里面的數(shù)據(jù)與 zoo.cfg 里面的配置信息比較從而判斷到底是那個(gè) server。
- 2888 端口號(hào)是 zookeeper 服務(wù)之間通信的端口。
文件內(nèi)容就是 1。
使配置文件生效
source /home/longload/.bash_profile?
-
關(guān)閉防火墻并且禁止開機(jī)啟動(dòng)
systemctl stop firewalld.service systemctl disable firewalld.service?安裝iptables防火墻
yum install iptables-services編輯配置文件
vi /etc/sysconfig/iptables增加以下 3 行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT重啟防火墻:
systemctl restart iptables.service設(shè)置防火墻開機(jī)啟動(dòng)
systemctl enable iptables.service查看防火墻端口狀態(tài):
iptables -L -n?
其中,QuorumPeerMain 是 zookeeper 進(jìn)程,啟動(dòng)正常
查看狀態(tài):
zkServer.sh status?
查看 zookeeper 服務(wù)輸出信息
-
?由于服務(wù)信息輸出文件在/home/longload/zookeeper-3.4.6/bin/zookeeper.out
- $ tail -500f zookeeper.out
?
- 編輯/etc/rc.local 文件,加入 su - longload -c '/home/longload/zookeeper-3.4.8/bin/zkServer.sh start'
?
轉(zhuǎn)載于:https://my.oschina.net/longload/blog/713133
總結(jié)
以上是生活随笔為你收集整理的linux环境下zookeeper部署的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android后台保活实践总结:即时通讯
- 下一篇: linux 其他常用命令