页面树结构
转至元数据结尾
转至元数据起始

sSmartbi MPP 高速缓存库,列式数据库管理系统,用于抽取数据。

1、安装包说明

普通用户权限部署smartbimpp的安装介质,请联系Smartbi官方获取

smartbi-mpp.xxx.tar.gz安装包与RPM包方式部署有所不同,区别如下:

类别

tar.gz安装包

RPM安装包

安装权限要求

普通用户

root或sudo权限

部署目录路径

所有文件均在安装目录

系统中不同目录

启、停、重启

进入目录执行脚本

执行systemctl命令

安装、卸载操作

进入目录执行脚本

执行rpm命令

2、系统环境要求

组件

要求

操作系统

64位Linux操作系统

建议:

 Centos 7或以上

 RedHat 7以上

CPU

支持SSE 4.2指令集,建议8核或以上

内存

建议32G以上

硬盘

部署目录建议200G以上


注:查询CPU是否支持SSE 4.2指令集

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

3、系统环境配置(需要管理员权限)

配置系统环境需要root或sudo权限。

3.1 取消打开文件数限制

在/etc/security/limits.conf 文件的末尾加入以下内容(注意: * 不能省略):

* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072

在/etc/sysctl.conf中,添加以下内容:

fs.inotify.max_user_watches=524288
fs.inotify.max_user_instances=8192

  保存后,执行以下命令让设置生效

#  sudo sysctl -p /etc/sysctl.conf

3.2 防火墙配置

1、取消SELINUX

#临时关闭selinux

#  setenforce 0

#永久关闭Selinux,需要重启服务器生效

sed -i 's/=enforcing/=disabled/g'  /etc/selinux/config

2、关闭防火墙

1)CentOS 7.X/Redhat 7.X

#  systemctl stop firewalld
#  systemctl disable firewalld
#  systemctl status firewalld


3、开启防火墙

如果需要开启防火墙,则需要开放smartbi-mpp服务使用到的端口:

服务名

端口

说明

smartbi-mpp

8123

JDBC连接端口

开启端口参考如下:

#  firewall-cmd --permanent --add-port=8123/tcp
#  firewall-cmd --reload

4、部署smartbi-mpp

4.1 、准备安装smartbi-mpp

将smartbi-mpp-22.8.9.24.tar.gz安装包上传至服务器,并解压

注意

由于默认数据目录存放在安装包目录中,请确认目录空间充足,避免磁盘空间不足导致数据库异常

$ tar -zxvf smartbi-mpp-22.8.9.24-x86_64.tar.gz

解压后,目录结果如下:

目录说明:

install.sh:smartbi-mpp安装脚本

uninstall.sh:smartbi-mpp卸载脚本

packages:smartbi-mpp安装包文件

4.2、安装smartbi-mpp

1、进入smartbi-mpp-22.8.9.24目录,执行install.sh脚本

cd smartbi-mpp-22.8.9.24
./install.sh

如下图所示,表示安装完成,

安装过程中的信息,记录在smartbi-mpp-22.8.9.24/var/log/clickhouse-server/install.log文件中。

2、安装完成后,目录结构如下:

目录说明:

clickhouse-client、clickhouse-common-static、clickhouse-server:smartbi-mpp安装包程序

etc:smartbi-mpp配置文件存放目录

usr:smartbi-mpp执行文件存放目录

var:smartbi-mpp数据目录(var/lib/clickhouse)、运行状态(var/run)、日志文件(var/log)存放目录

clickhouse.sh:smartbi-mpp启动、停止、重启脚本

netstat:查看端口工具

5、运维操作

5.1、修改配置文件(可选)

配置文件存放路径:smartbi-mpp-22.8.9.24/etc/clickhouse-server/

配置文件说明:

  • SmartbiMPP配置文件:etc/clickhouse-server/config.xml
  • SmartbiMPP用户配置文件:etc/clickhouse-server/users.xml

5.1.1、config.xml配置文件

1、修改日志存放目录

修改日志目录时,需要给目录添加对应用户的权限,例如,test用户安装smartbi-mpp时,新的日志目录需要修改为test的权限,参考如下

chown -R test.test  <新日志目录>


2、修改默认监听端口

8123:JDBC驱动的连接端口,一般不建议修改

9000:clickhouse-client的连接端口,一般不建议修改


3、修改数据目录

数据存储目录用来存储smartbimpp的数据文件,可以设置其他目录用于存储SMARTBIMPP的数据文件,默认数据数据目录:smartbi-mpp-22.8.9.24/var/lib/clickhouse/


