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

mrphzbgm  于 2022-12-09  发布在  Apache
关注(0)|答案(1)|浏览(321)

我尝试按照文档为zookeeper添加多个地址,添加以下配置应该足够了

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

查看了Zookeeper的代码:https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/QuorumPeer.java行327,它检查类似的键zookeeper.multiAddress.enabled,但仍然将multiAddress.enabled求值为假
参考文件: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
qacovj5a

qacovj5a1#

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

您可以将***-Dzookeeper.multiAddress.enabled=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 ...

相关问题