Clickhouse单机安装详解

一、安装环境

Clickhouse的环境需求官网也有介绍:

即,CH只支持Linux,且必须支持4.2 SSE指令。若是在其他环境中想要搭建CH,可以使用docker或者使用线上云服务。

System requirements for pre-built packages: Linux, x86_64 with SSE 4.2.

检测系统是否支持SSE4.2

grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

二、版本选择和下载

第一步:创建安装包下载的目录

mkdir -p /bigdata/software/clickhouse

第二步:获取最新的稳定版本,并下载安装包

export LATEST_VERSION=$(curl -s https://repo.clickhouse.tech/tgz/stable/ | \
    grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | sort -V -r | head -n 1)
curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-common-static-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-common-static-dbg-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-server-$LATEST_VERSION.tgz
curl -O https://repo.clickhouse.tech/tgz/stable/clickhouse-client-$LATEST_VERSION.tgz

三、安装

解压安装包,并安装

tar -xzvf clickhouse-common-static-$LATEST_VERSION.tgz
sudo clickhouse-common-static-$LATEST_VERSION/install/doinst.sh
​
tar -xzvf clickhouse-common-static-dbg-$LATEST_VERSION.tgz
sudo clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh
​
tar -xzvf clickhouse-server-$LATEST_VERSION.tgz
sudo clickhouse-server-$LATEST_VERSION/install/doinst.sh
​
tar -xzvf clickhouse-client-$LATEST_VERSION.tgz
sudo clickhouse-client-$LATEST_VERSION/install/doinst.sh

四、配置文件

CH的配置主要为config.xml、user.xml和metrika.xml这三个。

功能,config.xml的配置信息如下:

<?xml version="1.0"?>
<!-- CH的config是热部署的 -->
<yandex>
    <!-- 日志地址即日志信息配置 -->
    <logger>
        <level>trace</level>
        <log>/data/clickhouse_1/log/server.log</log>
        <errorlog>/data/clickhouse_1/log/error.log</errorlog>
        <size>1000M</size>
        <count>10</count>
    </logger>
    
    <!-- 配置是否发送崩溃信息给官方 -->
    <send_crash_reports>
        <enabled>false</enabled>
        <anonymize>false</anonymize>
        <endpoint>https://[email protected]/5226277</endpoint>
    </send_crash_reports>
​
    <!-- 端口配置 -->
    <http_port>8321</http_port>
    <tcp_port>9015</tcp_port>
    <interserver_http_port>9019</interserver_http_port>
    <listen_host>::</listen_host>
​
    <!-- 最大并发查询数 -->
    <max_concurrent_queries>16</max_concurrent_queries>
 
   <!-- 指定数据存储路径 -->
    <path>/data/clickhouse_1/data/clickhouse/</path>
    <tmp_path>/data/clickhouse_1/data/clickhouse/tmp/</tmp_path>
​
    <!-- user配置 -->
  <users_config>users.xml</users_config>
    <default_profile>default</default_profile>
 
   <!-- 默认设置配置文件,在参数user_config中指定 -->
    <default_profile>default</default_profile>
    <!-- 默认数据库 -->
    <default_database>default</default_database>
​
    <!-- 远程服务器,分布式表引擎和集群表功能使用的集群的配置 -->
    <remote_servers incl="clickhouse_remote_servers" />
​
    <distributed_ddl>
      <!-- 在ZooKeeper中与DDL查询队列的路径 -->
      <path>/clickhouse/task_queue/ddl</path>
    </distributed_ddl>
​
    <!-- zk启动 -->
    <zookeeper incl="zookeeper-servers" optional="true" />
    <!-- 启动macros,并指定地址 -->
    <macros incl="macros" optional="true" />
    <include_from>/opt/clickhouse-server_1/metrika.xml</include_from>
 
   <!-- 标记缓存的大小,用于MergeTree系列的表中。单位是B,共享服务器的缓存,并根据需要分配内存。缓存大小必须至少为5368709120 -->
    <mark_cache_size>5368709120</mark_cache_size>
</yandex>

user.xml,用于用户管理和资源分配,其配置信息如下:

<?xml version="1.0"?>
<yandex>
    <profiles>
        <!-- 读写用户配置 -->
        <default>
            <!-- 单查询最大内存使用 -->
            <max_memory_usage>10000000000</max_memory_usage>
            <!-- 是否使用未压缩格式存储缓存(一般不建议) -->
            <use_uncompressed_cache>0</use_uncompressed_cache>
            <!-- 分配模式下选择副本的方式 -->
            <load_balancing>random</load_balancing>
        </default>
