ClickHouse配置与使用

静态IP配置
shell 复制代码
# 修改网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-ens33
 
# 修改文件内容
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.18.128
NETMASK=255.255.255.0
GATEWAY=192.168.18.2
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=2c2371f1-ef29-4514-a568-c4904bd11130
DEVICE=ens33
ONBOOT=true
DNS1=114.114.114.114
 
# 重启网络
systemctl restart network

ClickHouse配置
shell 复制代码
cd /usr/local/src
wget https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/clickhouse-client-22.2.2.1-2.noarch.rpm
wget https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/clickhouse-common-static-22.2.2.1-2.x86_64.rpm
wget https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/clickhouse-common-static-dbg-22.2.2.1-2.x86_64.rpm
wget https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/clickhouse-server-22.2.2.1-2.noarch.rpm

yum -y localinstall *.rpm


sudo systemctl enable clickhouse-server
sudo systemctl start clickhouse-server
sudo systemctl status clickhouse-server


vim /etc/clickhouse-server/config.xml
<listen_host>::</listen_host>

# default@default
vim /etc/clickhouse-server/users.xml
<password>default</password>

sudo systemctl restart clickhouse-server

SpringBoot集成ClickHouse
example.sql
shell 复制代码
CREATE TABLE `default`.example (
    uuid VARCHAR(100)
) ENGINE = Log;
pom.xml
xml 复制代码
        <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-extension -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-extension</artifactId>
            <version>3.3.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc -->
        <dependency>
            <groupId>com.clickhouse</groupId>
            <artifactId>clickhouse-jdbc</artifactId>
            <version>0.6.0-patch4</version>
        </dependency>
        <dependency>
            <groupId>org.lz4</groupId>
            <artifactId>lz4-java</artifactId>
            <version>1.8.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.luben</groupId>
            <artifactId>zstd-jni</artifactId>
            <version>1.5.5-5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5 -->
        <dependency>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
            <version>5.3.1</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/com.baomidou/dynamic-datasource-spring-boot-starter -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
            <version>3.3.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.32</version>
            <scope>provided</scope>
        </dependency>
application.yml
yaml 复制代码
spring:
  application:
    name: Elastic-Batch

  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    dynamic:
      primary: clickhouse
      datasource:
        clickhouse:
          driver-class-name: com.clickhouse.jdbc.ClickHouseDriver
          url: jdbc:clickhouse://192.168.15.128:8123/default
          name: default
          password: default
        clickhouse-2:
          driver-class-name: com.clickhouse.jdbc.ClickHouseDriver
          url: jdbc:clickhouse://192.168.15.128:8123/default
          name: default
          password: default
Example.java
java 复制代码
@Data
@Builder
public class Example {
    private String uuid;
}
ExampleMapper.java
java 复制代码
@DS(value = "clickhouse")
@Mapper
public interface ExampleMapper extends BaseMapper<Example> {
}
Application.java
java 复制代码
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
    @Resource
    private ExampleMapper exampleMapper;
    
    @PostConstruct
    public void mock() {
    	exampleMapper.insert(
                Example.builder()
                        .uuid(UUID.randomUUID().toString().toUpperCase(Locale.ROOT).replace("-", ""))
                        .build()
        );
    }
    
}
相关推荐
爱上口袋的天空15 小时前
09 - Clickhouse的SQL操作
数据库·sql·clickhouse
爱上口袋的天空3 天前
06 - Clickhouse的表引擎
数据库·clickhouse
吹老师个人app编程教学4 天前
ClickHouse的介绍、安装、数据类型
数据库·clickhouse·oracle
有被蠢哭到4 天前
Python连接Mysql、Postgre、ClickHouse、Redis常用库及封装方法
redis·python·mysql·clickhouse·postgresql
genghongsheng4 天前
执行flink sql连接clickhouse库
数据库·clickhouse·flink
爱上口袋的天空5 天前
04 - Clickhouse-21.7.3.14-2单机版安装
linux·服务器·clickhouse
LanFengXuXue5 天前
Clickhouse集群新建用户、授权以及remote权限问题
数据库·clickhouse
期待着201313 天前
ClickHouse创建分布式表
数据库·clickhouse
昨天今天明天好多天13 天前
【ClickHouse】创建表
数据库·clickhouse·oracle
从未完美过14 天前
clickhouse自增id的处理
数据库·clickhouse