例如,test用户安装smartbi-mpp时,新的数据目录需要修改为test的权限,参考如下

chown -R test.test <新数据目录>     

修改以下配置


4、开启远程访问权限

默认监听本地地址,其他无法提供对外访问,可以开放远程访问

如果需要配置监听ipv4地址,则配置问<listen_host>0.0.0.0</listen_host>

如果需要配置监听ipv6地址,则配置问<listen_host>::</listen_host>

注意:ipv4地址和ipv6地址只能配置一个


5、修改内存配置

22.8版本的clickhouse,修改内存使用的配置文件在smartbi-mpp-22.8.9.24/etc/clickhouse-server/etc/clickhouse-server/config.xml

修改配置文件smartbi-mpp-22.8.9.24/etc/clickhouse-server/etc/clickhouse-server/config.xml

<max_server_memory_usage>0</max_server_memory_usage>

<max_server_memory_usage_to_ram_ratio>0.9</max_server_memory_usage_to_ram_ratio>

温馨提示

max_server_memory_usage默认值为0,表示不限制内存使用。跟config.xml文件的max_server_memory_usage_to_ram_ratio参数一起使用。默认最大内存是服务器的物理内存的90%。

max_server_memory_usage的配置值不能大于服务器物理内存乘以max_server_memory_usage_to_ram_ratio的值。

max_server_memory_usage的配置值也不能太小,否则可能导致无法执行sql查询

5.1.2、users.xml配置文件

温馨提示

密码不能使用特殊字符&、 小于号< 、大于号>

1、设置数据库密码

方法一:设置明文密码

方法二:设置加密密码

生成加密密码串

echo -n "manager" | sha256sum | tr -d '-'
#注意:manager替换成实际的密码

注意:明文密码和加密密码只能二选一

5.2、启动、停止、重启smartbi-mpp

进入部署目录,以下所有操作均在此目录进行

cd smartbi-mpp-22.8.9.24

1、启动smartbi-mpp

sh clickhouse.sh start

查看进程

ps -ef | grep  clickhouse

查看端口监听

./netstat -lntp | grep 8123

本地客户端登录数据库,示例如下,注意替换成实际的服务器地址

cd smartbi-mpp-22.8.9.24

usr/bin/clickhouse-client -h 10.10.35.133


如果有设置数据库的密码,则参考以下命令登录:

cd smartbi-mpp-22.8.9.24

usr/bin/clickhouse-client  --host 10.10.35.133 --port 9000  --user default --password manaer

#manager替换成实际密码


2、重启smartbi-mpp

sh clickhouse.sh restart


3、停止smartbi-mpp

sh clickhouse.sh stop


5.3、卸载smartbi-mpp

进入部署目录,以下所有操作均在此目录进行

cd smartbi-mpp-22.8.9.24

执行卸载脚本

注意:默认卸载不删除数据目录,但避免出现异常,卸载前请备份数据目录:smartbi-mpp-22.8.9.24/var/lib/clickhouse/

sh uninstall.sh

执行卸载脚本时,会提示备份数据目录,需要手工进行备份,卸载脚本不会自动备份数据目录,并需要输入 yes 才会执行卸载操作

卸载完成后,默认数据目录和日志文件目录不会删除,如果需要删除,请手动操作。


5.4、调试方法

有时可能会出现smartbi-mpp启动失败,但是又没有日志的情况,可以使用如下命令启动smartbi-mpp,在前端获取启动日志分析问题

$ cd smartbi-mpp-22.8.9.24
$ usr/bin/clickhouse-server --config-file etc/clickhouse-server/config.xml --pid-file  var/run/clickhouse-server/clickhouse-server.pid


5.5、配置开机启动服务

注意

需要管理员权限(root或sudo权限),才能配置服务的开机启动

下载开机启动配置文件clickhouse-server.service

使用nodepad++等文本编辑工具编辑开机启动配置文件

如上图所示,配置启动mpp服务的用户名和用户组名称。

mpp的启动命令,需要配置mpp部署的实际路径,并且需要写绝对路径名称。

配置完成后保存文件,并把修改后的文件复制到操作系统的/usr/lib/systemd/system/ 目录

然后以管路员权限执行以下命令

重新加载服务配置文件

# systemctl daemon-reload

启动smartbimpp

# systemctl start clickhouse-server

配置开机启动

# systemctl enable clickhouse-server

查看mpp的状态

# systemctl status clickhouse-server

5.6、smartbi连接高速缓存库

高速缓存库在Smartbi中的配置方法如下:

(1)启动服务器,在浏览器输入Smartbi地址,进行登录;

