ClickHouse教程 — 第一章 ClickHouse单机版安装

ClickHouse教程 — 第一章 ClickHouse单机版安装

  • 1 版本区别
    • 1.0 重要提示
    • 1.1 clickhouse21.1.9.41以上版本
    • 1.2 clickhouse21.1.9.41以下版本
  • 2 clickhouse21.1.9.41以上版本
    • 2.1 下载
    • 2.2 解压安装
    • 2.3 启动
    • 2.4 clickhouse相关目录
    • 2.5 允许远程访问
  • 3 clickhouse21.1.9.41以下版本
    • 3.1 下载
    • 3.2 安装
    • 3.4 允许远程访问
    • 3.5 启动
    • 3.6 进入客户端
    • 3.7 卸载
  • 4 使用DBeaver连接Clickhouse

1 版本区别

1.0 重要提示

golang在使用 github.com/ClickHouse/clickhouse-go/v2 报错:

WARNING: version 21.3.19 of ClickHouse is not supported by this client
ClickHouse (clickhouse-standalone) server version 21.3.19 revision 54447 (timezone Asia/Shanghai)

经最终测试发现不是clickhouse版本的问题,而是clickhouse-go/v2具体版本导致的,所以只需要把 clickhouse-go/v2降级就行,安装 clickhouse 时按照 2 clickhouse21.1.9.41以上版本 操作。


降级前

module clickhouse_demo

go 1.19

require github.com/ClickHouse/clickhouse-go/v2 main

执行 go mod tidy 后导入的具体版本

module clickhouse_demo

go 1.19

require github.com/ClickHouse/clickhouse-go/v2 v2.4.1

降级后

module clickhouse_demo

go 1.19

require github.com/ClickHouse/clickhouse-go/v2 v2.2.0

1.1 clickhouse21.1.9.41以上版本

clickhouse-client-21.1.9.41以上版本的都是tgz格式的文件,属于最新版本的安装包。所以后续 2、3、4、5、6都是针对tgz格式的安装教程。但是golang在使用 github.com/ClickHouse/clickhouse-go/v2时会提示如下信息:

WARNING: version 21.3.19 of ClickHouse is not supported by this client
ClickHouse (clickhouse-standalone) server version 21.3.19 revision 54447 (timezone Asia/Shanghai)

1.2 clickhouse21.1.9.41以下版本

clickhouse-client-21.1.9.41以下版本的都是rpm格式的文件,属于旧版本的安装包。

2 clickhouse21.1.9.41以上版本

2.1 下载

官方下载地址:https://packages.clickhouse.com/tgz/stable
阿里云下载地址:https://mirrors.aliyun.com/clickhouse/tgz/stable

一共需要下载4个文件:

  1. clickhouse-client-21.3.19.1.tgz
  2. clickhouse-common-static-21.3.19.1.tgz
  3. clickhouse-common-static-dbg-21.3.19.1.tgz
  4. clickhouse-server-21.3.19.1.tgz

2.2 解压安装

将下载后的四个安装文件上传到服务器,这里是上传到linuxopt/下。

依次将这四个安装包解压,并且每解压一个,执行一下解压文件夹下的install下的doinst.sh脚本。


① clickhouse-common-static-21.3.19.1.tgz

tar -zxvf clickhouse-common-static-21.3.19.1.tgz

./clickhouse-common-static-21.3.19.1/install/doinst.sh

② clickhouse-common-static-dbg-21.3.19.1.tgz

tar -zxvf clickhouse-common-static-dbg-21.3.19.1.tgz

./clickhouse-common-static-dbg-21.3.19.1/install/doinst.sh

③ clickhouse-server-21.3.19.1.tgz
注意:在运行doinst.sh时,clickhouse会默认创建一个default的用户,让你设置密码,不设置密码可以按回车。

tar -zxvf clickhouse-server-21.3.19.1.tgz

./clickhouse-server-21.3.19.1/install/doinst.sh

④ clickhouse-client-21.3.19.1.tgz

tar -zxvf clickhouse-client-21.3.19.1.tgz

./clickhouse-client-21.3.19.1/install/doinst.sh

