1、集群規(guī)劃
在node1 node2 node3 三個節(jié)點服務器上部署Zookeeper
node1 | node2 | node3 |
---|---|---|
Zookeeper | Zookeeper | Zookeeper |
2本姥、配置主機名映射
[victor@node1 ~]$ sudo vim /etc/hosts
192.168.2.101 node1
192.168.2.102 node2
192.168.2.103 node3
3、安裝Zookeeper思想
在node1上安裝好Zookeeper形病,向node2 node3 做scp 分發(fā)
在node2 和 node3 上修改myid文件并配置環(huán)境變量
4磷脯、解壓zookeeper安裝包到/opt/module/目錄下
[victor@node1 software]$ tar -xzvf zookeeper-3.4.10.tar.gz -C /opt/module/
5蛾找、在/opt/module/zookeeper-3.4.10/這個目錄下創(chuàng)建zkdata
[victor@node1 zookeeper-3.4.10]$ cd /opt/module/zookeeper-3.4.10/
[victor@node1 zookeeper-3.4.10]$ pwd
/opt/module/zookeeper-3.4.10
[victor@node1 zookeeper-3.4.10]$ mkdir zkdata
6、重命名/opt/module/zookeeper-3.4.10/conf這個目錄下的zoo_sample.cfg為zoo.cfg
[victor@node1 ~]$ cd /opt/module/zookeeper-3.4.10/conf/
[victor@node1 conf]$ pwd
/opt/module/zookeeper-3.4.10/conf
[victor@node1 conf]$ mv zoo_sample.cfg zoo.cfg
7赵誓、配置zoo.cfg 文件
[victor@node1 conf]$ vim zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/module/zookeeper-3.4.10/zkdata
dataLogDir=/opt/module/zookeeper-3.4.10/zkdata/logs
clientPort=2181
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
maxClientCnxns=300
尖叫提示:maxClientCnxns默認連接最多60打毛,超過設置的連接數(shù)會報Too many connections from錯誤
8、創(chuàng)建myid文件編寫內容
[victor@node1 zookeeper-3.4.10]$ cd /opt/module/zookeeper-3.4.10/zkdata/
[victor@node1 zkdata]$ touch myid
[victor@node1 zkdata]$ echo 1 > myid
[victor@node1 zkdata]$ cat myid
1
9俩功、zookeeper 日志配置
$http://www.reibang.com/p/05bab8d5419c
10幻枉、使用scp把node1節(jié)點上的Zookeeper分發(fā)到node2 node3 兩臺節(jié)點上
[victor@node1 ~]$ scp -r /opt/module/zookeeper-3.4.10 root@node2:/opt/module/
[victor@node1 ~]$ scp -r /opt/module/zookeeper-3.4.10 root@node3:/opt/module/
11、修改node2 node3 節(jié)點的myid
node2
[victor@node2 ~]$ echo 2 > /opt/module/zookeeper-3.4.10/zkdata/myid
[victor@node2 zkdata]$ cat myid
2
node3
[victor@node3 ~]$ echo 3 > /opt/module/zookeeper-3.4.10/zkdata/myid
[victor@node3 zkdata]$ cat myid
3
12绑雄、分別啟動node1 node2 node3 節(jié)點上的zookeeper
[victor@node1 zookeeper-3.4.10]$ bin/zkServer.sh start
[victor@node2 zookeeper-3.4.10]$ bin/zkServer.sh start
[victor@node3 zookeeper-3.4.10]$ bin/zkServer.sh start
**尖叫提示:當啟動第一臺時會報****This ZooKeeper instance is not currently serving requests** **
錯誤提示展辞,這是因為集群里的結點只剩下一臺奥邮,或者不足半數(shù)時万牺,就會出現(xiàn)這個錯誤提示,根據(jù)zookeeper每次write請求
洽腺,都要寫到log日志脚粟,并刷到磁盤里的特性,zookeeper最好用本地磁盤蘸朋,且磁盤IO略好核无。**
13、分別查看node1 node2 node3 節(jié)點上zookeeper的運行狀態(tài)
node1
[victor@node1 zookeeper-3.4.10]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
node2
[victor@node2 zookeeper-3.4.10]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
node3
[victor@node3 zookeeper-3.4.10]$ bin/zkServer.sh status
JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
14藕坯、查找不能成功啟動原因
查看啟動時報的是什么異常
[victor@node3 zookeeper-3.4.10]$ bin/zkServer.sh start-foreground
查看運行過程中報的是什么異常
[victor@node3 zookeeper-3.4.10]$ bin/zkServer.sh print-cmd
15团南、zookeeper 刪除日志
$http://www.reibang.com/p/00799191cba3
16、zookeeper 查看日志
[victor@node1 zookeeper]$ java -classpath .:zookeeper-3.4.10.jar:lib/slf4j-api-1.6.1.jar org.apache.zookeeper.server.LogFormatter zkdata/version-2 /log.400000001