(2)输入用户名密码,登录平台;

(3)在“系统导航栏”选择 数据连接,在“资源目录区”的高速缓存库更多操作,选择 打开,或双击 高速缓存库;

(4)进入“高速缓存库”界面

(5)据实际使用的数据库,修改相应连接属性,连接属性详情请参见 各数据库的连接详情

(6)点击保存,保存配置。

详细说明请参考:高速缓存库


5.7、smartbi-mpp调优配置参考

安装完成后,如果需要进行相关的参数调优,可以参考以下示例进行配置

5.7.1 config.xml调优参考

调优配置项说明

配置项默认值建议值说明
leveltraceerror配置日志级别
size1000M100M配置日志文件大小
listen_host-0.0.0.0限制来源主机的请求
<listen_host>::</listen_host> :支持IPv6和IPv4网络
<listen_host>0.0.0.0</listen_host> :不支持IPV6网络
ifconfig 查看 是否有
inet6表示是否支持IPV6
keep_alive_timeout3300关闭连接之前等待传入请求的秒数, 默认为3秒
注:推荐300,解决大数据了插入时 broken write问题
max_concurrent_queries100300最大并发处理的请求数(包含 select,insert 等)
Maximum number of concurrent queries
query_log--配置存储数据库名,表名,分区字段,刷新频率和采集频率等相关信息
建议增加TTL 只保留30天之内数据,减少系统空间占用
1)query_log
2)trace_log
3)query_thread_log
4)query_views_log
5)part_log
<ttl>event_date + INTERVAL 30 DAY DELETE</ttl>
trace_log--
query_thread_log--
query_views_log--
part_log--
openSSL--SSL客户端/服务器配置
timezone-Asia/Shanghai时区配置
database_atomic_delay_before_drop_table_sec4800解决删除副本表立马重建会报错的问题
inactive_parts_to_throw_insert-0

当表中非活跃部分(未参与合并的部分)数量超过此值时,新插入操作会抛出异常

MergeTree引擎配置
<merge_tree>
  <inactive_parts_to_throw_insert>0</inactive_parts_to_throw_insert>
  <inactive_parts_to_delay_insert>0</inactive_parts_to_delay_insert>
  <non_replicated_deduplication_window>0</non_replicated_deduplication_window>
  <execute_merges_on_single_replica_time_threshold>0</execute_merges_on_single_replica_time_threshold>
  <try_fetch_recompressed_part_timeout>7200</try_fetch_recompressed_part_timeout>
  <replicated_fetches_http_connection_timeout>1</replicated_fetches_http_connection_timeout>
  <replicated_fetches_http_send_timeout>0</replicated_fetches_http_send_timeout>
  <replicated_fetches_http_receive_timeout>0</replicated_fetches_http_receive_timeout>
  <max_partitions_to_read>-1</max_partitions_to_read>
  <allow_nullable_key>FALSE</allow_nullable_key>
  <min_bytes_to_rebalance_partition_over_jbod>0</min_bytes_to_rebalance_partition_over_jbod>
  <min_marks_to_honor_max_concurrent_queries>0</min_marks_to_honor_max_concurrent_queries>
  <detach_old_local_parts_when_cloning_replica>TRUE</detach_old_local_parts_when_cloning_replica>
  <always_fetch_merged_part>TRUE</always_fetch_merged_part>
  <max_suspicious_broken_parts>10000</max_suspicious_broken_parts>
  <parts_to_throw_insert>300</parts_to_throw_insert>
  <parts_to_delay_insert>150</parts_to_delay_insert>
  <max_delay_to_insert>256</max_delay_to_insert>
  <max_parts_in_total>100000</max_parts_in_total>
  <replicated_deduplication_window>100</replicated_deduplication_window>
  <replicated_deduplication_window_seconds>604800</replicated_deduplication_window_seconds>
  <max_replicated_logs_to_keep>1000</max_replicated_logs_to_keep>
  <min_replicated_logs_to_keep>10</min_replicated_logs_to_keep>
  <prefer_fetch_merged_part_time_threshold>3600</prefer_fetch_merged_part_time_threshold>
  <prefer_fetch_merged_part_size_threshold>10737418240</prefer_fetch_merged_part_size_threshold>
  <max_files_to_modify_in_alter_columns>75</max_files_to_modify_in_alter_columns>
  <max_files_to_remove_in_alter_columns>50</max_files_to_remove_in_alter_columns>
  <replicated_max_ratio_of_wrong_parts>0.5</replicated_max_ratio_of_wrong_parts>
  <replicated_max_parallel_fetches_for_host>15</replicated_max_parallel_fetches_for_host>
  <replicated_can_become_leader>TRUE</replicated_can_become_leader>
  <zookeeper_session_expiration_check_period>1</zookeeper_session_expiration_check_period>
  <old_parts_lifetime>480</old_parts_lifetime>
  <max_bytes_to_merge_at_max_space_in_pool>161061273600</max_bytes_to_merge_at_max_space_in_pool>
  <max_bytes_to_merge_at_min_space_in_pool>1048576</max_bytes_to_merge_at_min_space_in_pool>
  <merge_max_block_size>8192</merge_max_block_size>
  <max_part_loading_threads>16</max_part_loading_threads>
