{"id":178168,"date":"2020-05-10T09:49:02","date_gmt":"2020-05-10T01:49:02","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=178168"},"modified":"2020-04-26T09:49:36","modified_gmt":"2020-04-26T01:49:36","slug":"zookeeper-install-comfiguration","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/zookeeper-install-comfiguration.html","title":{"rendered":"ZooKeeper \u5b89\u88c5\u914d\u7f6e\u5165\u95e8\u6559\u7a0b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nZooKeeper \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\uff0c\u5f00\u653e\u6e90\u7801\u7684\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u534f\u540c\u670d\u52a1\u3002ZooKeeper \u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u5c06\u90a3\u4e9b\u590d\u6742\u4e14\u5bb9\u6613\u51fa\u9519\u7684\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u670d\u52a1\u5c01\u88c5\u8d77\u6765\uff0c\u6784\u6210\u4e00\u4e2a\u9ad8\u6548\u53ef\u9760\u7684\u539f\u8bed\u96c6\uff0c\u5e76\u4ee5\u4e00\u7cfb\u5217\u7b80\u5355\u6613\u7528\u7684\u63a5\u53e3\u63d0\u4f9b\u7ed9\u7528\u6237\u4f7f\u7528\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

ZooKeeper \u6700\u65e9\u8d77\u6e90\u4e8e\u96c5\u864e\u7814\u7a76\u9662\u7684\u4e00\u4e2a\u7814\u7a76\u5c0f\u7ec4\u3002\u5728\u5f53\u65f6\uff0c\u7814\u7a76\u4eba\u5458\u53d1\u73b0\uff0c\u5728\u96c5\u864e\u5185\u90e8\u5f88\u591a\u5927\u578b\u7cfb\u7edf\u57fa\u672c\u90fd\u9700\u8981\u4f9d\u8d56\u4e00\u4e2a\u7c7b\u4f3c\u7684\u7cfb\u7edf\u6765\u8fdb\u884c\u5206\u5e03\u5f0f\u534f\u540c\uff0c\u4f46\u662f\u8fd9\u4e9b\u7cfb\u7edf\u5f80\u5f80\u90fd\u5b58\u5728\u5206\u5e03\u5f0f\u5355\u70b9\u95ee\u9898\u3002<\/p>\n

\u6240\u4ee5\uff0c\u96c5\u864e\u7684\u5f00\u53d1\u4eba\u5458\u5c31\u5f00\u53d1\u4e86\u4e00\u4e2a\u901a\u7528\u7684\u65e0\u5355\u70b9\u95ee\u9898\u7684\u5206\u5e03\u5f0f\u534f\u8c03\u6846\u67b6\uff0c\u8fd9\u5c31\u662f ZooKeeper\u3002ZooKeeper \u4e4b\u540e\u5728\u5f00\u6e90\u754c\u88ab\u5927\u91cf\u4f7f\u7528\uff0c\u4e0b\u9762\u5217\u51fa\u4e86 3 \u4e2a\u8457\u540d\u5f00\u6e90\u9879\u76ee\u662f\u5982\u4f55\u4f7f\u7528 ZooKeeper\uff1a<\/p>\n

Hadoop\uff1a\u4f7f\u7528 ZooKeeper \u505a Namenode \u7684\u9ad8\u53ef\u7528\u3002
\nHBase\uff1a\u4fdd\u8bc1\u96c6\u7fa4\u4e2d\u53ea\u6709\u4e00\u4e2a master\uff0c\u4fdd\u5b58 hbase:meta \u8868\u7684\u4f4d\u7f6e\uff0c\u4fdd\u5b58\u96c6\u7fa4\u4e2d\u7684 RegionServer \u5217\u8868\u3002
\nKafka\uff1a\u96c6\u7fa4\u6210\u5458\u7ba1\u7406\uff0ccontroller \u8282\u70b9\u9009\u4e3e\u3002<\/p>\n

\u5f88\u591a\u5206\u5e03\u5f0f\u534f\u8c03\u670d\u52a1\u90fd\u53ef\u4ee5\u7528 ZooKeeper \u6765\u505a\uff0c\u5176\u4e2d\u5178\u578b\u5e94\u7528\u573a\u666f\u5982\u4e0b\uff1a<\/p>\n

\u914d\u7f6e\u7ba1\u7406\uff08configuration management\uff09\uff1a\u5982\u679c\u6211\u4eec\u505a\u666e\u901a\u7684\u00a0Java\u00a0\u5e94\u7528\uff0c\u4e00\u822c\u914d\u7f6e\u9879\u5c31\u662f\u4e00\u4e2a\u672c\u5730\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5982\u679c\u662f\u5fae\u670d\u52a1\u7cfb\u7edf\uff0c\u5404\u4e2a\u72ec\u7acb\u670d\u52a1\u90fd\u8981\u4f7f\u7528\u96c6\u4e2d\u5316\u7684\u914d\u7f6e\u7ba1\u7406\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u9700\u8981 ZooKeeper\u3002
\nDNS \u670d\u52a1
\n\u7ec4\u6210\u5458\u7ba1\u7406\uff08group membership\uff09\uff1a\u6bd4\u5982\u4e0a\u9762\u8bb2\u5230\u7684 HBase \u5176\u5b9e\u5c31\u662f\u7528\u6765\u505a\u96c6\u7fa4\u7684\u7ec4\u6210\u5458\u7ba1\u7406\u3002
\n\u5404\u79cd\u5206\u5e03\u5f0f\u9501<\/p>\n

ZooKeeper \u9002\u7528\u4e8e\u5b58\u50a8\u548c\u534f\u540c\u76f8\u5173\u7684\u5173\u952e\u6570\u636e\uff0c\u4e0d\u9002\u5408\u7528\u4e8e\u5927\u6570\u636e\u91cf\u5b58\u50a8\u3002\u5982\u679c\u8981\u5b58 KV \u6216\u8005\u5927\u91cf\u7684\u4e1a\u52a1\u6570\u636e\uff0c\u8fd8\u662f\u8981\u7528\u6570\u636e\u5e93\u6216\u8005\u5176\u4ed6 NoSql \u6765\u505a\u3002<\/p>\n

\u4e3a\u4ec0\u4e48 ZooKeeper \u4e0d\u9002\u5408\u5927\u6570\u636e\u91cf\u5b58\u50a8\u5462\uff1f\u4e3b\u8981\u6709\u4ee5\u4e0b\u4e24\u4e2a\u539f\u56e0\uff1a<\/p>\n

\u8bbe\u8ba1\u65b9\u9762\uff1aZooKeeper \u9700\u8981\u628a\u6240\u6709\u7684\u6570\u636e\uff08\u5b83\u7684 data tree\uff09\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u8fd9\u5c31\u51b3\u5b9a\u4e86ZooKeeper \u5b58\u50a8\u7684\u6570\u636e\u91cf\u53d7\u5185\u5b58\u7684\u9650\u5236\u3002\u8fd9\u4e00\u70b9 ZooKeeper \u548c Redis \u6bd4\u8f83\u50cf\u3002\u4e00\u822c\u7684\u6570\u636e\u5e93\u7cfb\u7edf\u4f8b\u5982 MySQL\uff08\u4f7f\u7528 InnoDB \u5b58\u50a8\u5f15\u64ce\u7684\u8bdd\uff09\u53ef\u4ee5\u5b58\u50a8\u5927\u4e8e\u5185\u5b58\u7684\u6570\u636e\uff0c\u8fd9\u662f\u56e0\u4e3a InnoDB \u662f\u57fa\u4e8e B-Tree \u7684\u5b58\u50a8\u5f15\u64ce\u3002B-tree \u5b58\u50a8\u5f15\u64ce\u548c LSM \u5b58\u50a8\u5f15\u64ce\u90fd\u53ef\u4ee5\u5b58\u50a8\u5927\u4e8e\u5185\u5b58\u7684\u6570\u636e\u91cf\u3002
\n\u5de5\u7a0b\u65b9\u9762\uff1aZooKeeper \u7684\u8bbe\u8ba1\u76ee\u6807\u662f\u4e3a\u534f\u540c\u670d\u52a1\u63d0\u4f9b\u6570\u636e\u5b58\u50a8\uff0c\u6570\u636e\u7684\u9ad8\u53ef\u7528\u6027\u548c\u6027\u80fd\u662f\u6700\u91cd\u8981\u7684\u7cfb\u7edf\u6307\u6807\uff0c\u5904\u7406\u5927\u6570\u91cf\u4e0d\u662f ZooKeeper \u7684\u9996\u8981\u76ee\u6807\u3002\u56e0\u6b64\uff0cZooKeeper \u4e0d\u4f1a\u5bf9\u5927\u6570\u91cf\u5b58\u50a8\u505a\u592a\u591a\u5de5\u7a0b\u4e0a\u7684\u4f18\u5316\u3002<\/p>\n

\u8981\u4f7f\u7528 ZooKeeper \u670d\u52a1\uff0c\u9996\u5148\u6211\u4eec\u7684\u5e94\u7528\u8981\u5f15\u5165 ZooKeeper \u7684\u5ba2\u6237\u7aef\u5e93\uff0c\u7136\u540e\u6211\u4eec\u5ba2\u6237\u7aef\u5e93\u548c ZooKeeper \u96c6\u7fa4\u6765\u8fdb\u884c\u7f51\u7edc\u901a\u4fe1\u6765\u4f7f\u7528 ZooKeeper \u7684\u670d\u52a1\uff0c\u672c\u8d28\u4e0a\u662f Client-Server \u7684\u67b6\u6784\uff0c\u6211\u4eec\u7684\u5e94\u7528\u4f5c\u4e3a\u4e00\u4e2a\u5ba2\u6237\u7aef\u6765\u8c03\u7528 ZooKeeper Server \u7aef\u7684\u670d\u52a1\u3002<\/p>\n

\"\"<\/p>\n

ZooKeeper\u670d\u52a1<\/strong><\/div>\n

ZooKeeper\u5c42\u6b21\u6570\u636e\u6a21\u578b<\/p>\n

\"\"<\/p>\n

ZooKeeper \u7684\u6570\u636e\u6a21\u578b\u662f\u5c42\u6b21\u6a21\u578b\u3002\u5c42\u6b21\u6a21\u578b\u5e38\u89c1\u4e8e\u6587\u4ef6\u7cfb\u7edf\u3002\u5c42\u6b21\u6a21\u578b\u548c key-value \u6a21\u578b\u662f\u4e24\u79cd\u4e3b\u6d41\u7684\u6570\u636e\u6a21\u578b\u3002ZooKeeper \u4f7f\u7528\u6587\u4ef6\u7cfb\u7edf\u6a21\u578b\u4e3b\u8981\u57fa\u4e8e\u4ee5\u4e0b\u4e24\u70b9\u8003\u8651\uff1a<\/p>\n

\u6587\u4ef6\u7cfb\u7edf\u7684\u6811\u5f62\u7ed3\u6784\u4fbf\u4e8e\u8868\u8fbe\u6570\u636e\u4e4b\u95f4\u7684\u5c42\u6b21\u5173\u7cfb\u3002
\n\u6587\u4ef6\u7cfb\u7edf\u7684\u6811\u5f62\u7ed3\u6784\u4fbf\u4e8e\u4e3a\u4e0d\u540c\u7684\u5e94\u7528\u5206\u914d\u72ec\u7acb\u7684\u547d\u540d\u7a7a\u95f4\uff08namespace\uff09\u3002<\/p>\n

ZooKeeper \u7684\u5c42\u6b21\u6a21\u578b\u79f0\u4f5c data tree\u3002Data tree \u7684\u6bcf\u4e2a\u8282\u70b9\u53eb\u505a znode\u3002\u4e0d\u540c\u4e8e\u6587\u4ef6\u7cfb\u7edf\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u53ef\u4ee5\u4fdd\u5b58\u6570\u636e\u3002\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u4e00\u4e2a\u7248\u672c(version)\uff0c\u7248\u672c\u4ece 0 \u5f00\u59cb\u8ba1\u6570\u3002<\/p>\n

ZooKeeper\u5c42\u6b21\u6570\u636e\u6a21\u578b\u5b9e\u4f8b<\/p>\n

\"\"<\/p>\n

\u5982\u4e0a\u56fe\u6240\u793a\u7684 data tree \u4e2d\u6709\u4e24\u4e2a\u5b50\u6811\uff0c\u4e00\u4e2a\u7528\u4e8e\u5e94\u7528 1\uff08\/app1\uff09\u548c\u53e6\u4e00\u4e2a\u7528\u4e8e\u5e94\u7528 2\uff08\/app2\uff09\u3002<\/p>\n

\u5e94\u7528 1 \u7684\u5b50\u6811\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u7ec4\u6210\u5458\u534f\u8bae\uff1a\u6bcf\u4e2a\u5ba2\u6237\u7aef\u8fdb\u7a0b pi \u521b\u5efa\u4e00\u4e2a znode p_i \u5728 \/app1 \u4e0b\uff0c\u53ea\u8981 \/app1\/p_i \u5b58\u5728\u5c31\u4ee3\u8868\u8fdb\u7a0b pi \u5728\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n

ZooKeeper \u5bf9\u5916\u63d0\u4f9b\u4e00\u4e2a\u7528\u6765\u8bbf\u95ee data tree\u7684\u7b80\u5316\u6587\u4ef6\u7cfb\u7edf API\uff1a<\/p>\n

\u4f7f\u7528 UNIX \u98ce\u683c\u7684\u8def\u5f84\u540d\u6765\u5b9a\u4f4d znode,\u4f8b\u5982 \/A\/X \u8868\u793a znode A \u7684\u5b50\u8282\u70b9 X\u3002
\nznode \u7684\u6570\u636e\u53ea\u652f\u6301\u5168\u91cf\u5199\u5165\u548c\u8bfb\u53d6\uff0c\u6ca1\u6709\u50cf\u901a\u7528\u6587\u4ef6\u7cfb\u7edf\u90a3\u6837\u652f\u6301\u90e8\u5206\u5199\u5165\u548c\u8bfb\u53d6\u3002
\ndata tree \u7684\u6240\u6709 API \u90fd\u662f wait-free \u7684\uff0c\u6b63\u5728\u6267\u884c\u4e2d\u7684 API \u8c03\u7528\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6 API \u7684\u5b8c\u6210\u3002
\ndata tree \u7684 API\u90fd\u662f\u5bf9\u6587\u4ef6\u7cfb\u7edf\u7684 wait-free \u64cd\u4f5c\uff0c\u4e0d\u76f4\u63a5\u63d0\u4f9b\u9501\u8fd9\u6837\u7684\u5206\u5e03\u5f0f\u534f\u540c\u673a\u5236\u3002\u4f46\u662f data tree \u7684 API \u975e\u5e38\u5f3a\u5927\uff0c\u53ef\u4ee5\u7528\u6765\u5b9e\u73b0\u591a\u79cd\u5206\u5e03\u5f0f\u534f\u540c\u673a\u5236\u3002<\/p>\n

\u4e00\u4e2a znode \u53ef\u4ee5\u662f\u6301\u4e45\u6027\u7684\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e34\u65f6\u6027\u7684\uff0cznode \u8282\u70b9\u4e5f\u53ef\u4ee5\u662f\u987a\u5e8f\u6027\u7684\u3002\u6bcf\u4e00\u4e2a\u987a\u5e8f\u6027\u7684 znode \u5173\u8054\u4e00\u4e2a\u552f\u4e00\u7684\u5355\u8c03\u9012\u589e\u6574\u6570\uff0c\u56e0\u6b64 ZooKeeper \u4e3b\u8981\u6709\u4ee5\u4e0b 4 \u79cd znode\uff1a<\/p>\n

<\/div>\n

\u6301\u4e45\u6027\u7684 znode (PERSISTENT): ZooKeeper \u5b95\u673a\uff0c\u6216\u8005 client \u5b95\u673a\uff0c\u8fd9\u4e2a znode \u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u4f1a\u4e22\u5931\u3002
\n\u4e34\u65f6\u6027\u7684 znode (EPHEMERAL): ZooKeeper \u5b95\u673a\u4e86\uff0c\u6216\u8005 client \u5728\u6307\u5b9a\u7684 timeout \u65f6\u95f4\u5185\u6ca1\u6709\u8fde\u63a5 server\uff0c\u90fd\u4f1a\u88ab\u8ba4\u4e3a\u4e22\u5931\u3002
\n\u6301\u4e45\u987a\u5e8f\u6027\u7684 znode (PERSISTENT_SEQUENTIAL): znode \u9664\u4e86\u5177\u5907\u6301\u4e45\u6027 znode \u7684\u7279\u70b9\u4e4b\u5916\uff0cznode \u7684\u540d\u5b57\u5177\u5907\u987a\u5e8f\u6027\u3002
\n\u4e34\u65f6\u987a\u5e8f\u6027\u7684 znode (EPHEMERAL_SEQUENTIAL): znode \u9664\u4e86\u5177\u5907\u4e34\u65f6\u6027 znode \u7684\u7279\u70b9\u4e4b\u5916\uff0cznode \u7684\u540d\u5b57\u5177\u5907\u987a\u5e8f\u6027\u3002<\/p>\n

\u5230\u00a0https:\/\/archive.apache.org\/dist\/zookeeper\/stable\/<\/a>\u00a0\u4e0b\u8f7d ZooKeeper\uff0c\u76ee\u524d\u7684\u6700\u65b0\u7248\u662f 3.5.6\u3002<\/p>\n

\"\"<\/p>\n

\u5b89\u88c5ZooKeeper<\/p>\n

\u628a apache-zookeeper-3.5.6-bin.tar.gz \u89e3\u538b\u5230\u4e00\u4e2a\u672c\u5730\u76ee\u5f55 (\u76ee\u5f55\u540d\u6700\u597d\u4e0d\u8981\u5305\u542b\u7a7a\u683c\u548c\u4e2d\u6587)\u3002\u6211\u4f7f\u7528 \/usr\/local \u76ee\u5f55\u3002<\/p>\n

tar -zxvf apache-zookeeper-3.5.6-bin.tar.gz<\/p>\n

\u628a conf \u76ee\u5f55\u4e0b\u7684 zoo_sample.cfg \u91cd\u547d\u540d\u4e3a zoo.cfg\uff0c\u7136\u540e\u4fee\u6539\u914d\u7f6e\u3002<\/p>\n

# \u5fc3\u8df3\u68c0\u67e5\u7684\u65f6\u95f4 2\u79d2\r\ntickTime=2000\r\n# \u521d\u59cb\u5316\u65f6 \u8fde\u63a5\u5230\u670d\u52a1\u5668\u7aef\u7684\u95f4\u9694\u6b21\u6570\uff0c\u603b\u65f6\u95f410*2=20\u79d2\r\ninitLimit=10\r\n# ZK Leader \u548cfollower \u4e4b\u95f4\u901a\u8baf\u7684\u6b21\u6570\uff0c\u603b\u65f6\u95f45*2=10\u79d2\r\nsyncLimit=5\r\n# \u5b58\u50a8\u5185\u5b58\u4e2d\u6570\u636e\u5feb\u7167\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u4e0d\u8bbe\u7f6e\u53c2\u6570\uff0c\u66f4\u65b0\u4e8b\u52a1\u65e5\u5fd7\u5c06\u88ab\u5b58\u50a8\u5230\u9ed8\u8ba4\u4f4d\u7f6e\u3002\r\ndataDir=\/data\/zookeeper\r\n# ZK \u670d\u52a1\u5668\u7aef\u7684\u76d1\u542c\u7aef\u53e3\r\nclientPort=2181\r\n<\/pre>\n

\u914d\u7f6e\u4ee5\u4e0b\u73af\u5883\u53d8\u91cf vim \/etc\/profile \uff1a<\/p>\n

export ZOOKEEPER_HOME=\/usr\/local\/apache-zookeeper-3.5.6-bin\r\nexport PATH=$PATH:$ZOOKEEPER_HOME\/bin:$ZOOKEEPER_HOME\/conf\r\n<\/pre>\n

\u518d\u5b89\u88c5\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u5c31\u53ef\u4ee5\u542f\u52a8 Zookeeper\uff0c\u4f7f\u7528 zkServer.sh start \u542f\u52a8 ZooKeeper \u670d\u52a1\uff1a<\/p>\n

[root@wupx apache-zookeeper-3.5.6-bin]# zkServer.sh start\r\n\/usr\/bin\/java\r\nZooKeeper JMX enabled by default\r\nUsing config: \/usr\/local\/apache-zookeeper-3.5.6-bin\/bin\/..\/conf\/zoo.cfg\r\nStarting zookeeper ... STARTED\r\n<\/pre>\n

\u68c0\u67e5 ZooKeeper \u65e5\u5fd7\u662f\u5426\u6709\u51fa\u9519\u4fe1\u606f\uff1a<\/p>\n

[root@wupx apache-zookeeper-3.5.6-bin]# cd logs\/\r\n[root@wupx logs]# grep -E -i \"((exception)|(error))\" *\r\n<\/pre>\n

\u56e0\u4e3a\u8fd4\u56de\u6ca1\u6709\u7ed3\u679c\uff0c\u8bf4\u660e\u6ca1\u6709\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n

\u68c0\u67e5 ZooKeeper \u6570\u636e\u6587\u4ef6\uff0c\u8fd9\u91cc\u5b58\u653e\u7684 ZooKeeper \u7684\u4e8b\u52a1\u65e5\u5fd7\u6587\u4ef6\u548c\u5feb\u7167\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n

[root@wupx zookeeper]# cd \/data\/zookeeper\/\r\n[root@wupx zookeeper]# tree\r\n.\r\n\u251c\u2500\u2500 version-2\r\n\u2502\u00a0 \u2514\u2500\u2500 snapshot.0\r\n\u2514\u2500\u2500 zookeeper_server.pid\r\n1 directory, 2 files\r\n<\/pre>\n

\u56e0\u4e3a\u73b0\u5728\u8fd8\u6ca1\u6709\u8fd0\u884c\u4efb\u4f55 ZooKeeper \u547d\u4ee4\uff0c\u6240\u4ee5\u8fd8\u6ca1\u6709\u4e8b\u52a1\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n

\u6700\u540e\u4f1a\u68c0\u67e5 ZooKeeper \u662f\u5426\u5728 2181 \u7aef\u53e3\u4e0a\u76d1\u542c\u3002<\/p>\n

netstat -an | ag 2181\r\n<\/pre>\n

\u6267\u884c\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 ZooKeeper \u5df2\u7ecf\u5728 2181 \u8fd9\u4e2a\u7aef\u53e3\u4e0a\u76d1\u542c\u4e86\u3002<\/p>\n

\u4e0b\u9762\u6211\u4eec\u6f14\u793a\u4e0b\u5982\u4f55\u4f7f\u7528 zkCli\uff1a<\/p>\n

\u5728\u6267\u884c zkCli.sh \u547d\u4ee4\u540e\uff0c\u4f1a\u51fa\u73b0\u5f88\u591a\u6d88\u606f\uff0c\u8fd9\u4e9b\u6d88\u606f\u8bc1\u660e\u6211\u4eec\u7684 zkCli \u548c ZooKeeper \u7684\u8282\u70b9\u5efa\u7acb\u4e86\u6709\u6548\u8fde\u63a5\u3002<\/p>\n

2019-12-22 10:38:36,684 [myid:localhost:2181] - INFO\u00a0 [main-SendThread(localhost:2181):ClientCnxn$SendThread@959] - Socket connection established, initiating session, client: \/127.0.0.1:54038, server: localhost\/127.0.0.1:2181\r\n<\/pre>\n

\u4f7f\u7528 ls -R \/ \u53ef\u4ee5\u9012\u5f52\u67e5\u627e ZooKeeper \u7684 znode \u8282\u70b9\uff0c\u4f7f\u7528 create \/znode_name \u53ef\u4ee5\u521b\u5efa znode \u8282\u70b9\uff0c\u5177\u4f53\u6f14\u793a\u5982\u4e0b\uff1a<\/p>\n

# \u4f7f\u7528 ls -R \u53ef\u4ee5\u9012\u5f52\u67e5\u627e ZooKeeper \u7684 znode \u8282\u70b9\r\n[zk: localhost:2181(CONNECTED) 0] ls -R \/\r\n\/\r\n\/zookeeper\r\n\/zookeeper\/config\r\n\/zookeeper\/quota\r\n# \u521b\u5efa znode \/app1\r\n[zk: localhost:2181(CONNECTED) 1] create \/app1\r\nCreated \/app1\r\n[zk: localhost:2181(CONNECTED) 2] create \/app2\r\nCreated \/app2\r\n[zk: localhost:2181(CONNECTED) 3] create \/app1\/p_1 1\r\nCreated \/app1\/p_1\r\n[zk: localhost:2181(CONNECTED) 4] create \/app1\/p_2 2\r\nCreated \/app1\/p_2\r\n[zk: localhost:2181(CONNECTED) 5] create \/app1\/p_3 3\r\nCreated \/app1\/p_3\r\n[zk: localhost:2181(CONNECTED) 6] ls -R \/\r\n\/\r\n\/app1\r\n\/app2\r\n\/zookeeper\r\n\/app1\/p_1\r\n\/app1\/p_2\r\n\/app1\/p_3\r\n\/zookeeper\/config\r\n\/zookeeper\/quota\r\n<\/pre>\n

\u5206\u5e03\u5f0f\u9501\u8981\u6c42\u5982\u679c\u9501\u7684\u6301\u6709\u8005\u5b95\u4e86\uff0c\u9501\u53ef\u4ee5\u88ab\u91ca\u653e\u3002ZooKeeper \u7684 ephemeral \u8282\u70b9\u6070\u597d\u5177\u5907\u8fd9\u6837\u7684\u7279\u6027\u3002<\/p>\n

\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u6f14\u793a\u4e0b\uff0c\u9700\u8981\u5728\u4e24\u4e2a\u7ec8\u7aef\u4e0a\u5206\u522b\u542f\u52a8 zkCli\uff0c<\/p>\n

\u5728\u7ec8\u7aef 1 \u4e0a\uff1a<\/p>\n

\u6267\u884c zkCli.sh\uff0c\u518d\u6267\u884c create -e \/lock \u547d\u4ee4\uff0c\u6765\u5efa\u7acb\u4e34\u65f6 znode\uff0c\u52a0\u9501\u7684\u64cd\u4f5c\u5176\u5b9e\u5c31\u662f\u5efa\u7acb znode \u7684\u8fc7\u7a0b\uff0c\u6b64\u65f6\u7b2c\u4e00\u4e2a\u5ba2\u6237\u7aef\u52a0\u9501\u6210\u529f\u3002<\/p>\n

\u63a5\u4e0b\u6765\u5c1d\u8bd5\u5728\u7b2c\u4e8c\u4e2a\u5ba2\u6237\u7aef\u52a0\u9501\uff0c\u5728\u7ec8\u7aef 2 \u4e0a\uff1a<\/p>\n

\u6267\u884c zkCli.sh\uff0c\u518d\u6267\u884c create -e \/lock \u547d\u4ee4\uff0c\u4f1a\u53d1\u73b0\u63d0\u793a Node already exists: \/lock\uff0c\u63d0\u793a znode \u5df2\u5b58\u5728\uff0cznode \u5efa\u7acb\u5931\u8d25\uff0c\u56e0\u6b64\u52a0\u9501\u5931\u8d25\uff0c\u8fd9\u65f6\u5019\u6211\u4eec\u6765\u76d1\u63a7\u8fd9\u4e2a znode\uff0c\u4f7f\u7528 stat -w \/lock \u6765\u7b49\u5f85\u9501\u88ab\u91ca\u653e\u3002<\/p>\n

\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u9000\u51fa\u7b2c\u4e00\u4e2a\u5ba2\u6237\u7aef\uff0c\u5728\u7ec8\u7aef 1 \u4e0a\u6267\u884c quit \u547d\u4ee4\uff0c\u4f1a\u5728\u5ba2\u6237\u7aef 2 \u4e0a\u6536\u5230\u4e00\u6761 WATCHER \u4fe1\u606f\uff0c\u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n

WATCHER::\r\nWatchedEvent state:SyncConnected type:NodeDeleted path:\/lock\r\n<\/pre>\n

\u518d\u6536\u5230\u8fd9\u4e2a\u4e8b\u4ef6\u540e\u518d\u6b21\u5728\u5ba2\u6237\u7aef 2 \u4e0a\u6267\u884c\u52a0\u9501\uff0c\u6267\u884c create -e \/lock\uff0c\u4f1a\u663e\u793a\u521b\u5efa znode \u6210\u529f\uff0c\u5373\u52a0\u9501\u6210\u529f\u3002<\/p>\n

\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86 ZooKeeper \u7684\u5b89\u88c5\u914d\u7f6e\uff0cZooKeeper \u7684\u57fa\u672c\u6982\u5ff5\u548c zkCli \u7684\u4f7f\u7528\uff0c\u5e76\u7528 zkCli \u6765\u5b9e\u73b0\u4e00\u4e2a\u9501\uff0c\u4e3a\u540e\u9762\u66f4\u52a0\u6df1\u5165\u7684\u5b66\u4e60\u6253\u597d\u57fa\u7840\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

ZooKeeper \u6700\u65e9\u8d77\u6e90\u4e8e\u96c5\u864e\u7814\u7a76\u9662\u7684\u4e00\u4e2a\u7814\u7a76\u5c0f\u7ec4\u3002\u5728\u5f53\u65f6\uff0c\u7814\u7a76\u4eba\u5458\u53d1\u73b0\uff0c\u5728\u96c5\u864e\u5185\u90e8\u5f88\u591a\u5927\u578b\u7cfb\u7edf\u57fa\u672c\u90fd\u9700\u8981 […]<\/p>\n","protected":false},"author":362,"featured_media":129994,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-178168","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/178168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=178168"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/178168\/revisions"}],"predecessor-version":[{"id":180712,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/178168\/revisions\/180712"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/129994"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=178168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=178168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=178168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}