Clickhouse stand-alone installation details

1. Installation environment

Clickhouse's environmental requirements official website also introduces:

That is, CH only supports Linux and must support 4.2 SSE instructions. If you want to build CH in other environments, you can use docker or use online cloud services.

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

Check whether the system supports SSE4.2

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

2. Version selection and download

Step 1: Create a directory for downloading the installation package

mkdir -p /bigdata/software/clickhouse

Step 2: Obtain the latest stable version and download the installation package

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

Three, installation

Unzip the installation package and install

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

Fourth, the configuration file

The configuration of CH is mainly config.xml, user.xml and metrika.xml.

Function, the configuration information of config.xml is as follows:

<?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, used for user management and resource allocation, its configuration information is as follows:

<?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, used to configure cluster information, its configuration is explained as follows (this installation does not need to modify the file configuration):

<?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>

Five, start and verify

Start the server of CH:

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

Log in to CH​Client:

Log in locally:

clickhouse-client -u username --password pwd

Remote login:

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

 

 

Guess you like

Origin blog.csdn.net/sileiH/article/details/113404907