</merge_tree>
inactive_parts_to_delay_insert-0

当表中非活跃部分数量超过此值时,新插入操作会被延迟

non_replicated_deduplication_window-0非复制表的去重窗口大小
execute_merges_on_single_replica_time_threshold-0

在单个副本上执行合并的时间阈值(秒),超过此值后会在其他副本上执行

try_fetch_recompressed_part_timeout-7200

尝试从其他副本获取重新压缩部分的超时时间(秒)

replicated_fetches_http_connection_timeout-1

副本间通过HTTP获取数据时的连接超时时间(秒)

replicated_fetches_http_send_timeout-0

副本间通过HTTP发送数据的超时时间(秒)

replicated_fetches_http_receive_timeout-0

副本间通过HTTP接收数据的超时时间(秒)

max_partitions_to_read--1

单次查询可读取的最大分区数 (默认-1=无限制)

allow_nullable_key-FALSE

是否允许主键或排序键使用Nullable类型

min_bytes_to_rebalance_partition_over_jbod-0

在JBOD(多磁盘)配置中,重新平衡分区所需的最小字节数

min_marks_to_honor_max_concurrent_queries-0

考虑最大并发查询限制所需的最小标记数

detach_old_local_parts_when_cloning_replica-TRUE

克隆副本时是否分离旧的本地部分

always_fetch_merged_part-TRUE

是否总是从其他副本获取合并后的部分

max_suspicious_broken_parts-10000

允许的最大可疑损坏部分数

parts_to_throw_insert-300

当表中未合并部分数量超过此值时,新插入操作会抛出异常

parts_to_delay_insert-150

当表中未合并部分数量超过此值时,新插入操作会被延迟

max_delay_to_insert-256

插入操作的最大延迟秒数

max_parts_in_total-100000

表中允许的最大分区数量上限

replicated_deduplication_window-100复制表去重窗口大
replicated_deduplication_window_seconds-604800复制表去重时间窗口(秒)
max_replicated_logs_to_keep-1000

保留的最大复制日志数

min_replicated_logs_to_keep-10

保留的最小复制日志数

prefer_fetch_merged_part_time_threshold-3600超过此时间阈值(秒)后,优先获取合并后的部分
prefer_fetch_merged_part_size_threshold-10737418240

超过此大小阈值后,优先获取合并后的部分

max_files_to_modify_in_alter_columns-75

ALTER COLUMN操作中允许修改的最大文件数

max_files_to_remove_in_alter_columns-50

ALTER COLUMN操作中允许删除的最大文件数

replicated_max_ratio_of_wrong_parts-0.5

允许错误部分的最大比例

replicated_max_parallel_fetches_for_host-15

从单个主机并行获取的最大数量

replicated_can_become_leader-TRUE

该副本是否可以成为leader

zookeeper_session_expiration_check_period-1

ZooKeeper会话过期检查周期(秒)

old_parts_lifetime-480旧部分保留时间(秒)
max_bytes_to_merge_at_max_space_in_pool-161061273600合并任务最大字节数(默认150G)
max_bytes_to_merge_at_min_space_in_pool-1048576合并任务最小字节数(默认1M)
merge_max_block_size-8192

合并操作时的最大块大小

max_part_loading_threads-16

加载部分的最大线程数

配置示例config.xml:调优的都配置示例在<!-- smartbi begin -->和<!-- smartbi end →之间

注意

调优参数的配置可以根据实际环境进行调整

<?xml version="1.0"?>
<clickhouse>
    <logger>
<!-- smartbi begin 日志级别从trace调整成error减少无用日志输出-->
        <level>error</level>
<!-- smartbi end  -->
        <log>/var/log/clickhouse-server/clickhouse-server.log</log>
        <errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<!-- smartbi begin 配置日志文件大小从1000M 修改成100M 防止日志过大无法下载和打开-->  
        <size>100M</size>
