当前位置:   article > 正文

Zookeeper服务器单机版启动_port datadir

port datadir

先来看下ZooKeeper服务端的整体构架。

1.单机版服务器启动

        ZooKeeper服务器的启动,大体分为以下5个步骤:配置文件解析、初始化数据管理器、初始化网络I/O管理器、数据恢复与对外服务。下图为单机版的服务器启动流程。

1.1 预启动

预启动步骤如下。

(1)统一由QuorumPeerMain作为启动类。

         无论是单机版还是集群版,在启动ZooKeeper服务器时,在zkServer.cmd和zkServer.sh两个脚本中,都配置了使用org.apach.zookeeper.server.quorum.QuorumPeerMain作为启动类入口。

  1. public class QuorumPeerMain {
  2. private static final Logger LOG = LoggerFactory.getLogger(QuorumPeerMain.class);
  3. private static final String USAGE = "Usage: QuorumPeerMain configfile";
  4. protected QuorumPeer quorumPeer;
  5. /**
  6. * To start the replicated server specify the configuration file name on
  7. * the command line.
  8. * @param args path to the configfile
  9. */
  10. public static void main(String[] args) {
  11. QuorumPeerMain main = new QuorumPeerMain();
  12. try {
  13. main.initializeAndRun(args);
  14. } catch (IllegalArgumentException e) {
  15. LOG.error("Invalid arguments, exiting abnormally", e);
  16. LOG.info(USAGE);
  17. System.err.println(USAGE);
  18. System.exit(2);
  19. } catch (ConfigException e) {
  20. LOG.error("Invalid config, exiting abnormally", e);
  21. System.err.println("Invalid config, exiting abnormally");
  22. System.exit(2);
  23. } catch (Exception e) {
  24. LOG.error("Unexpected exception, exiting abnormally", e);
  25. System.exit(1);
  26. }
  27. LOG.info("Exiting normally");
  28. System.exit(0);
  29. }
  30. protected void initializeAndRun(String[] args)
  31. throws ConfigException, IOException
  32. {
  33. QuorumPeerConfig config = new QuorumPeerConfig();
  34. if (args.length == 1) {
  35. config.parse(args[0]); //解析配置文件zoo.cfg
  36. }
  37. // Start and schedule the the purge task //创建并启动历史文件清理器
  38. DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
  39. .getDataDir(), config.getDataLogDir(), config
  40. .getSnapRetainCount(), config.getPurgeInterval());
  41. purgeMgr.start();
  42. if (args.length == 1 && config.servers.size() > 0) { //集群模式
  43. runFromConfig(config);
  44. } else { //单机模式
  45. LOG.warn("Either no config or no quorum defined in config, running "
  46. + " in standalone mode");
  47. // there is only server in the quorum -- run as standalone
  48. ZooKeeperServerMa
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/804574
推荐阅读
相关标签
  

闽ICP备14008679号