vmware15.5
centos7
jdk8
虚拟服务器配置(三台服务器):
192.168.116.61 centos61
192.168.116.62 centos62
192.168.116.63 centos63
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/
打开链接 stable目录,
apache-zookeeper-3.5.6-bin.tar.gz
apache-zookeeper-3.5.6.tar.gz
下载第一个包(带bin的包),
上传到服务器上,解压缩:
[root@centos3 temp]# tar -zxvf apache-zookeeper-3.5.6-bin.tar.gz -C /home/soft
[root@centos3 temp]# cd /home/soft
[root@centos3 soft]# cd apache-zookeeper-3.5.6-bin
[root@centos3 apache-zookeeper-3.5.6-bin]# ll
total 32
drwxr-xr-x. 2 root root 232 Oct 9 04:14 bin
drwxr-xr-x. 2 root root 77 Oct 9 04:14 conf
drwxr-xr-x. 5 root root 4096 Oct 9 04:15 docs
drwxr-xr-x. 2 root root 4096 Dec 3 22:59 lib
-rw-r--r--. 1 root root 11358 Oct 5 19:27 LICENSE.txt
-rw-r--r--. 1 root root 432 Oct 9 04:14 NOTICE.txt
-rw-r--r--. 1 root root 1560 Oct 9 04:14 README.md
-rw-r--r--. 1 root root 1347 Oct 5 19:27 README_packaging.txt
进入conf目录,配置zoo.cfg:
[root@centos3 data]# cd conf
[root@centos3 conf]# cp zoo_sample.cfg zoo.cfg
[root@centos3 conf]# ll
total 16
-rw-r--r--. 1 root root 535 Oct 5 19:27 configuration.xsl
-rw-r--r--. 1 root root 2712 Oct 5 19:27 log4j.properties
-rw-r--r--. 1 root root 922 Dec 3 23:05 zoo.cfg
-rw-r--r--. 1 root root 922 Oct 9 04:14 zoo_sample.cfg
[root@centos3 conf]# 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/data/zookeeper/data
dataLogDir=/home/data/zookeeper/log
# 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.61=centos61:2888:3888
server.62=centos62:2888:3888
server.63=centos63:2888:3888
简洁版:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/data/zookeeper/data
dataLogDir=/home/data/zookeeper/log
clientPort=2181
server.61=centos61:2888:3888
server.62=centos62:2888:3888
server.63=centos63:2888:3888
注意:需要先创建这两个目录:
dataDir=/home/data/zookeeper/data
dataLogDir=/home/data/zookeeper/log
进入dataDir配置的目录:/home/data/zookeeper/data
[root@centos3 apache-zookeeper-3.5.6-bin]# cd /home/data/zookeeper/
[root@centos3 zookeeper]# cd data
[root@centos3 data]# ll
total 0
[root@centos3 data]# echo '61'>myid
[root@centos3 data]# ll
total 4
-rw-r--r--. 1 root root 3 Dec 3 23:12 myid
[root@centos3 data]# more myid
61
三台服务器分别配置61, 62, 63,
与zoo.cfg中server.N的序号一致:
server.61=centos61:2888:3888
server.62=centos62:2888:3888
server.63=centos63:2888:3888
分别启动三台服务器:
[root@centos3 apache-zookeeper-3.5.6-bin]# cd bin
[root@centos3 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/soft/apache-zookeeper-3.5.6-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@centos1 bin]# jps
3816 QuorumPeerMain
3854 Jps
查看状态:
[root@centos1 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/soft/apache-zookeeper-3.5.6-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[root@centos2 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/soft/apache-zookeeper-3.5.6-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[root@centos3 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/soft/apache-zookeeper-3.5.6-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
1、找不到主类,启动时报如下异常:
./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/soft/apache-zookeeper-3.5.6/bin/../conf/zoo.cfg
Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain
原因:
这是下载错了,一般一个版本有两个包:
apache-zookeeper-3.5.6-bin.tar.gz
apache-zookeeper-3.5.6.tar.gz
需要下载带有bin的包,它是编译好的版本,
另一个是源码版本,看一下它的目录就明白了。
apache-zookeeper-3.5.6-bin.tar.gz
lib目录下是编译好的jar文件:
[root@centos1 soft]# cd apache-zookeeper-3.5.6-bin
[root@centos1 apache-zookeeper-3.5.6-bin]# ll
total 32
drwxr-xr-x. 2 root root 232 Oct 9 04:14 bin
drwxr-xr-x. 2 root root 77 Oct 9 04:14 conf
drwxr-xr-x. 5 root root 4096 Oct 9 04:15 docs
drwxr-xr-x. 2 root root 4096 Dec 3 23:01 lib
-rw-r--r--. 1 root root 11358 Oct 5 19:27 LICENSE.txt
-rw-r--r--. 1 root root 432 Oct 9 04:14 NOTICE.txt
-rw-r--r--. 1 root root 1560 Oct 9 04:14 README.md
-rw-r--r--. 1 root root 1347 Oct 5 19:27 README_packaging.txt
[root@centos1 apache-zookeeper-3.5.6-bin]# cd lib
[root@centos1 lib]# ll
total 7980
-rw-r--r--. 1 root root 20437 Oct 5 21:29 audience-annotations-0.5.0.jar
-rw-r--r--. 1 root root 41123 Oct 5 21:29 commons-cli-1.2.jar
-rw-r--r--. 1 root root 66894 Oct 5 21:32 jackson-annotations-2.9.10.jar
-rw-r--r--. 1 root root 325636 Oct 5 21:32 jackson-core-2.9.10.jar
-rw-r--r--. 1 root root 1348567 Oct 5 21:32 jackson-databind-2.9.10.jar
-rw-r--r--. 1 root root 95806 Oct 5 21:32 javax.servlet-api-3.1.0.jar
-rw-r--r--. 1 root root 202738 Oct 5 21:32 jetty-http-9.4.17.v20190418.jar
-rw-r--r--. 1 root root 156436 Oct 5 21:32 jetty-io-9.4.17.v20190418.jar
-rw-r--r--. 1 root root 116281 Oct 5 21:32 jetty-security-9.4.17.v20190418.jar
-rw-r--r--. 1 root root 647357 Oct 5 21:32 jetty-server-9.4.17.v20190418.jar
-rw-r--r--. 1 root root 121159 Oct 5 21:32 jetty-servlet-9.4.17.v20190418.jar
-rw-r--r--. 1 root root 526135 Oct 5 21:32 jetty-util-9.4.17.v20190418.jar
-rw-r--r--. 1 root root 208781 Oct 5 21:32 jline-2.11.jar
-rw-r--r--. 1 root root 1535 Oct 5 19:27 jline-2.11.LICENSE.txt
-rw-r--r--. 1 root root 23931 Oct 5 21:32 json-simple-1.1.1.jar
-rw-r--r--. 1 root root 11366 Oct 5 19:27 json-simple-1.1.1.LICENSE.txt
-rw-r--r--. 1 root root 489884 Oct 5 21:32 log4j-1.2.17.jar
-rw-r--r--. 1 root root 11366 Oct 5 19:27 log4j-1.2.17.LICENSE.txt
-rw-r--r--. 1 root root 277351 Oct 5 21:32 netty-buffer-4.1.42.Final.jar
-rw-r--r--. 1 root root 11366 Oct 9 04:14 netty-buffer-4.1.42.Final.LICENSE.txt
-rw-r--r--. 1 root root 318187 Oct 5 21:32 netty-codec-4.1.42.Final.jar
-rw-r--r--. 1 root root 11366 Oct 9 04:14 netty-codec-4.1.42.Final.LICENSE.txt
-rw-r--r--. 1 root root 603879 Oct 5 21:32 netty-common-4.1.42.Final.jar
-rw-r--r--. 1 root root 11366 Oct 9 04:14 netty-common-4.1.42.Final.LICENSE.txt
-rw-r--r--. 1 root root 436951 Oct 5 21:32 netty-handler-4.1.42.Final.jar
-rw-r--r--. 1 root root 11366 Oct 9 04:14 netty-handler-4.1.42.Final.LICENSE.txt
-rw-r--r--. 1 root root 32843 Oct 5 21:32 netty-resolver-4.1.42.Final.jar
-rw-r--r--. 1 root root 11366 Oct 9 04:14 netty-resolver-4.1.42.Final.LICENSE.txt
-rw-r--r--. 1 root root 473465 Oct 5 21:32 netty-transport-4.1.42.Final.jar
-rw-r--r--. 1 root root 11366 Oct 9 04:14 netty-transport-4.1.42.Final.LICENSE.txt
-rw-r--r--. 1 root root 124118 Oct 5 21:32 netty-transport-native-epoll-4.1.42.Final.jar
-rw-r--r--. 1 root root 11366 Oct 9 04:14 netty-transport-native-epoll-4.1.42.Final.LICENSE.txt
-rw-r--r--. 1 root root 32993 Oct 5 21:32 netty-transport-native-unix-common-4.1.42.Final.jar
-rw-r--r--. 1 root root 11366 Oct 9 04:14 netty-transport-native-unix-common-4.1.42.Final.LICENSE.txt
-rw-r--r--. 1 root root 1133 Oct 5 19:27 slf4j-1.7.25.LICENSE.txt
-rw-r--r--. 1 root root 41203 Oct 5 21:32 slf4j-api-1.7.25.jar
-rw-r--r--. 1 root root 12244 Oct 5 21:32 slf4j-log4j12-1.7.25.jar
-rw-r--r--. 1 root root 984810 Oct 9 04:19 zookeeper-3.5.6.jar
-rw-r--r--. 1 root root 250329 Oct 9 04:18 zookeeper-jute-3.5.6.jar
apache-zookeeper-3.5.6.tar.gz
**zookeeper-**开头的目录下,都是源代码
[root@centos3 apache-zookeeper-3.5.6]# ll
total 172
drwxr-xr-x. 2 root root 232 Oct 9 04:14 bin
-rw-rw-r--. 1 root root 94368 Oct 9 04:14 build.xml
drwxr-xr-x. 2 root root 77 Oct 9 04:14 conf
-rw-rw-r--. 1 root root 411 Oct 5 19:27 excludeFindBugsFilter.xml
-rw-rw-r--. 1 root root 1709 Oct 5 19:27 ivysettings.xml
-rw-rw-r--. 1 root root 7810 Oct 9 04:14 ivy.xml
-rw-r--r--. 1 root root 11358 Oct 5 19:27 LICENSE.txt
-rw-r--r--. 1 root root 432 Oct 9 04:14 NOTICE.txt
-rw-rw-r--. 1 root root 1625 Oct 5 19:27 owaspSuppressions.xml
-rwxrwxr-x. 1 root root 28334 Oct 9 04:14 pom.xml
-rw-r--r--. 1 root root 1560 Oct 9 04:14 README.md
-rw-r--r--. 1 root root 1347 Oct 5 19:27 README_packaging.txt
drwxrwxr-x. 3 root root 32 Oct 9 04:16 zookeeper-assembly
drwxrwxr-x. 3 root root 47 Oct 9 04:16 zookeeper-client
drwxrwxr-x. 12 root root 4096 Oct 9 04:15 zookeeper-contrib
drwxrwxr-x. 3 root root 32 Oct 9 04:15 zookeeper-docs
drwxrwxr-x. 3 root root 35 Oct 5 19:27 zookeeper-it
drwxrwxr-x. 3 root root 32 Oct 9 04:15 zookeeper-jute
drwxrwxr-x. 5 root root 176 Oct 9 04:16 zookeeper-recipes
drwxrwxr-x. 3 root root 32 Oct 9 04:16 zookeeper-server
2、启动失败,无法找到myid:
zookeeper无法找到myid文件(myid file is missing)
[root@centos3 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/soft/apache-zookeeper-3.5.6-bin/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START
[root@centos3 bin]# cd ../logs
[root@centos3 logs]# ll
total 4
-rw-r--r--. 1 root root 1385 Dec 3 23:08 zookeeper-root-server-centos3.out
[root@centos3 logs]# more zookeeper-root-server-centos3.out
2019-12-03 23:08:22,025 [myid:] - INFO [main:QuorumPeerConfig@133] - Reading configuration from: /home/soft/apache-zookeeper-3.5.6-bin/bin/../conf/zoo.cfg
2019-12-03 23:08:22,038 [myid:] - INFO [main:QuorumPeerConfig@385] - clientPortAddress is 0.0.0.0/0.0.0.0:2181
2019-12-03 23:08:22,039 [myid:] - INFO [main:QuorumPeerConfig@389] - secureClientPort is not set
2019-12-03 23:08:22,046 [myid:] - ERROR [main:QuorumPeerMain@89] - Invalid config, exiting abnormally
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /home/soft/apache-zookeeper-3.5.6-bin/bin/../conf/zoo.cfg
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:154)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:113)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
Caused by: java.lang.IllegalArgumentException: myid file is missing
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.checkValidity(QuorumPeerConfig.java:734)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.setupQuorumPeerConfig(QuorumPeerConfig.java:605)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:420)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:150)
... 2 more
Invalid config, exiting abnormally
原因:
myid配置错误或没有配置,
myid的正确配置路径是根据zoo.cfg的配置项
dataDir=/home/data/zookeeper/data
在它的路径下生成一个myid文件,
而不是在安装目录/data/myid