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()
        );
    }
    
}
相关推荐
时时刻刻看着自己的心1 天前
clickhouse分布式表插入数据不用带ON CLUSTER
分布式·clickhouse
吹老师个人app编程教学2 天前
clickhouse-题库
clickhouse
fusugongzi2 天前
clickhouse一直重启,日志提示structure needs cleaning
clickhouse
arnold662 天前
深入探索 ClickHouse:性能优化之道
clickhouse·性能优化
孤独天狼3 天前
Clickhouse(Centos)
clickhouse
Favor_Yang4 天前
C# 连接ClickHouse 数据库
数据库·clickhouse·c#
fusugongzi5 天前
clickhouse优化记录
clickhouse
吹老师个人app编程教学5 天前
clickhouse-副本和分片
java·服务器·clickhouse
天地风雷水火山泽5 天前
二百七十九、ClickHouse——用Kettle对DWD层清洗数据进行增量补全
clickhouse
天地风雷水火山泽5 天前
二百八十、ClickHouse——用Kettle对DWD层补全的清洗数据进行记录
大数据·clickhouse·kettle