您好,登錄后才能下訂單哦!
ZooKeeper是一個分布式開源框架,提供了協(xié)調(diào)分布式應(yīng)用的基本服務(wù),它向外部應(yīng)用暴露一組通用服務(wù)——分布式同步(Distributed Synchronization).命名服務(wù)(Naming Service).集群維護(hù)(Group Maintenance)等,簡化分布式應(yīng)用協(xié)調(diào)及其管理的難度,提供高性能的分布式服務(wù)。ZooKeeper本身可以以Standalone模式安裝運(yùn)行,不過它的長處在于通過分布式ZooKeeper集群(一個Leader,多個Follower),基于一定的策略來保證ZooKeeper集群的穩(wěn)定性和可用性,從而實(shí)現(xiàn)分布式應(yīng)用的可靠性。(我是網(wǎng)上抄寫的,方便大家學(xué)習(xí),請勿吐槽?。。?
這里先講解一下單節(jié)點(diǎn)安裝(后期會提供集群安裝模式),由于直接進(jìn)行操作,故下面記錄詳細(xì)步驟:
ZooKeeper Standalone模式
1.修改操作系統(tǒng)的/etc/hosts 文件中添加
# zookeeper servers (主機(jī)IP jeesz-provider-01)
[root@cloud ~]# vi/etc/hosts
xxx.xxx.xxx.xxxjeesz-provider-01
2.到 http://apache.fayea.com/zookeeper/下載 zookeeper-3.4.6
[root@cloud ~]# wgethttp://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
由于我提前下載了并上傳到了我指定的目錄:/home/jeesz
3. 解壓zookeeper 安裝包
[root@cloud jeesz] tar -zxvfzookeeper-3.4.6.tar.gz
4. 在/home/jeesz/zookeeper-3.4.6目錄下創(chuàng)建以下目錄
[root@cloud ~]# cd /home/jeesz/zookeeper-3.4.6
[root@cloud zookeeper-3.4.6]# mkdirdata
[root@cloudzookeeper-3.4.6]# mkdir logs
5.將 zookeeper-3.4.6/conf 目錄下的 zoo_sample.cfg 文件拷貝一份,命名為為zoo.cfg
[root@cloudconf]# cpzoo_sample.cfg zoo.cfg
6.修改 zoo.cfg 配置文件
[root@cloud conf]# vizoo.cfg
# The number ofmilliseconds of each tick
tickTime=2000
# The number of ticksthat the initial
# synchronization phasecan take
initLimit=10
# The number of ticksthat can pass between
#sending a request and getting an acknowledgement
syncLimit=5
# the directory wherethe snapshot is stored.
# donot use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/jeesz/zookeeper-3.4.6/data
dataLogDir=/home/jeesz/zookeeper-3.4.6/logs
# the port at which theclients will connect
clientPort=2181
#2888,3888 are election port
server.1=jeesz-provider-01:2888:3888
7.在/home/jeesz/zookeeper-3.4.6/data 下創(chuàng)建 myid 文件
編輯 myid 文件,并在對應(yīng)的 IP 的機(jī)器上輸入對應(yīng)的編號。如在 zookeeper 上,myid
文件內(nèi)容就是 1。如果只在單點(diǎn)上進(jìn)行安裝配置,那么只有一個 server.1。
[root@cloud data]# vi myid
1
8.jeesz 用戶下修改 vi /home/jeesz/.bash_profile,增加 zookeeper 配置
[root@cloud ~] vi /home/jeesz/.bash_profile
# zookeeper env
exportZOOKEEPER_HOME=/home/jeesz/zookeeper-3.4.6
exportPATH=$ZOOKEEPER_HOME/bin:$PATH
使配置文件生效
[root@cloud~]# source/home/jeesz/.bash_profile
9.在防火墻中打開要用到的端口 2181.2888.3888
切換到 root 用戶權(quán)限,執(zhí)行以下命令:
[root@cloud ~]# chkconfig iptables on
[root@cloud ~]# service iptables start
編輯/etc/sysconfig/iptables
[root@cloud ~]# vi /etc/sysconfig/iptables
增加以下 3 行:
-A INPUT -m state --stateNEW -m tcp -p tcp --dport 2181 -j ACCEPT
-A INPUT -m state --stateNEW -m tcp -p tcp --dport 2888 -j ACCEPT
-A INPUT -m state --stateNEW -m tcp -p tcp --dport 3888 -j ACCEPT
重啟防火墻:
[root@cloud ~] service iptables restart
查看防火墻端口狀態(tài):
[root@cloud]# serviceiptables status
Table: filter
Chain INPUT (policyACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 stateRELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-withicmp-host-prohibited
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:8080
7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2181
8 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2888
9 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:3888
Chain FORWARD (policyACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-withicmp-host-prohibited
Chain OUTPUT (policyACCEPT)
num target prot opt source destination
10.啟動并測試 zookeeper
(1) 到/home/jeesz/zookeeper-3.4.6/bin 目錄中執(zhí)行:
[root@cloud bin]# zkServer.shstart
(2) 輸入 jps 命令查看進(jìn)程:
[root@cloudzookeeper-3.4.6]# jps
48064 Jps
47348 QuorumPeerMain
46826 Bootstrap
其中,QuorumPeerMain 是 zookeeper 進(jìn)程,啟動正常
(3) 查看狀態(tài):
[root@cloud bin]# zkServer.shstatus
JMX enabled by default
Using config: /home/jeesz/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
(4) 查看 zookeeper 服務(wù)輸出信息:
由于服務(wù)信息輸出文件在/home/jeesz/zookeeper-3.4.6/bin/zookeeper.out
[root@cloudbin]# tail -fzookeeper.out
2016-02-16 02:20:14,500[myid:] - INFO [main:QuorumPeerConfig@103] - Reading configuration from:/home/jeesz/zookeeper-3.4.6/bin/../conf/zoo.cfg
2016-02-16 02:20:14,700[myid:] - ERROR [main:QuorumPeerConfig@289] - Invalid configuration, only oneserver specified (ignoring)
......
11.停止 zookeeper 進(jìn)程
[root@cloudbin]# zkServer.shstop
12.配置 zookeeper 開機(jī)使用jeesz 用戶啟動
編輯/etc/rc.local 文件,加入:
[root@cloudbin]# vi /etc/rc.local
su - jeesz -c'/home/jeesz/zookeeper-3.4.6/bin/zkServer.sh start'
想了解更多詳細(xì)請點(diǎn)擊源碼地址獲取:mingli.com
有興趣的朋友們可以前往球球哦~一起分享學(xué)習(xí)技術(shù):2042849237
請大家持續(xù)關(guān)注搭建JEESZ分布式架構(gòu)8--消息中間件安裝單、多節(jié)點(diǎn)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。