<!-- smartbi end  -->
        <count>10</count>
    </logger>
        <header>
            <name>Access-Control-Allow-Origin</name>
            <value>*</value>
        </header>
        <header>
            <name>Access-Control-Allow-Headers</name>
            <value>origin, x-requested-with</value>
        </header>
        <header>
            <name>Access-Control-Allow-Methods</name>
            <value>POST, GET, OPTIONS</value>
        </header>
        <header>
            <name>Access-Control-Max-Age</name>
            <value>86400</value>
        </header>
    <http_port>8123</http_port>
    <tcp_port>9000</tcp_port>
    <mysql_port>9004</mysql_port>
    <postgresql_port>9005</postgresql_port>
    <interserver_http_port>9009</interserver_http_port>
    <listen_host>0.0.0.0</listen_host>
    <max_connections>4096</max_connections>

<!-- smartbi begin 关闭连接之前等待传入请求的秒数, 默认为3秒,调整为300,解决大数据了插入时 broken write问题-->
    <keep_alive_timeout>3</keep_alive_timeout>
<!-- smartbi end  -->
    <grpc>
        <enable_ssl>false</enable_ssl>
        <ssl_cert_file>/path/to/ssl_cert_file</ssl_cert_file>
        <ssl_key_file>/path/to/ssl_key_file</ssl_key_file>
        <ssl_require_client_auth>false</ssl_require_client_auth>
        <ssl_ca_cert_file>/path/to/ssl_ca_cert_file</ssl_ca_cert_file>
        <transport_compression_type>none</transport_compression_type>
        <transport_compression_level>0</transport_compression_level>
        <max_send_message_size>-1</max_send_message_size>
        <max_receive_message_size>-1</max_receive_message_size>
        <verbose_logs>false</verbose_logs>
    </grpc>
    <openSSL>
        <server> 
            <certificateFile>/etc/clickhouse-server/server.crt</certificateFile>
            <privateKeyFile>/etc/clickhouse-server/server.key</privateKeyFile>
            <verificationMode>none</verificationMode>
            <loadDefaultCAFile>true</loadDefaultCAFile>
            <cacheSessions>true</cacheSessions>
            <disableProtocols>sslv2,sslv3</disableProtocols>
            <preferServerCiphers>true</preferServerCiphers>
        </server>
        <client>
            <loadDefaultCAFile>true</loadDefaultCAFile>
            <cacheSessions>true</cacheSessions>
            <disableProtocols>sslv2,sslv3</disableProtocols>
            <preferServerCiphers>true</preferServerCiphers>
            <invalidCertificateHandler>
                <name>RejectCertificateHandler</name>
            </invalidCertificateHandler>
        </client>
    </openSSL>

<!-- smartbi begin 最大并发处理的请求数(包含 select,insert 等),默认100 调整到300 可以根据机器性能和并发情况再调大-->
    <max_concurrent_queries>300</max_concurrent_queries>
<!-- smartbi end  -->

    <max_server_memory_usage>0</max_server_memory_usage>
    <max_thread_pool_size>10000</max_thread_pool_size>
    <max_server_memory_usage_to_ram_ratio>0.9</max_server_memory_usage_to_ram_ratio>
    <total_memory_profiler_step>4194304</total_memory_profiler_step>
    <total_memory_tracker_sample_probability>0</total_memory_tracker_sample_probability>
    <uncompressed_cache_size>8589934592</uncompressed_cache_size>
    <mark_cache_size>5368709120</mark_cache_size>
    <mmap_cache_size>1000</mmap_cache_size>
    <compiled_expression_cache_size>134217728</compiled_expression_cache_size>
    <compiled_expression_cache_elements_size>10000</compiled_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.xml</path>
        </users_xml>
        <local_directory>
            <path>/var/lib/clickhouse/access/</path>
        </local_directory>
    </user_directories>
    <default_profile>default</default_profile>
    <custom_settings_prefixes></custom_settings_prefixes>
    <default_database>default</default_database>
<!-- smartbi begin 配置时区-->
     <timezone>Asia/Shanghai</timezone>
<!-- smartbi end  -->  
<!-- smartbi begin 解决删除副本表立马重建会报错的问题 ,默认是480s,调整为0-->
    <database_atomic_delay_before_drop_table_sec>0</database_atomic_delay_before_drop_table_sec>