2.3 启动

#查看命令
clickhouse --help 
 
#启动
clickhouse start 

启动结果:

 chown --recursive clickhouse '/var/run/clickhouse-server/'
Will run su -s /bin/sh 'clickhouse' -c '/usr/bin/clickhouse-server --config-file /etc/clickhouse-server/config.xml --pid-file /var/run/clickhouse-server/clickhouse-server.pid --daemon'
Waiting for server to start
Waiting for server to start
Server started

连接clickhouse

clickhouse-client

连接结果:

ClickHouse client version 21.3.19.1 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.3.19 revision 54447.

2.4 clickhouse相关目录

#  命令目录
/usr/bin
ll |grep clickhouse
-------------------------------------------
# 配置文件目录
cd /etc/clickhouse-server/
-------------------------------------------
# 日志目录
cd /var/log/clickhouse-server/
-------------------------------------------
# 数据文件目录
cd /var/lib/clickhouse/
-------------------------------------------

2.5 允许远程访问

clickhouse 默认不允许远程访问,需要修改配置文件:

cd /etc/clickhouse-server/
 
vim config.xml

注意:只需要把 :: 这一个的注释放开即可。
放开后的配置:



<clickhouse>
    <logger>
        
        <level>tracelevel>
        <log>/var/log/clickhouse-server/clickhouse-server.loglog>
        <errorlog>/var/log/clickhouse-server/clickhouse-server.err.logerrorlog>
        
        <size>1000Msize>
        <count>10count>
         

        
        

        
        
    logger>

    
    
    

    
    

    
    <http_port>8123http_port>

    
    <tcp_port>9000tcp_port>

    
    <mysql_port>9004mysql_port>

    
    <postgresql_port>9005postgresql_port>

    
    

    
    

    
    

    
    <interserver_http_port>9009interserver_http_port>

    
    

    

    

    
    

    
    <listen_host>::listen_host>


    
    

    
    

    
    

    
    

    

    <max_connections>4096max_connections>

    
    <keep_alive_timeout>3keep_alive_timeout>

    
    
    <grpc>
        <enable_ssl>falseenable_ssl>

        
        <ssl_cert_file>/path/to/ssl_cert_filessl_cert_file>
        <ssl_key_file>/path/to/ssl_key_filessl_key_file>

        
        <ssl_require_client_auth>falsessl_require_client_auth>

        
        <ssl_ca_cert_file>/path/to/ssl_ca_cert_filessl_ca_cert_file>

        
        <transport_compression_type>nonetransport_compression_type>

        
        <transport_compression_level>0transport_compression_level>

        
        <max_send_message_size>-1max_send_message_size>
        <max_receive_message_size>-1max_receive_message_size>

        
        <verbose_logs>falseverbose_logs>
    grpc>

    
    <openSSL>
        <server> 
            
            <certificateFile>/etc/clickhouse-server/server.crtcertificateFile>
            <privateKeyFile>/etc/clickhouse-server/server.keyprivateKeyFile>
            
            
            <verificationMode>noneverificationMode>
            <loadDefaultCAFile>trueloadDefaultCAFile>
            <cacheSessions>truecacheSessions>
            <disableProtocols>sslv2,sslv3disableProtocols>
            <preferServerCiphers>truepreferServerCiphers>
        server>

        <client> 
            <loadDefaultCAFile>trueloadDefaultCAFile>
            <cacheSessions>truecacheSessions>
            <disableProtocols>sslv2,sslv3disableProtocols>
            <preferServerCiphers>truepreferServerCiphers>
            
            <invalidCertificateHandler>
                
                <name>RejectCertificateHandlername>
            invalidCertificateHandler>
        client>
    openSSL>

    
    

    
    <max_concurrent_queries>100max_concurrent_queries>

    
    <max_server_memory_usage>0max_server_memory_usage>

    

    <max_thread_pool_size>10000max_thread_pool_size>

    
    

    
    <max_server_memory_usage_to_ram_ratio>0.9max_server_memory_usage_to_ram_ratio>

    
    <total_memory_profiler_step>4194304total_memory_profiler_step>

    
    <total_memory_tracker_sample_probability>0total_memory_tracker_sample_probability>

    
    

    
    <uncompressed_cache_size>8589934592uncompressed_cache_size>

    
    <mark_cache_size>5368709120mark_cache_size>


    
    <mmap_cache_size>1000mmap_cache_size>

    
    <compiled_expression_cache_size>134217728compiled_expression_cache_size>

    
    <compiled_expression_cache_elements_size>10000compiled_expression_cache_elements_size>

    
    <path>/var/lib/clickhouse/path>

    
    <tmp_path>/var/lib/clickhouse/tmp/tmp_path>

    
    

    
    <user_files_path>/var/lib/clickhouse/user_files/user_files_path>

    
    <ldap_servers>
        
    ldap_servers>

    

    
    <user_directories>
        <users_xml>
            
            <path>users.xmlpath>
        users_xml>
        <local_directory>
            
            <path>/var/lib/clickhouse/access/path>
        local_directory>

        
    user_directories>

    
    <default_profile>defaultdefault_profile>

    
    <custom_settings_prefixes>custom_settings_prefixes>

    
    

    
    

    
    <default_database>defaultdefault_database>

    
    

    
    

    
    <mlock_executable>truemlock_executable>

    
    <remap_executable>falseremap_executable>

    ' | sed -e 's|.*>\(.*\)<.*|\1|')
           wget https://github.com/ClickHouse/clickhouse-jdbc-bridge/releases/download/v$PKG_VER/clickhouse-jdbc-bridge_$PKG_VER-1_all.deb
           apt install --no-install-recommends -f ./clickhouse-jdbc-bridge_$PKG_VER-1_all.deb
           clickhouse-jdbc-bridge &

         * [CentOS/RHEL]
           export MVN_URL=https://repo1.maven.org/maven2/ru/yandex/clickhouse/clickhouse-jdbc-bridge
           export PKG_VER=$(curl -sL $MVN_URL/maven-metadata.xml | grep '' | sed -e 's|.*>\(.*\)<.*|\1|')
           wget https://github.com/ClickHouse/clickhouse-jdbc-bridge/releases/download/v$PKG_VER/clickhouse-jdbc-bridge-$PKG_VER-1.noarch.rpm
           yum localinstall -y clickhouse-jdbc-bridge-$PKG_VER-1.noarch.rpm
           clickhouse-jdbc-bridge &

         Please refer to https://github.com/ClickHouse/clickhouse-jdbc-bridge#usage for more information.
    ]]>
    

    
    <remote_servers>
        
        <test_shard_localhost>
            
            

            <shard>
                
                
                
                
                <replica>
                    <host>localhosthost>
                    <port>9000port>
                    
                    
                replica>
            shard>
        test_shard_localhost>
        <test_cluster_one_shard_three_replicas_localhost>
            <shard>
                <internal_replication>falseinternal_replication>
                <replica>
                    <host>127.0.0.1host>
                    <port>9000port>
                replica>
                <replica>
                    <host>127.0.0.2host>
                    <port>9000port>
                replica>
                <replica>
                    <host>127.0.0.3host>
                    <port>9000port>
                replica>
            shard>
            
        test_cluster_one_shard_three_replicas_localhost>
        <test_cluster_two_shards_localhost>
             <shard>
                 <replica>
                     <host>localhosthost>
                     <port>9000port>
                 replica>
             shard>
             <shard>
                 <replica>
                     <host>localhosthost>
                     <port>9000port>
                 replica>
             shard>
        test_cluster_two_shards_localhost>
        <test_cluster_two_shards>
            <shard>
                <replica>
                    <host>127.0.0.1host>
                    <port>9000port>
                replica>
            shard>
            <shard>
                <replica>
                    <host>127.0.0.2host>
                    <port>9000port>
                replica>
            shard>
        test_cluster_two_shards>
        <test_cluster_two_shards_internal_replication>
            <shard>
                <internal_replication>trueinternal_replication>
                <replica>
                    <host>127.0.0.1host>
                    <port>9000port>
                replica>
            shard>
            <shard>
                <internal_replication>trueinternal_replication>
                <replica>
                    <host>127.0.0.2host>
                    <port>9000port>
                replica>
            shard>
        test_cluster_two_shards_internal_replication>
        <test_shard_localhost_secure>
            <shard>
                <replica>
                    <host>localhosthost>
                    <port>9440port>
                    <secure>1secure>
                replica>
            shard>
        test_shard_localhost_secure>
        <test_unavailable_shard>
            <shard>
                <replica>
                    <host>localhosthost>
                    <port>9000port>
                replica>
            shard>
            <shard>
                <replica>
                    <host>localhosthost>
                    <port>1port>
                replica>
            shard>
        test_unavailable_shard>
    remote_servers>

    
    
        

        
    

    

    

    

    
    


    
    <builtin_dictionaries_reload_interval>3600builtin_dictionaries_reload_interval>


    
    <max_session_timeout>3600max_session_timeout>

    
    <default_session_timeout>60default_session_timeout>

    
    
    

    
    
    

    
    <query_log>
        
        <database>systemdatabase>
        <table>query_logtable>
        
        <partition_by>toYYYYMM(event_date)partition_by>
        

        

        
        <flush_interval_milliseconds>7500flush_interval_milliseconds>
    query_log>

    
    <trace_log>
        <database>systemdatabase>
        <table>trace_logtable>

        <partition_by>toYYYYMM(event_date)partition_by>
        <flush_interval_milliseconds>7500flush_interval_milliseconds>
    trace_log>

    
    <query_thread_log>
        <database>systemdatabase>
        <table>query_thread_logtable>
        <partition_by>toYYYYMM(event_date)partition_by>
        <flush_interval_milliseconds>7500flush_interval_milliseconds>
    query_thread_log>

    
    <query_views_log>
        <database>systemdatabase>
        <table>query_views_logtable>
        <partition_by>toYYYYMM(event_date)partition_by>
        <flush_interval_milliseconds>7500flush_interval_milliseconds>
    query_views_log>

    
    <part_log>
        <database>systemdatabase>
        <table>part_logtable>
        <partition_by>toYYYYMM(event_date)partition_by>
        <flush_interval_milliseconds>7500flush_interval_milliseconds>
    part_log>

    

    
    <metric_log>
        <database>systemdatabase>
        <table>metric_logtable>
        <flush_interval_milliseconds>7500flush_interval_milliseconds>
        <collect_interval_milliseconds>1000collect_interval_milliseconds>
    metric_log>

    
    <asynchronous_metric_log>
        <database>systemdatabase>
        <table>asynchronous_metric_logtable>
        
        <flush_interval_milliseconds>7000flush_interval_milliseconds>
    asynchronous_metric_log>

    
    <opentelemetry_span_log>
        
        <engine>
            engine MergeTree
            partition by toYYYYMM(finish_date)
            order by (finish_date, finish_time_us, trace_id)
        engine>
        <database>systemdatabase>
        <table>opentelemetry_span_logtable>
        <flush_interval_milliseconds>7500flush_interval_milliseconds>
    opentelemetry_span_log>


    
    <crash_log>
        <database>systemdatabase>
        <table>crash_logtable>

        <partition_by />
        <flush_interval_milliseconds>1000flush_interval_milliseconds>
    crash_log>

    
    <session_log>
        <database>systemdatabase>
        <table>session_logtable>

        <partition_by>toYYYYMM(event_date)partition_by>
        <flush_interval_milliseconds>7500flush_interval_milliseconds>
    session_log>

    

    
    

    
    


    
    
    <top_level_domains_lists>
        
    top_level_domains_lists>

    
    <dictionaries_config>*_dictionary.xmldictionaries_config>

    
    <user_defined_executable_functions_config>*_function.xmluser_defined_executable_functions_config>

    
    

    
    <encryption_codecs>
        
            
            
            

            
            
            
            
            
            

            
            
            

            
            

        
    encryption_codecs>

    
    <distributed_ddl>
        
        <path>/clickhouse/task_queue/ddlpath>

        
        

        
        

        

        
        

        
        

        
        
    distributed_ddl>

    
    

    
    
    

    
    <graphite_rollup_example>
        <pattern>
            <regexp>click_costregexp>
            <function>anyfunction>
            <retention>
                <age>0age>
                <precision>3600precision>
            retention>
            <retention>
                <age>86400age>
                <precision>60precision>
            retention>
        pattern>
        <default>
            <function>maxfunction>
            <retention>
                <age>0age>
                <precision>60precision>
            retention>
            <retention>
                <age>3600age>
                <precision>300precision>
            retention>
            <retention>
                <age>86400age>
                <precision>3600precision>
            retention>
        default>
    graphite_rollup_example>

    
    <format_schema_path>/var/lib/clickhouse/format_schemas/format_schema_path>

    
    <query_masking_rules>
        <rule>
            <name>hide encrypt/decrypt argumentsname>
            <regexp>((?:aes_)?(?:encrypt|decrypt)(?:_mysql)?)\s*\(\s*(?:'(?:\\'|.)+'|.*?)\s*\)regexp>
            
            <replace>\1(???)replace>
        rule>
    query_masking_rules>

    

    <send_crash_reports>
        
        
        
        <enabled>falseenabled>
        
        <anonymize>falseanonymize>
        
        
        <endpoint>https://[email protected]/5226277endpoint>
    send_crash_reports>

    
    

    
    
clickhouse>

重启clickhouse

clickhouse restart

在浏览器输入服务器ip:8123验证一下,显示OK即可。
ClickHouse教程 — 第一章 ClickHouse单机版安装_第1张图片
如果访问不了,可能需要开放端口或关闭防火墙。

开放 http_port:8123、tcp_port:9000、mysql_port:9004、interserver_http_port:9009端口

firewall-cmd --zone=public --add-port=8123/tcp --permanent
firewall-cmd --zone=public --add-port=9000/tcp --permanent
firewall-cmd --zone=public --add-port=9004/tcp --permanent
firewall-cmd --zone=public --add-port=9009/tcp --permanent

重启防火墙:

firewall-cmd --reload

查看开放的端口:

firewall-cmd --list-port

关闭firewall:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

3 clickhouse21.1.9.41以下版本

3.1 下载

下载地址:https://packagecloud.io/Altinity/clickhouse

一共需要下载4个文件:

clickhouse-server-common-20.8.3.18-1.el7.x86_64.rpm
clickhouse-server-20.8.3.18-1.el7.x86_64.rpm
clickhouse-common-static-20.8.3.18-1.el7.x86_64.rpm
clickhouse-client-20.8.3.18-1.el7.x86_64.rpm
ClickHouse教程 — 第一章 ClickHouse单机版安装_第2张图片
注意:右上角有下载按钮。可以直接下载对应的rpm文件。
ClickHouse教程 — 第一章 ClickHouse单机版安装_第3张图片

3.2 安装

rpm -ivh clickhouse-common-static-20.8.3.18-1.el7.x86_64.rpm

rpm -ivh clickhouse-server-common-20.8.3.18-1.el7.x86_64.rpm

rpm -ivh clickhouse-server-20.8.3.18-1.el7.x86_64.rpm

rpm -ivh clickhouse-client-20.8.3.18-1.el7.x86_64.rpm

3.4 允许远程访问

2.5 允许远程访问

3.5 启动

service clickhouse-server start

3.6 进入客户端

clickhouse-client(未设置密码登录)

clickhouse-client --multiline --password(设置密码登录)

3.7 卸载

参考1:clickhouse下载与安装

4 使用DBeaver连接Clickhouse

DBeaver的安装:DBeaver下载安装与连接MySQL数据库

DBeaver连接Clickhouse:DBeaver连接Clickhouse
SQL—》选择ClickHouse
ClickHouse教程 — 第一章 ClickHouse单机版安装_第4张图片
第一次连接需要安装驱动,根据提示操作即可安装成功。
注意:修改url,用户名默认是default,密码未设置则不填写。

ClickHouse教程 — 第一章 ClickHouse单机版安装_第5张图片

你可能感兴趣的:(clickhouse,clickhouse)