Closed Hooollin closed 1 year ago
Looks like it's due to 3 nodes using the same internal_port. If you deploy three instances on one node, you need to use different port
, forwarding_port
, internal_port
.
And use a configuration similar to the following in
<cluster>
<server>
<id>1</id>
<host>127.0.0.1</host>
<internal_port>8103</internal_port>
<forwarding_port>8102</forwarding_port>
</server>
<server>
<id>2</id>
<host>127.0.0.1</host>
<internal_port>8113</internal_port>
<forwarding_port>8112</forwarding_port>
</server>
<server>
<id>3</id>
<host>127.0.0.1</host>
<internal_port>8123</internal_port>
<forwarding_port>8122</forwarding_port>
</server>
</cluster>
How can I deploy a 3-node RaftKeeper cluster on a single machine? After setting different ports for the nodes, I tried to modify the my_id
field in config.xml
and start 3 instances of RaftKeeper in 3 different folders, but encountered port conflict issues. Before starting the 3 instances, I used pgrep
and kill
to terminate all the previous RaftKeeper instances, making sure the availability of the ports to be used in the 3 instance.
You can use:
./raftkeeper server --config-file ./config1.xml
./raftkeeper server --config-file ./config2.xml
./raftkeeper server --config-file ./config3.xml
Different port
internal_port
forwarding_port
and my_id
are specified in config1.xml, config2.xml, and config3.xml.
Please pull the latest code to 9c10ee24534b21f0d17d1906ebae41646446779b. Fixed some issues.
After configuring three different config.xml
files, I successfully started the service in cluster mode. There are two issues keeps me from successfully starting the RaftKeeper service.
I did not modify the parameters for keeper
in the config.xml
file to correspond with the cluster configuration, causing RaftKeeper to start all services on default ports, resulting in port conflicts on single machine.
Starting the service in the RaftKeeper/
directory with ./lib/raftkeeper server --config=conf/config.xml
caused a null pointer exception in BaseDeamon
. I was unable to generate a coredump file on my Mac to accurately locate the issue or provide relevant logs. However, starting the service with ./raftkeeper server --config=conf/config.xml
in the RaftKeeper/lib/
directory allows the service to start successfully.
My three config.xml
files are as follows (For those who may run into the same problems):
config1.xml:
<?xml version="1.0"?>
<raftkeeper>
<logger>
<!-- Logger file path, default is empty string. If is empty string will not log to file -->
<path>./node1/log/raftkeeper.log</path>
<!-- Error logger file path, default is empty string. If is empty string will not log to file -->
<err_log_path>./node1/log/raftkeeper.err.log</err_log_path>
</logger>
<keeper>
<!-- My id in cluster. -->
<my_id>1</my_id>
<!-- Bing(d, maybe it's a typo)ing host, default is "0.0.0.0." -->
<host>127.0.0.1</host>
<!-- Port for user request and 4lw command -->
<port>8101</port>
<!-- Port for follower forward write request and session info to leader. -->
<forwarding_port>8102</forwarding_port>
<!-- Port for Raft internal usage: heartbeat, log replicate, leader selection etc. -->
<internal_port>8103</internal_port>
<!-- Raft log store directory -->
<log_dir>./node1/data/log</log_dir>
<!-- Raft snapshot store directory -->
<snapshot_dir>./node1/data/snapshot</snapshot_dir>
<!-- If you want a RaftKeeper cluster, you can uncomment this and configure it carefully -->
<cluster>
<server>
<id>1</id>
<host>127.0.0.1</host>
<forwarding_port>8102</forwarding_port>
<internal_port>8103</internal_port>
<!-- `true` if this node is learner. Learner will not initiate or participate in leader election. -->
<!-- <learner>false</learner> -->
<!-- Priority of this server, default is 1 and if is 0 the server will never be leader. -->
<!-- <priority>1</priority> -->
</server>
<server>
<id>2</id>
<host>127.0.0.1</host>
<forwarding_port>8112</forwarding_port>
<internal_port>8113</internal_port>
</server>
<server>
<id>3</id>
<host>127.0.0.1</host>
<forwarding_port>8122</forwarding_port>
<internal_port>8123</internal_port>
</server>
</cluster>
</keeper>
</raftkeeper>
----------------------------------------------------------
config2.xml:
<?xml version="1.0"?>
<raftkeeper>
<logger>
<!-- Logger file path, default is empty string. If is empty string will not log to file -->
<path>./node2/log/raftkeeper.log</path>
<!-- Error logger file path, default is empty string. If is empty string will not log to file -->
<err_log_path>./node2/log/raftkeeper.err.log</err_log_path>
</logger>
<keeper>
<!-- My id in cluster. -->
<my_id>2</my_id>
<!-- Bing(d)ing host, default is "0.0.0.0." -->
<host>127.0.0.1</host>
<!-- Port for user request and 4lw command -->
<port>8111</port>
<!-- Port for follower forward write request and session info to leader. -->
<forwarding_port>8112</forwarding_port>
<!-- Port for Raft internal usage: heartbeat, log replicate, leader selection etc. -->
<internal_port>8113</internal_port>
<!-- Raft log store directory -->
<log_dir>./node2/data/log</log_dir>
<!-- Raft snapshot store directory -->
<snapshot_dir>./node2/data/snapshot</snapshot_dir>
<!-- If you want a RaftKeeper cluster, you can uncomment this and configure it carefully -->
<cluster>
same as cluster in config1.xml
</cluster>
</keeper>
</raftkeeper>
----------------------------------------------------------
config3.xml:
<?xml version="1.0"?>
<raftkeeper>
<logger>
<!-- Logger file path, default is empty string. If is empty string will not log to file -->
<path>./node3/log/raftkeeper.log</path>
<!-- Error logger file path, default is empty string. If is empty string will not log to file -->
<err_log_path>./node3/log/raftkeeper.err.log</err_log_path>
</logger>
<keeper>
<!-- My id in cluster. -->
<my_id>3</my_id>
<!-- Binging host, default is "0.0.0.0." -->
<host>127.0.0.1</host>
<!-- Port for user request and 4lw command -->
<port>8121</port>
<!-- Port for follower forward write request and session info to leader. -->
<forwarding_port>8122</forwarding_port>
<!-- Port for Raft internal usage: heartbeat, log replicate, leader selection etc. -->
<internal_port>8123</internal_port>
<!-- Raft log store directory -->
<log_dir>./node3/data/log</log_dir>
<!-- Raft snapshot store directory -->
<snapshot_dir>./node3/data/snapshot</snapshot_dir>
<!-- If you want a RaftKeeper cluster, you can uncomment this and configure it carefully -->
<cluster>
same as cluster in config1.xml
</cluster>
</keeper>
</raftkeeper>
@Hooollin Thanks for your recording.
It works fine now. I believe the NPE is due to the same data/
directory I used in these 3 nodes.
Thanks a lot!
RaftKeeper is new in github. We appreciate any contributions for docs and code and we have some easy tasks for beginners, if you are interesting see #22 .
System: MacOS Ventura 13.2.1 Build Version: the lastest commit bf5f6c1
I built RaftKeeper on my machine following the instruction in README. Then I modified the configuration file
conf/config.xml
to set up a 3 nodes Raft cluster:With that configuration and I run RaftKeeper with command
./lib/raftkeeper server --config=conf/config.xml
, got the logs below:It seems that the Raft cluster has failed to maintain heartbeats, resulting in re-elections.
Has this situation occurred before? If it is confirmed to be a reproducible situation, I am willing to participate in resolving it.