zookeeper 集群簡單搭建,以及Error contacting service,It is probably not running問題解決


第一步:現在http://www-eu.apache.org/dist/zookeeper/zookeeper-3.4.9/ 下載一個gz包,然后解壓。當然,zookeeper 需要在java 的環境中運行,所以,你需要安裝jdk http://java.sun.com/javase/downloads/index.jsp  。

第二部:cd zookeeper-3.4.9/,cp conf/zoo_sample.cfg conf/zoo.cfg     zoo_sample.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

建議需要去看一下 zookeeper的部署和管理的指南 http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance 雖然是英文的,但是可以進行翻譯

在部署和管理的指南中有提到 

dataDir=/tmp/zookeeper  這個配置,在原注解中do not use /tmp for storage, /tmp here is just example sakes. 需要將tmp 換成其他目錄,官方文檔上是:/var/lib/zookeeper/

然后是配置各個節點 地址  最終的配置如下

# 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/zookeeper/server/data

# 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 = 10.211.55.9:2888:3888

server.2 = 10.211.55.12:2888:3888

server.3 = 10.211.55.13:2888:3888

 

 

10.211.55.9是我自己的ip 根據自己的ip去配置,接下來要注意:

在配置的dataDir 下創建myid 文件,內容就是對應的你當前 ip 下的 server.x

例如 server 的 ip 為 10.211.55.9  conf 文件中是 server.1 = 10.211.55.9:2888:3888   myid 對應的內容就是 1

      server 的 ip 為 10.211.55.12  conf 文件中是 server.2 = 10.211.55.12:2888:3888  myid 對應的內容就是 2

  即:server.x  =>  myid = x

 

最后一步在每個服務器上開啟服務,cd zookeeper-3.4.9/  ./bin/zkServer.sh start

 

 

 啟動之后,通過  ./bin/zkServer.sh status 查看服務的狀態

 

 或者

 

以上都是成功的

如果出現了提示:Error contacting service.It is probably not running

會有以下的原因:

1. 配置錯了,仔細閱讀以下流程

2. zoo.cfg 三個端口沒有開啟。

 

 

 

 

 

 附上官網文檔,地址 http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance 即 指南

  1. Install the Java JDK. You can use the native packaging system for your system, or download the JDK from:

    http://java.sun.com/javase/downloads/index.jsp

  2. Set the Java heap size. This is very important to avoid swapping, which will seriously degrade ZooKeeper performance. To determine the correct value, use load tests, and make sure you are well below the usage limit that would cause you to swap. Be conservative - use a maximum heap size of 3GB for a 4GB machine.

  3. Install the ZooKeeper Server Package. It can be downloaded from:

    http://zookeeper.apache.org/releases.html

  4. Create a configuration file. This file can be called anything. Use the following settings as a starting point:

    tickTime=2000
    dataDir=/var/lib/zookeeper/
    clientPort=2181
    initLimit=5
    syncLimit=2
    server.1=zoo1:2888:3888
    server.2=zoo2:2888:3888
    server.3=zoo3:2888:3888

    You can find the meanings of these and other configuration settings in the section Configuration Parameters. A word though about a few here:

    Every machine that is part of the ZooKeeper ensemble should know about every other machine in the ensemble. You accomplish this with the series of lines of the form server.id=host:port:port. The parameters host and port are straightforward. You attribute the server id to each machine by creating a file named myid, one for each server, which resides in that server's data directory, as specified by the configuration file parameter dataDir.

  5. The myid file consists of a single line containing only the text of that machine's id. So myid of server 1 would contain the text "1" and nothing else. The id must be unique within the ensemble and should have a value between 1 and 255.

  6. If your configuration file is set up, you can start a ZooKeeper server:

    $ java -cp zookeeper.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:lib/log4j-1.2.15.jar:conf \ org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg

    QuorumPeerMain starts a ZooKeeper server, JMX management beans are also registered which allows management through a JMX management console. The ZooKeeper JMX document contains details on managing ZooKeeper with JMX.

    See the script bin/zkServer.sh, which is included in the release, for an example of starting server instances.

  7. Test your deployment by connecting to the hosts:

    In Java, you can run the following command to execute simple operations:

    $ bin/zkCli.sh -server 127.0.0.1:218

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM