High-availability distributed clickhouse cluster construction

Introduce clickhouse stand-alone and high-availability distributed construction

    Docker stand-alone construction method

#使用yandex的服务端镜像
docker pull yandex/clickhouse-server
#使用yandex的客户端镜像
docker pull yandex/clickhouse-client

The Dockerfile of yandex/clickhosue-server is as follows, you can refer to the custom image construction

FROM ubuntu:16.04

ARG repository="deb http://repo.yandex.ru/clickhouse/deb/stable/ main/"
ARG version=\*

RUN apt-get update && \
    apt-get install -y apt-transport-https && \
    mkdir -p /etc/apt/sources.list.d && \
    echo $repository | tee /etc/apt/sources.list.d/clickhouse.list && \
    apt-get update && \
    apt-get install --allow-unauthenticated -y clickhouse-server-common=$version clickhouse-server-base=$version && \
    rm -rf /var/lib/apt/lists/* /var/cache/debconf && \
    apt-get clean

COPY docker_related_config.xml /etc/clickhouse-server/config.d/
RUN chown -R clickhouse /etc/clickhouse-server/

USER clickhouse
EXPOSE 9000 8123 9009
VOLUME /var/lib/clickhouse

ENV CLICKHOUSE_CONFIG /etc/clickhouse-server/config.xml

ENTRYPOINT exec /usr/bin/clickhouse-server --config=${CLICKHOUSE_CONFIG}

Run the clickhosue service mirror yandex/clickhouse-server

$ docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server

Run the clickhouse client mirror yandex/clickhouse-client

$ docker run -it --rm --link some-clickhouse-server:clickhouse-server yandex/clickhouse-client --host clickhouse-server

A visual connection tool DBeaver is recommended here  https://dbeaver.jkiss.org/download/

Can connect directly to clickhosue Username defaults to default

    High Availability Cluster Construction

        I am here to prepare three machine systems are ubuntu server 16.04

            192.168.43.225 yun0

            192.168.43.226 yun1

            192.168.43.227 yun2

    Install the clickhouse database on the machine (if you are a virtual machine, you can install one first, and then copy two)

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E0C56BD4    # optional
sudo apt-add-repository "deb http://repo.yandex.ru/clickhouse/deb/stable/ main/"
sudo apt-get update
sudo apt-get install clickhouse-server-common clickhouse-client -y

If the prompt does not have app-add-repository, you need to install the following two

apt-get install python-software-properties
apt-get install software-properties-common

After installation, configure the clickhouse cluster

configure /etc/clickhouse-server/config.xml

Between lines 60 and 70, there is a listening host (configured for remote connections)

Generally, just remove the following three lines of comments.

<listen_host>::</listen_host>                                            
<listen_host>::1</listen_host>                                           
<listen_host>127.0.0.1</listen_host>

At the same time, you can see such a comment in this xml file

<!-- If element has 'incl' attribute, then for it's value will be used corresponding substi
    tution from another file.
155          By default, path to file with substitutions is /etc/metrika.xml. It could be changed i
    n config in 'include_from' element.
156          Values for substitutions are specified in /yandex/name_of_substitution elements in tha
    t file.
157       -->

metrika.xml is the distributed configuration file

Create a new metrika.xml file in the etc directory

can be modified directly in the following example

<yandex>
<clickhouse_remote_servers>
    <perftest_3shards_1replicas>
        <shard>
             <internal_replication>true</internal_replication>
            <replica>
                <host>yun0</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <replica>
                <internal_replication>true</internal_replication>
                <host>yun1</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <internal_replication>true</internal_replication>
            <replica>
                <host>yun2</host>
                <port>9000</port>
            </replica>
        </shard>
    </perftest_3shards_1replicas>
</clickhouse_remote_servers>


<zookeeper-servers>
  <node index="1">
    <host>yun0</host>
    <port>2181</port>
  </node>

  <node index="2">
    <host>yun1</host>
    <port>2181</port>
  </node>
  <node index="3">
    <host>yun2</host>
    <port>2181</port>
  </node>
</zookeeper-servers>

<macros>
    <replica>yun0</replica>
</macros>


<networks>
   <ip>::/0</ip>
</networks>


<clickhouse_compression>
<case>
  <min_part_size>10000000000</min_part_size>
                                             
  <min_part_size_ratio>0.01</min_part_size_ratio>                                                                                                                                       
  <method>lz4</method>
</case>
</clickhouse_compression>

</yandex>
            

This configuration is mainly modified in three places 

1. Configure the node

<clickhouse_remote_servers>
    <perftest_3shards_1replicas>
        <shard>
             <internal_replication>true</internal_replication>
            <replica>
                <host>yun0</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <replica>
                <internal_replication>true</internal_replication>
                <host>yun1</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <internal_replication>true</internal_replication>
            <replica>
                <host>yun2</host>
                <port>9000</port>
            </replica>
        </shard>
    </perftest_3shards_1replicas>
</clickhouse_remote_servers>

2. Configure zookeeper 

<zookeeper-servers>
  <node index="1">
    <host>yun0</host>
    <port>2181</port>
  </node>

  <node index="2">
    <host>yun1</host>
    <port>2181</port>
  </node>
  <node index="3">
    <host>yun2</host>
    <port>2181</port>
  </node>
</zookeeper-servers>

3. The first two have nothing to say, the following note that each node fills in the ip of the current node

<macros>
    <replica>yun0</replica>
</macros>

The latter is to install jdk, zookeeper. These two will not be introduced.

Restart after installation Start zookerper, clickhouse-server service.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324416328&siteId=291194637