​
        <!-- 只读用户配置 -->
        <readonly>
            <max_memory_usage>10000000000</max_memory_usage>
            <use_uncompressed_cache>0</use_uncompressed_cache>
            <load_balancing>random</load_balancing>
            <readonly>1</readonly>
        </readonly>
    </profiles>
​
    <!-- 用户和访问权限控制 -->
    <users>
        <!-- default为用户么,可以自己指定 -->
        <default>
            <!-- 密码可以用SHA256加密 -->
            <password_sha256_hex>967f3bf355dddfabfca1c9f5cab39352b2ec1cd0b05f9e1e6b8f629705fe7d6e</password_sha256_hex>
            <!-- 访问权限设置。
                 
                 任何地方都能读取:
                    <ip>::/0</ip>
​
                 只能从本地读取:
                    <ip>::1</ip>
                    <ip>127.0.0.1</ip>
​
                 可以用正则表达式去表示。
             -->
            <networks incl="networks" replace="replace">
                <ip>::/0</ip>
            </networks>
            <!-- profile 指定标签 -->
            <profile>default</profile>
            <!-- Quota 指定标签 -->
            <quota>default</quota>
        </default>
        <!-- 只读用户(个人创建) -->
        <ck>
            <password_sha256_hex>967f3bf355dddfabfca1c9f5cab39352b2ec1cd0b05f9e1e6b8f629705fe7d6e</password_sha256_hex>
            <networks incl="networks" replace="replace">
                <ip>::/0</ip>
            </networks>
            <profile>readonly</profile>
            <quota>default</quota>
        </ck>
    </users>
​
    <!-- 资源限额 -->
    <quotas>
        <!-- 资源限额的名字. -->
        <default>
            <!-- 用于限制一定时间间隔内的资源使用量 -->
            <interval>
                <!-- 时间间隔 -->
                <duration>3600</duration>
                <!-- 下面配置为无限制 -->
                <queries>0</queries>
                <errors>0</errors>
                <result_rows>0</result_rows>
                <read_rows>0</read_rows>
                <execution_time>0</execution_time>
            </interval>
        </default>
    </quotas>
</yandex>

metrika.xml,用于配置集群信息,其配置解释如下(本次安装不用修改该文件配置):

<?xml version="1.0"?>
<yandex>
<!-- 集群配置 -->
<clickhouse_remote_servers>
    <!-- 集群名称-->
    <ck_cluster>
        <shard>
            <!-- 建议一个台机器一个节点,避免资源争夺 -->
            <!-- 表示是否只将数据写入其中一个副本,默认为false,表示写入所有副本,在复制表的情况下可能会导致重复和不一致,所以这里一定要改为true。-->
            <internal_replication>false</internal_replication>
            <!-- 副本配置,ch没有主备之分 -->
            <replica>
                <host>ck-host1</host>
                <port>9000</port>
                <user>default</user>
                <password>******</password>
            </replica>
            <replica>
                <host>ck-host2</host>
                <port>9000</port>
                <user>default</user>
                <password>******</password>
            </replica>
        </shard>
        <shard>
            <internal_replication>false</internal_replication>
            <replica>
                <host>ck-host3</host>
                <port>9000</port>
                <user>default</user>
                <password>******</password>
            </replica>
            <replica>
                <host>ck-host4</host>
                <port>9000</port>
                <user>default</user>
                <password>******</password>
            </replica>
        </shard>
        <!-- ... -->
    </ck_cluster>
</clickhouse_remote_servers>
​
<!-- 本节点副本名称,配置后能方便后续创建复制表时不用指定zk路径 -->
<macros>
    <replica>ck1</replica>
</macros>
​
<!-- ZK配置  -->
<zookeeper-servers>
  <node index="1">
    <host>zk-host1</host>
    <port>2181</port>
  </node>
  <node index="2">
    <host>zk-host2</host>
    <port>2181</port>
  </node>
  <node index="3">
    <host>zk-host3</host>
    <port>2181</port>
  </node>
</zookeeper-servers>
​
<!-- 数据压缩算法配置  -->
<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>

五、启动并验证

启动CH的服务端:

sudo /etc/init.d/clickhouse-server start

登录CH​客户端:

本地登录:

clickhouse-client -u username --password pwd

远程登录:

clickhouse-client -h host --port port -u username --password pwd

 

猜你喜欢

转载自blog.csdn.net/sileiH/article/details/113404907