部署clickhouse cluster(基于docker+zookeeper)

#安装zookeeper
虽然不是必要的,但clickhouse官方建议使用zookeeper部署集群,原因是ck的复制是用zk实现的:

ZooKeeper is not a strict requirement: in some simple cases you can duplicate the data by writing it into all the replicas from your application code. This approach is not recommended, in this case ClickHouse won’t be able to guarantee data consistency on all replicas. This remains the responsibility of your application.
而且很重要的是,如果不安装zookeeper,那么副本表是无法实现的


1.准备三台机器(/etc/hosts):

192.168.11.100 ch100
192.168.11.101 ch101
192.168.11.102 ch102

2.下载zookeeper3.5.6
注意一定要下载带有bin的版本,否则会
【报错】
Starting Zookeeper Cluster. Error: Could not find or load main class org.apache.zookeeper.server.quorum.QuorumPeerMain

3.解压并修改配置文件,三机一致
目录:/apps/

tar -zxvf apache-zookeeper-3.5.6-bin.tar.gz
mkdir -p /apps/apache-zookeeper-3.5.6-bin/data/zookeeper && mkdir -p /apps/apache-zookeeper-3.5.6-bin/log/zookeeper
cp /apps/apache-zookeeper-3.5.6-bin/conf/zoo-sample.cnf  /apps/apache-zookeeper-3.5.6-bin/conf/zoo.cnf
vi /apps/apache-zookeeper-3.5.6-bin/conf/zoo.cnf

配置文件主要改两个地方:

dataDir=/apps/zookeeper-3.5.6/data/zookeeper
dataLogDir=/apps/zookeeper-3.5.6/log/zookeeper

server.1=ch100:2888:3888 #这里的.1 .2 .3实际上对应了后面要创建的myid
server.2=ch101:2888:3888
server.3=ch102:2888:3888

4.每台机器创建自己的myid文件
在刚刚配置文件中指定的dataDir目录下创建myid文件
vi /apps/zookeeper-3.5.6/data/zookeeper/myid
三台机器,分别写上数字1,2,3

5.三台机器按顺序启动zk:

 ./bin/zkServer.sh start

启动后,检查:

 ./bin/zkServer.sh status

会看到一个leader,两个follower:
follower
leader

如果这步出现错误:
Error contacting service. It is probably not running.
请检查防火墙:firewalld 或者 iptables

#docker安装clickhouse-server
单机安装在这篇文章中有讲述


1.先启动一个节点,目的是将config目录拷贝出来,clickhouse的默认配置目录为:/etc/clickhouse-server/

docker run -d --name clickhouse-server --ulimit nofile=262144:262144 -p 8123:8123 --volume=$HOME/clickhouse:/var/lib/clickhouse  yandex/clickhouse-server
docker cp clickhouse-server :/etc/clickhouse-server/ /etc/clickhouse-server/
  1. 编辑配置
    vi /etc/clickhouse-server/config.xml
    修改以下配置:
 <listen_host>::</listen_host>  -- 去掉注释

找到<remote_servers>标签末尾,添加<include_from>标签
<!-- If element has 'incl' attribute, then for it's value will be used corresponding substitution from another file.
         By default, path to file with substitutions is /etc/metrika.xml. It could be changed in config in 'include_from' element.
         Values for substitutions are specified in /yandex/name_of_substitution elements in that file.
      -->
<include_from>/etc/clickhouse-server/metrika.xml</include_from>
<!-- 修改时区-->
<timezone>Asia/Shanghai</timezone> 

然后增加metrika.xml:(注:这个配置只配置了分片,没有配置副本)
这个配置中,cluster_3s_1r就是集群的名字

<yandex>
 
    <!-- 集群配置 -->
    <clickhouse_remote_servers>
        <cluster_3s_1r>
 
            <!-- 数据分片1  -->
            <shard>
                <internal_replication>false</internal_replication>
                <replica>
                    <host>ch100</host>
                    <port>9000</port>
                    <user>default</user>
                    <password></password>
                </replica>
            </shard>
 
            <!-- 数据分片2  -->
            <shard>
                <internal_replication>false</internal_replication>
                <replica>
                    <host>ch101</host>
                    <port>9000</port>
                    <user>default</user>
                    
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值