<!-- smartbi end  -->
    <mlock_executable>true</mlock_executable>
    <remap_executable>false</remap_executable>
    <![CDATA[
         Uncomment below in order to use JDBC table engine and function.

         To install and run JDBC bridge in background:
         * [Debian/Ubuntu]
           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 '<release>' | 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 '<release>' | 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>
    </remote_servers>

    <builtin_dictionaries_reload_interval>3600</builtin_dictionaries_reload_interval>
    <max_session_timeout>3600</max_session_timeout>
    <default_session_timeout>60</default_session_timeout>

    <query_log>
        <database>system</database>
        <table>query_log</table>
        <partition_by>toYYYYMM(event_date)</partition_by>
        <flush_interval_milliseconds>7500</flush_interval_milliseconds>
<!-- smartbi begin 建议增加TTL 只保留30天之内数据,减少系统空间占用-->
<ttl>event_date + INTERVAL 30 DAY DELETE</ttl>
<!-- smartbi end  -->
    </query_log>

    <trace_log>
        <database>system</database>
        <table>trace_log</table>
        <partition_by>toYYYYMM(event_date)</partition_by>
        <flush_interval_milliseconds>7500</flush_interval_milliseconds>
<!-- smartbi begin 建议增加TTL 只保留30天之内数据,减少系统空间占用-->
<ttl>event_date + INTERVAL 30 DAY DELETE</ttl>
<!-- smartbi end  -->
    </trace_log>

    <query_thread_log>
        <database>system</database>
        <table>query_thread_log</table>
        <partition_by>toYYYYMM(event_date)</partition_by>
        <flush_interval_milliseconds>7500</flush_interval_milliseconds>
<!-- smartbi begin 建议增加TTL 只保留30天之内数据,减少系统空间占用-->
<ttl>event_date + INTERVAL 30 DAY DELETE</ttl>
<!-- smartbi end  -->
    </query_thread_log>

    <query_views_log>
        <database>system</database>
        <table>query_views_log</table>
        <partition_by>toYYYYMM(event_date)</partition_by>
        <flush_interval_milliseconds>7500</flush_interval_milliseconds>
<!-- smartbi begin 建议增加TTL 只保留30天之内数据,减少系统空间占用-->
<ttl>event_date + INTERVAL 30 DAY DELETE</ttl>
<!-- smartbi end  -->
    </query_views_log>

    <part_log>
        <database>system</database>
        <table>part_log</table>
        <partition_by>toYYYYMM(event_date)</partition_by>
        <flush_interval_milliseconds>7500</flush_interval_milliseconds>
<!-- smartbi begin 建议增加TTL 只保留30天之内数据,减少系统空间占用-->
<ttl>event_date + INTERVAL 30 DAY DELETE</ttl>
<!-- smartbi end  -->
    </part_log>

    <metric_log>
        <database>system</database>
        <table>metric_log</table>
        <flush_interval_milliseconds>7500</flush_interval_milliseconds>
        <collect_interval_milliseconds>1000</collect_interval_milliseconds>
    </metric_log>
    <asynchronous_metric_log>
        <database>system</database>
        <table>asynchronous_metric_log</table>
        <flush_interval_milliseconds>7000</flush_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>system</database>
        <table>opentelemetry_span_log</table>
        <flush_interval_milliseconds>7500</flush_interval_milliseconds>
    </opentelemetry_span_log>

    <crash_log>
        <database>system</database>
        <table>crash_log</table>

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

    <session_log>
        <database>system</database>
        <table>session_log</table>

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

    <top_level_domains_lists>
    </top_level_domains_lists>
    <dictionaries_config>*_dictionary.xml</dictionaries_config>
    <user_defined_executable_functions_config>*_function.xml</user_defined_executable_functions_config>

    <encryption_codecs>
    </encryption_codecs>
    <distributed_ddl>
        <path>/clickhouse/task_queue/ddl</path>
    </distributed_ddl>

<!-- smartbi begin merge_tree调优配置-->
<merge_tree>
    <inactive_parts_to_throw_insert>0</inactive_parts_to_throw_insert>
    <inactive_parts_to_delay_insert>0</inactive_parts_to_delay_insert>
    <non_replicated_deduplication_window>0</non_replicated_deduplication_window>
    <execute_merges_on_single_replica_time_threshold>0</execute_merges_on_single_replica_time_threshold>
    <try_fetch_recompressed_part_timeout>7200</try_fetch_recompressed_part_timeout>
    <replicated_fetches_http_connection_timeout>1</replicated_fetches_http_connection_timeout>
    <replicated_fetches_http_send_timeout>0</replicated_fetches_http_send_timeout>
    <replicated_fetches_http_receive_timeout>0</replicated_fetches_http_receive_timeout>
    <max_partitions_to_read>-1</max_partitions_to_read>
    <allow_nullable_key>FALSE</allow_nullable_key>
    <min_bytes_to_rebalance_partition_over_jbod>0</min_bytes_to_rebalance_partition_over_jbod>
    <min_marks_to_honor_max_concurrent_queries>0</min_marks_to_honor_max_concurrent_queries>
    <detach_old_local_parts_when_cloning_replica>TRUE</detach_old_local_parts_when_cloning_replica>
    <always_fetch_merged_part>TRUE</always_fetch_merged_part>
    <max_suspicious_broken_parts>10000</max_suspicious_broken_parts>
    <parts_to_throw_insert>300</parts_to_throw_insert>
    <parts_to_delay_insert>150</parts_to_delay_insert>
    <max_delay_to_insert>256</max_delay_to_insert>
    <max_parts_in_total>100000</max_parts_in_total>
    <replicated_deduplication_window>100</replicated_deduplication_window>
    <replicated_deduplication_window_seconds>604800</replicated_deduplication_window_seconds>
    <max_replicated_logs_to_keep>1000</max_replicated_logs_to_keep>
    <min_replicated_logs_to_keep>10</min_replicated_logs_to_keep>
    <prefer_fetch_merged_part_time_threshold>3600</prefer_fetch_merged_part_time_threshold>
    <prefer_fetch_merged_part_size_threshold>10737418240</prefer_fetch_merged_part_size_threshold>
    <max_files_to_modify_in_alter_columns>75</max_files_to_modify_in_alter_columns>
    <max_files_to_remove_in_alter_columns>50</max_files_to_remove_in_alter_columns>
    <replicated_max_ratio_of_wrong_parts>0.5</replicated_max_ratio_of_wrong_parts>
    <replicated_max_parallel_fetches_for_host>15</replicated_max_parallel_fetches_for_host>
    <replicated_can_become_leader>TRUE</replicated_can_become_leader>
    <zookeeper_session_expiration_check_period>1</zookeeper_session_expiration_check_period>
    <old_parts_lifetime>480</old_parts_lifetime>
    <max_bytes_to_merge_at_max_space_in_pool>161061273600</max_bytes_to_merge_at_max_space_in_pool>
    <max_bytes_to_merge_at_min_space_in_pool>1048576</max_bytes_to_merge_at_min_space_in_pool>
    <merge_max_block_size>8192</merge_max_block_size>
    <max_part_loading_threads>16</max_part_loading_threads>
</merge_tree>
<!-- smartbi end  -->

    <graphite_rollup_example>
        <pattern>
            <regexp>click_cost</regexp>
            <function>any</function>
            <retention>
                <age>0</age>
                <precision>3600</precision>
            </retention>
            <retention>
                <age>86400</age>
                <precision>60</precision>
            </retention>
        </pattern>
        <default>
            <function>max</function>
            <retention>
                <age>0</age>
                <precision>60</precision>
            </retention>
            <retention>
                <age>3600</age>
                <precision>300</precision>
            </retention>
            <retention>
                <age>86400</age>
                <precision>3600</precision>
            </retention>
        </default>
    </graphite_rollup_example>

    <format_schema_path>/var/lib/clickhouse/format_schemas/</format_schema_path>
    <query_masking_rules>
        <rule>
            <name>hide encrypt/decrypt arguments</name>
            <regexp>((?:aes_)?(?:encrypt|decrypt)(?:_mysql)?)\s*\(\s*(?:'(?:\\'|.)+'|.*?)\s*\)</regexp>
            <replace>\1(???)</replace>
        </rule>
    </query_masking_rules>

    <send_crash_reports>
        <enabled>false</enabled>
        <anonymize>false</anonymize>
        <endpoint>https://6f33034cfe684dd7a3ab9875e57b1c8d@o388870.ingest.sentry.io/5226277</endpoint>
    </send_crash_reports>
</clickhouse>

5.7.2 user.xml调优参考

调优配置项说明

配置项默认值建议值说明
background_pool_size16 cpu 线程数的 2 倍后台线程池的大小
允许的前提下建议改成 cpu 线程数的 2 倍
background_schedule_pool_size 128 cpu 线程数的 2 倍执行后台任务(复制表、Kafka 流、DNS 缓存更新)的线程数
允许的前提下建议改成 cpu 线程数的 2 倍
background_distributed_schedule_pool_size16 cpu 线程数的 2 倍设置为分布式发送执行后台任务的线程数
允许的前提下建议改成 cpu 线程数的 2 倍
background_fetches_pool_size8 cpu 线程数的 2 倍将用于从后台 *MergeTree 引擎表的另一个副本获取数据部分的最大线程数
background_common_pool_size8 cpu 线程数的 2 倍将用于在后台对 *MergeTree 引擎表执行各种操作(主要是垃圾回收)的最大线程数
max_threads当前服务器CPU核数-设置单个查询所能使用的最大 cpu 个数
max_memory_usage0物理内存的*80%单次 Query 占用内存最大值,默认为0,表示不限制
该值可以设置的比较大,这样可以提升集群查询的上限,一般留操作系统20%。
max_bytes_before_external_group_by0max_memory_usage*50%分组最大内存,当 group 使用内存超过阈值后会刷新到磁盘进行,,默认为0,表示不限制
按照 max_memory_usage 的一半设置内存
max_bytes_before_external_sort0max_memory_usage*50%排序最大内存,默认是0表示不限制,但是如果内存不够时直接抛错,设置了该值 order by 可以正常完成,但是速度慢
按照 max_memory_usage 的一半设置内存
max_memory_usage_for_user00单个用户在运行查询时,限制使用的最大内存用量,默认值为0,即不做限制
max_partitions_per_insert_block1001000在单次INSERT写入的时候,限制创建的最大分区个数,默认值为100个
如果超出这个阈值数目,将会得到异常;
max_rows_to_group_by00在执行GROUP BY聚合查询的时候,限制去重后的聚合KEY的最大个数,默认值为0,即不做限制
  当超过阈值数量的时候,其处理方式由group_by_overflow_mode参数决定;
group_by_overflow_modethrowthrow当max_rows_to_group_by熔断规则触发的时候,有三种处理形式:
  throw抛出异常,此乃默认值;
  break立即停止查询,并返回当前部分的数据;
  any仅以当前已存在的聚合KEY,继续完成聚合查询;
max_query_size26214426214400sql语句最大长度,默认是256K
建议设置为25M
max_ast_elements5000010000000查询语法树中的最大元素数,默认值下为50000
建议设置为10000000
max_expanded_ast_elements5000010000000查询语法树中的最大元素数。默认值下为50000
建议设置为10000000
http_receive_timeout1803600接收超时时间,适量增大方式插入数据时出现 Broken pipe
http_send_timeout1803600发送超时时间,适量增大方式插入数据时出现 Broken pipe

配置示例user.xml:调优的都配置示例在<!-- smartbi begin -->和<!-- smartbi end →之间

注意

调优参数的配置可以根据实际环境进行调整

<?xml version="1.0"?>
<clickhouse>
    <profiles>
        <default>
        <!-- smartbi begin 数据接收和发送时间,默认180s,适量增大方式插入数据时出现 Broken pipe-->
        <http_send_timeout>3600</http_send_timeout>
        <http_receive_timeout>3600</http_receive_timeout>
        <max_query_size>26214400</max_query_size>
        <max_ast_elements>10000000</max_ast_elements>
        <max_expanded_ast_elements>10000000</max_expanded_ast_elements>        <!-- 其他user.xml调优参数添加在此处即可 -->
        <!-- smartbi end  →
            <load_balancing>random</load_balancing>
        </default>
        <readonly>
            <readonly>1</readonly>
        </readonly>
    </profiles>
    <users><!--用户配置-->
        <default> <!--用户名-->
            <password></password> <!--置登录密码 免密码登入,支持明文、SHA256加密和double_sha1加密三种形式-->
            <networks>
                <ip>::/0</ip>
            </networks>
            <profile>default</profile>
            <quota>default</quota>
        </default>
    </users>
    <quotas><!--限制资源被过度使用,当使用的资源数量达到阈值时,那么正在进行的操作会被自动中断-->
        <default><!--自定义名称,全局唯一-->
            <interval><!--配置时间间隔,每个时间内的资源消耗限制-->
                <duration>3600</duration><!--表示累积的时间周期,单位是秒-->
                <queries>0</queries><!--表示在周期内允许执行的查询次数,0表示不限制-->
                <errors>0</errors><!--表示在周期内允许发生异常的次数,0表示不限制-->
                <result_rows>0</result_rows> <!--表示在周期内允许查询返回的结果行数,0表示不限制-->
                <read_rows>0</read_rows><!--表示在周期内在分布式查询中,允许远端节点读取的数据行数,0表示不限制。-->
                <execution_time>0</execution_time><!--表示周期内允许执行的查询时间,单位是秒,0表示不限制。-->
            </interval>
        </default>
    </quotas>
</clickhouse>
  • 无标签