centos6.5环境下zookeeper-3.4.6集群环境部署及单机部署详解
centos6.5環(huán)境下Zookeeper-3.4.6集群環(huán)境部署
【系統(tǒng)】Centos 6.5
集群部署
【軟件】準(zhǔn)備好jdk環(huán)境,此次我們的環(huán)境是open_jdk1.8.0_101
zookeeper-3.4.6.tar.gz
【步驟】
1. 準(zhǔn)備條件
如果有內(nèi)部dns或者外網(wǎng)有域名,則直接使用域名
如果沒有需要修改/etc/hosts文件,或者直接使用IP
集群規(guī)劃
主機(jī)類型IP地址 域名
zookeeper1192.168.1.1zookeeper1.chinasoft.com
zookeeper2192.168.1.2zookeeper2.chinasoft.com
zookeeper3192.168.1.3zookeeper3.chinasoft.com
注意:zookeeper因?yàn)橛兄鞴?jié)點(diǎn)和從節(jié)點(diǎn)的關(guān)系,所以部署的集群臺(tái)數(shù)最好為奇數(shù)個(gè),否則可能出現(xiàn)腦裂導(dǎo)致服務(wù)異常
2. 安裝
下載地址:http://archive.apache.org/dist/zookeeper/zookeeper-3.4.6/
解壓
tar -zxf zookeeper-3.4.6.tar.gz?
cd zookeeper-3.4.6
拷貝配置文件,修改完成后分發(fā)給其他節(jié)點(diǎn)
cd /data/zookeeper-3.4.6/
cp zoo_sample.cfg zoo.cfg
cat zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper-3.4.6/data
dataLogDir=/data/zookeeper-3.4.6/logs
clientPort=2181
server.1=u04rtv01.yaya.corp:2888:3888
server.2=u04rtv02.yaya.corp:2888:3888
server.3=u04rtv03.yaya.corp:2888:3888
3.創(chuàng)建data和Log文件夾
mkdir /data/zookeeper-3.4.6/data
mkdir /data/zookeeper-3.4.6/logs
4、在zoo.cfg中的dataDir指定的目錄下,新建myid文件。?
例如:$ZK_INSTALL/data下,新建myid。在myid文件中輸入1。表示為server.1。?
如果為snapshot/d_2,則myid文件中的內(nèi)容為 2,依此類推。?
啟動(dòng):在集群中的每臺(tái)主機(jī)上執(zhí)行如下命令
bin/zkServer.sh start?
查看狀態(tài),可以看到其中一臺(tái)為主節(jié)點(diǎn),其他兩臺(tái)為從節(jié)點(diǎn):
bin/zkServer.sh status
主節(jié)點(diǎn):
./zkServer.sh status
JMX enabled by default
Using config: /data/yunva/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader
從屬節(jié)點(diǎn):
./zkServer.sh status
JMX enabled by default
Using config: /data/yunva/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
停止:
bin/zkServer.sh stop
連接:
bin/zkCli.sh -server zookeeper1:2181?
bin/zkCli.sh -server zookeeper2:2181?
bin/zkCli.sh -server zookeeper3:2181?
報(bào)錯(cuò):
原因就是沒有在dataDir目錄下創(chuàng)建myid文件并且賦值(如1、2、3分別代表集群中的server1,server2,server3)
2016-08-22 17:55:16,145 [myid:] - INFO ?[main:QuorumPeerConfig@103] - Reading configuration from: /data/yunva/zookeeper-3.4.6/bin/../conf/zoo.cfg
2016-08-22 17:55:16,150 [myid:] - INFO ?[main:QuorumPeerConfig@340] - Defaulting to majority quorums
2016-08-22 17:55:16,150 [myid:] - ERROR [main:QuorumPeerMain@85] - Invalid config, exiting abnormally
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /data/yunva/zookeeper-3.4.6/bin/../conf/zoo.cfg
? ? ? ? at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:123)
? ? ? ? at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:101)
? ? ? ? at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
Caused by: java.lang.IllegalArgumentException: /data/yunva/zookeeper-3.4.6/data/myid file is missing
? ? ? ? at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:350)
? ? ? ? at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:119)
? ? ? ? ... 2 more
Invalid config, exiting abnormally
?
單機(jī)部署——適用于開發(fā)測(cè)試
tar -zxvf zookeeper-3.4.6.tar.gz?
cd zookeeper-3.4.6/conf
cp zoo_sample.cfg zoo.cfg
創(chuàng)建日志目錄
mkdir /data/yunva/zookeeper-3.4.6/data
mkdir /data/yunva/zookeeper-3.4.6/logs
配置:conf/zoo.cfg
tickTime=2000?
initLimit=10?
syncLimit=5?
dataDir=/data/yunva/zookeeper-3.4.6/logs
dataLogDir=/data/yunva/zookeeper-3.4.6/logs
clientPort=2181
#自動(dòng)清除日志文件
autopurge.snapRetainCount=20
autopurge.purgeInterval=48
啟動(dòng):
bin/zkServer.sh start?
連接到Zookeeper:
bin/zkCli.sh -server 127.0.0.1:2181 ?適用于Java開發(fā)
查看狀態(tài):
bin/zkServer.sh status
JMX enabled by default
Using config: /data/yunva/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
?
zookeeper的內(nèi)存配置
nohup "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" -cp "$CLASSPATH" -server -Xmx256M -Xms256M -Xss256K -XX:-UseGCOverheadLimit -XX:ReservedCodeCacheSize=64M -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSScavengeBeforeRemark -XX:+DisableExplicitGC -Djava.awt.headless=true $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null &#-cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null &?
轉(zhuǎn)載于:https://www.cnblogs.com/reblue520/p/6239735.html
總結(jié)
以上是生活随笔為你收集整理的centos6.5环境下zookeeper-3.4.6集群环境部署及单机部署详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java中对象的深克隆和浅克隆
- 下一篇: 动态新增元素的js无效的解决方法