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()
        );
    }
    
}
相关推荐
gengjianchun2 天前
clickhouse 安装配置
服务器·网络·clickhouse
东皋长歌2 天前
ClickHouse安装
clickhouse
大嘴吧Lucy2 天前
实战攻略 | ClickHouse优化之FINAL查询加速
数据库·mysql·clickhouse
东皋长歌2 天前
SpringBoot+ClickHouse集成
clickhouse·springboot
从未完美过2 天前
ClickHouse集成Mysql表引擎跨服务器读表说明
服务器·mysql·clickhouse
华为云开发者联盟4 天前
华为云开源时序数据库openGemini:使用列存引擎解决时序高基数问题
clickhouse·时序数据库·高基数·opengemini
偏振万花筒5 天前
【BUG分析】clickhouse表final成功,但存在数据未合并
clickhouse·bug
爱折腾的小码农5 天前
宝塔使用clickhouse踩坑
clickhouse
激流丶5 天前
【Clikhouse 探秘】ClickHouse 物化视图:加速大数据分析的新利器
java·clickhouse·数据挖掘·数据分析·物化视图
程序员阿明5 天前
clickhouse配置用户角色与权限
java·数据库·clickhouse