{"id":158809,"date":"2020-09-16T05:43:49","date_gmt":"2020-09-15T21:43:49","guid":{"rendered":"http:\/\/4563.org\/?p=158809"},"modified":"2020-09-16T05:43:49","modified_gmt":"2020-09-15T21:43:49","slug":"%e6%b1%82%e6%95%99-clickhouse-%e7%9a%84%e5%89%af%e6%9c%ac%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=158809","title":{"rendered":"\u6c42\u6559 clickhouse \u7684\u526f\u672c\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6c42\u6559 clickhouse \u7684\u526f\u672c\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liunaijie <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u90e8\u7f72 clickhouse \u7684\u96c6\u7fa4\u6a21\u5f0f\u65f6\uff0c\u60f3\u52a0\u51e0\u4e2a\u526f\u672c\u3002<br \/> \u4f46\u662f\u6839\u636e\u6559\u7a0b\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u6570\u636e\u4e0d\u4f1a\u540c\u6b65\u5230\u526f\u672c\u8282\u70b9\u4e0a\uff0c\u770b\u4e86\u597d\u591a\u6559\u7a0b\uff0c\u6587\u7ae0\u90fd\u662f\u8fd9\u6837\u7684\u914d\u7f6e\uff0c\u6240\u4ee5\u60f3\u8bf7\u6559\u4e00\u4e0b\u5728\u54ea\u91cc\u51fa\u4e86\u95ee\u9898\u3002<br \/> \u73af\u5883\uff1a\u672c\u5730 docker \u8d77\u4e86\u4e24\u4e2a clickhouse \u5b9e\u4f8b\uff0c1 \u4e2a zookeeper \u5b9e\u4f8b\u3002<br \/> \u4e3b\u8981\u914d\u7f6e\u6587\u4ef6\u4e3a\uff1a<\/p>\n<pre><code>    &lt;clickhouse_remote_servers&gt;         &lt;ckcluster_1_2&gt;             &lt;!--\u5206\u7247 1--&gt;             &lt;shard&gt;              &lt;internal_replication&gt;true&lt;\/internal_replication&gt;                 &lt;!--\u526f\u672c 1--&gt;                 &lt;replica&gt;                     &lt;host&gt;172.17.0.3&lt;\/host&gt;                     &lt;port&gt;9000&lt;\/port&gt;                 &lt;\/replica&gt;                 &lt;!--\u526f\u672c 2--&gt;                 &lt;replica&gt;                     &lt;host&gt;172.17.0.4&lt;\/host&gt;                     &lt;port&gt;9000&lt;\/port&gt;                 &lt;\/replica&gt;             &lt;\/shard&gt;         &lt;\/ckcluster_1_2&gt;     &lt;\/clickhouse_remote_servers&gt;      &lt;zookeeper-servers&gt;         &lt;node index=\"1\"&gt;             &lt;host&gt;172.17.0.2&lt;\/host&gt;             &lt;port&gt;2181&lt;\/port&gt;         &lt;\/node&gt;     &lt;\/zookeeper-servers&gt;          &lt;macros&gt;      &lt;shard&gt;01&lt;\/shard&gt;         &lt;replica&gt;172.17.0.3&lt;\/replica&gt; ##\u53e6\u4e00\u4e2a\u4e3a 172.17.0.4     &lt;\/macros&gt;      <\/code><\/pre>\n<p>\u8fd9\u4e2a\u914d\u7f6e\u53ef\u4ee5\u6267\u884c\u5206\u5e03\u5f0f DDL \u547d\u4ee4\uff0c\u4f8b\u5982\u4e0b\u9762\u8fd9\u4e2a\u8bed\u53e5\uff0c\u6267\u884c\u540e\u5728\u4e24\u4e2a\u8282\u70b9\u90fd\u80fd\u67e5\u5230\u8fd9\u5f20\u8868\u3002<\/p>\n<pre><code>CREATE DATABASE cluster_test ON CLUSTER ckcluster_1_2; CREATE TABLE cluster_test.user_local ON CLUSTER ckcluster_1_2 (  name String,  address Nullable(String),  age UInt8 ) ENGINE = ReplicatedMergeTree('\/clickhouse\/tables\/{shard}\/ckcluster_1_2\/user_local', '{replica}') PARTITION BY age ORDER BY tuple() SETTINGS index_granularity = 8192; <\/code><\/pre>\n<p>\u4f46\u662f\u5411\u8fd9\u4e2a\u8868\u63d2\u5165\u6570\u636e\uff0c\u6570\u636e\u5e76\u4e0d\u4f1a\u540c\u6b65\u5230\u53e6\u4e00\u4e2a\u8282\u70b9\u4e0a\uff0c\u8fd9\u4e2a\u95ee\u9898\u56f0\u6270\u4e86\u6211\u597d\u4e45\uff0c\u5982\u679c\u96c6\u7fa4\u4e4b\u95f4\u4e0d\u80fd\u540c\u6b65\uff0c\u4e3a\u4ec0\u4e48\u521b\u8868\u80fd\u540c\u6b65\u3002<\/p>\n<p>\u7136\u540e\u53c8\u521b\u5efa\u4e86\u4e00\u4e2a\u5206\u5e03\u5f0f\u8868<\/p>\n<pre><code>CREATE TABLE IF NOT EXISTS cluster_test.user_all ON CLUSTER ckcluster_1_2  AS cluster_test.user_local  ENGINE = Distributed(ckcluster_1_2, cluster_test, user_local, rand()); <\/code><\/pre>\n<p>\u8fd9\u4e2a\u8868\u4e5f\u53ef\u4ee5\u96c6\u7fa4\u540c\u6b65\uff0c\u4f46\u662f\u5411\u8fd9\u4e2a\u8868\u63d2\u5165\u6570\u636e\u8fd8\u662f\u540c\u6b65\u4e0d\u4e86\u3002<br \/> \u5341\u5206\u56f0\u60d1\uff0c\u5e0c\u671b\u6709\u5927\u4f6c\u80fd\u6307\u6559\u4e00\u4e0b\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u6559 clickhouse \u7684\u526f\u672c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/158809"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158809"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/158809\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158809"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}