L'appel de org.apache.zookeeper.server.quorum.QuorumPeerMain.main() ne fonctionne pas.
Réponses
Trop de publicités?Pour démarrer ZooKeeper
vous devez exécuter la classe ZooKeeperServerMain
Vous pouvez utiliser le code suivant pour démarrer ZooKeeper
en mode intégré.
Properties startupProperties = ...
QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
try {
quorumConfiguration.parseProperties(startupProperties);
} catch(Exception e) {
throw new RuntimeException(e);
}
zooKeeperServer = new ZooKeeperServerMain();
final ServerConfig configuration = new ServerConfig();
configuration.readFrom(quorumConfiguration);
new Thread() {
public void run() {
try {
zooKeeperServer.runFromConfig(configuration);
} catch (IOException e) {
log.error("ZooKeeper Failed", e);
}
}
}.start();
271828183
Points
518
Vous pouvez utiliser quelque chose comme ça.
int clientPort = 21818; // none-standard
int numConnections = 5000;
int tickTime = 2000;
String dataDirectory = System.getProperty("java.io.tmpdir");
File dir = new File(dataDirectory, "zookeeper").getAbsoluteFile();
ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTime);
NIOServerCnxn.Factory standaloneServerFactory = new NIOServerCnxn.Factory(new InetSocketAddress(clientPort), numConnections);
standaloneServerFactory.startup(server); // start the server.
Et pour l'arrêter, appelez simplement standaloneServerFactory.shutdown()
Geoff Bourne
Points
311
S'appuyant sur 1 de réponse en ajoutant l'utilisation d'un port éphémère (représenté en zkPort
) et mis à jour pour les dernières API ZK:
int tickTime = 2000;
int numConnections = 5000;
String dataDirectory = System.getProperty("java.io.tmpdir");
File dir = new File(dataDirectory, "zookeeper").getAbsoluteFile();
ZooKeeperServer server = new ZooKeeperServer(dir, dir, tickTime);
standaloneServerFactory = ServerCnxnFactory.createFactory(0, numConnections);
int zkPort = standaloneServerFactory.getLocalPort();
standaloneServerFactory.startup(server);
Nikita Prokopov
Points
559