使用zookeeper中启用的multiAddress.enabled可以指定多个地址



我正在尝试为动物园管理员添加多个地址根据文档,添加以下配置应该足够

multiAddress.enabled=true
server.1=0.0.0.0:2888:3888
server.2=192.168.1.100:2888:3888 | 192.168.1.101:2889:3889

但是添加以下内容后,我得到错误消息

org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Multiple address feature is disabled, but multiple addresses were specified for sid 2
at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.initializeWithAddressString(QuorumPeer.java:327)
at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.<init>(QuorumPeer.java:278)
at org.apache.zookeeper.server.quorum.QuorumPeer$QuorumServer.<init>(QuorumPeer.java:273)
at org.apache.zookeeper.server.quorum.flexible.QuorumMaj.<init>(QuorumMaj.java:92)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.createQuorumVerifier(QuorumPeerConfig.java:658)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseDynamicConfig(QuorumPeerConfig.java:689)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.setupQuorumPeerConfig(QuorumPeerConfig.java:663)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:491)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:194)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:125)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:91)
Invalid config, exiting abnormally

查看动物园管理员代码:https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/QuorumPeer.java第327行,它检查类似的密钥zookeeper.multiAddress.enabled,但仍将multiAddress.eenabled评估为false

文档参考:https://zookeeper.apache.org/doc/r3.6.1/zookeeperAdmin.html

server.x=[hostname]:nnnnn[:nnnnn] etc : (No Java system property) servers making up the ZooKeeper ensemble. When the server starts up, it determines which server it is by looking for the file myid in the data directory. That file contains the server number, in ASCII, and it should match x in server.x in the left hand side of this setting. The list of servers that make up ZooKeeper servers that is used by the clients must match the list of ZooKeeper servers that each ZooKeeper server has. There are two port numbers nnnnn. The first followers use to connect to the leader, and the second is for leader election. If you want to test multiple servers on a single machine, then different ports can be used for each server.
Since ZooKeeper 3.6.0 it is possible to specify multiple addresses for each ZooKeeper server (see ZOOKEEPER-3188). To enable this feature, you must set the multiAddress.enabled configuration property to true. This helps to increase availability and adds network level resiliency to ZooKeeper. When multiple physical network interfaces are used for the servers, ZooKeeper is able to bind on all interfaces and runtime switching to a working interface in case a network error. The different addresses can be specified in the config using a pipe ('|') character. A valid configuration using multiple addresses looks like:
server.1=zoo1-net1:2888:3888|zoo1-net2:2889:3889
server.2=zoo2-net1:2888:3888|zoo2-net2:2889:3889
server.3=zoo3-net1:2888:3888|zoo3-net2:2889:3889

multiAddress.enabledjava系统属性,未在zoo.cfg中配置

您可以将-Dzookeeper.multiAddress.enable=true添加到zkServer.sh的某个位置,当您可以从ps进行grep时,它将生效

例如:

# ps -elf | grep java | grep multiAddress
0 S root      6973     1  0  80   0 - 1209436 futex_ 14:59 pts/0  00:00:04 java -Dzookeeper.log.dir=/root/apache-zookeeper-3.8.0-bin/bin/../logs -Dzookeeper.log.file=zookeeper-root-server-dev91.log -Dzookeeper.multiAddress.enabled=true -XX:+HeapDumpOnOutOfMemoryError ...

最新更新