window安装clickhouse数据库

1、下载镜像

docker pull yandex/clickhouse-server
docker pull yandex/clickhouse-client

window环境安装clickhouse:参考:https://blog.csdn.net/wjw465150/article/details/127030481


docker run -d --name=single-clickhouse-server -p 8123:8123 --volume D:/clickhouse/data:/var/lib/clickhouse:rw --volume D:/clickhouse/conf:/etc/clickhouse-server:rw --volume D:/clickhouse/log:/var/log/clickhouse-server:rw yandex/clickhouse-server

还可以参考:

复制代码
docker run -d --name clickhouse-server --ulimit nofile=262144:262144 --volume=//E/clickhouse:/var/lib/clickhouse yandex/clickhouse-server

#启动容器
docker run -d --name ch-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server:22.3.11.12-alpine
# 复制文件到宿主机
docker cp ch-server:/etc/clickhouse-server E:/clickhouse-server
docker cp ch-server:/var/lib/clickhouse E:/clickhouse/data
#停止容器
docker stop ch-server
# 再次启动容器
docker run -d --name=single-ch-server -p 8123:8123 -p 9000:9000 -p 9009:9009 --ulimit nofile=262144:262144 -v E:/clickhouse/data:/var/lib/clickhouse:rw -v E:/clickhouse-server:/etc/clickhouse-server:rw clickhouse/clickhouse-server:22.3.11.12-alpine
复制代码

 

建表语句:

复制代码
create database sensor
CREATE TABLE vehicle_dev.vehicle_pass on cluster ck_cluster
(

    `plate_info` String,

    `plate_type` String,

    `plate_color` String,

    `vehicle_speed` UInt16,

    `vehicle_type` String,

    `vehicle_color` String,

    `vehicle_logo` String,

    `vehicle_model` String,

    `vehicle_state` String,

    `pass_time` DateTime DEFAULT now(),

    `cross_code` String,

    `lane_id` UInt8,

    `longitude` String,

    `latitude` String,

    `alarm_action` String,

    `pic_plate` String,

    `pic_vehicle` String,

    `pic_vehicle1` String,

    `pic_vehicle2` String,

    `create_date` DateTime DEFAULT now()
)
ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(pass_time)
ORDER BY (plate_info,cross_code)
SETTINGS index_granularity = 8192;


CREATE TABLE vehicle_dev.vehicle_pass_all on cluster ck_cluster
(

    `plate_info` String,

    `plate_type` String,

    `plate_color` String,

    `vehicle_speed` UInt16,

    `vehicle_type` String,

    `vehicle_color` String,

    `vehicle_logo` String,

    `vehicle_model` String,

    `vehicle_state` String,

    `pass_time` DateTime DEFAULT now(),

    `cross_code` String,

    `lane_id` UInt8,

    `longitude` String,

    `latitude` String,

    `alarm_action` String,

    `pic_plate` String,

    `pic_vehicle` String,

    `pic_vehicle1` String,

    `pic_vehicle2` String,

    `create_date` DateTime DEFAULT now()
)
ENGINE = Distributed('ck_cluster',
 'vehicle_dev',
 'vehicle_pass',
 rand());


 CREATE TABLE vehicle_dev.vehicle_pass_buffer on cluster ck_cluster
(

    `plate_info` String,

    `plate_type` String,

    `plate_color` String,

    `vehicle_speed` UInt16,

    `vehicle_type` String,

    `vehicle_color` String,

    `vehicle_logo` String,

    `vehicle_model` String,

    `vehicle_state` String,

    `pass_time` DateTime DEFAULT now(),

    `cross_code` String,

    `lane_id` UInt8,

    `longitude` String,

    `latitude` String,

    `alarm_action` String,

    `pic_plate` String,

    `pic_vehicle` String,

    `pic_vehicle1` String,

    `pic_vehicle2` String,

    `create_date` DateTime DEFAULT now()
)
ENGINE = Buffer('vehicle_dev',
 'vehicle_pass',
 16,
 10,
 100,
 1000,
 10000,
 1000000,
 10000000);





CREATE TABLE vehicle_dev.t_test on cluster ck_cluster
(

    `id` String,

    `name` String,

    `age` String

    `create_date` DateTime DEFAULT now()
)
ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(create_date)
ORDER BY (id)
SETTINGS index_granularity = 8192;
复制代码
复制代码
docker run -d --name clickhouse-server --ulimit nofile=262144:262144 --volume=//E/clickhouse:/var/lib/clickhouse yandex/clickhouse-server

#启动容器
docker run -d --name ch-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server:22.3.11.12-alpine
# 复制文件到宿主机
docker cp ch-server:/etc/clickhouse-server E:/clickhouse-server
docker cp ch-server:/var/lib/clickhouse E:/clickhouse/data
#停止容器
docker stop ch-server
# 再次启动容器
docker run -d --name=single-ch-server -p 8123:8123 -p 9000:9000 -p 9009:9009 --ulimit nofile=262144:262144 -v E:/clickhouse/data:/var/lib/clickhouse:rw -v E:/clickhouse-server:/etc/clickhouse-server:rw clickhouse/clickhouse-server:22.3.11.12-alpine
复制代码

 window的docker部署单机版clickhouse步骤:

1、

docker run -d --name=clickhouse-server --ulimit nofile=262144:262144 -p 8123:8123 -p 9009:9009 -p 9090:9000 yandex/clickhouse-server

然后clickhouse的服务就启动了,可以访问:http://localhost:8123/,看到一个“OK”,即代表clickhouse运行成功

默认的clickhouse启动后:

  • 用户名:default
  • 密码:<空>

修改配置

进入容器:

复制代码
docker exec -it clickhouse的容器ID /bin/sh
# 如:
# docker exec -it 082242cb73de0c3fccff9758c16d7e535055063d1d576dd70a1ea73b09c20208 /bin/sh

因为我们后续对文件的修改要使用vim,因此先安装一下,便于修改配置文件
如果权限不足,就执行如下命令
docker exec -u 0 -it 39e661716809 /bin/bash apt
-get update apt-get install vim -y
复制代码

1. 修改用户名密码

cd /etc/clickhouse-server
vim users.xml

从40+行左右就可以看到如下内容:

复制代码
<!-- Users and ACL. -->
    <users>
        <!-- If user name was not specified, 'default' user is used. -->
        <default>
            <!-- See also the files in users.d directory where the password can be overridden.

                 Password could be specified in plaintext or in SHA256 (in hex format).

                 If you want to specify password in plaintext (not recommended), place it in 'password' element.
..........
复制代码

新增用户的配置方法如下:

复制代码
<users>
    <新增的用户名>
        <password>这里是新增用户名,对应的密码</password>
        <networks incl="networks" replace="replace">
            <ip>::/0</ip>
        </networks>
        <profile>default</profile>
        <quota>default</quota>
    </新增的用户名>
</users>
复制代码

比如新建一个用户:

  • 用户名:test_user
  • 密码:test_password

则可以增加配置内容:

复制代码
<!-- Users and ACL. -->
<users>
    <test_user>
        <password>test_password</password>
        <networks incl="networks" replace="replace">
            <ip>::/0</ip>
        </networks>
        <profile>default</profile>
        <quota>default</quota>
    </test_user>
    
    <!-- If user name was not specified, 'default' user is used. -->
    <default> <!-- 看,这个是默认的用户名 default,它下面的password是空的,所以没有密码 -->
        .........
    </default>
</users>
复制代码

2、配置远程访问:

cd /etc/clickhouse-server
vi config.xml

查询修改:/listen_,即可定位到配置标签:

<!-- <listen_host>::</listen_host> -->

取消注释即可配置远程访问:

<listen_host>::</listen_host>

或者是注释掉,开启ipv4的访问

 <!-- Same for hosts without support for IPv6: -->
<listen_host>0.0.0.0</listen_host>

查看linux开发的端口:netstat -nltp | grep 18124

 记录离线安装dbeaver连接clickhouse的过程

参考:

单机版部署可以参考默认是没有密码的,可以参考设置密码:https://blog.csdn.net/weixin_35757704/article/details/127359948

命令:

创建库:

CREATE DATABASE db_001 ON CLUSTER default;

创建表:

复制代码
CREATE TABLE local_table ON CLUSTER default
(
    Year UInt16,
    Quarter UInt8,
    Month UInt8,
    DayofMonth UInt8,
    DayOfWeek UInt8,
    FlightDate Date,
    FlightNum String,
    Div5WheelsOff String,
    Div5TailNum String
)ENGINE = MergeTree()
 PARTITION BY toYYYYMM(FlightDate)
 PRIMARY KEY (intHash32(FlightDate))
 ORDER BY (intHash32(FlightDate),FlightNum)
 SAMPLE BY intHash32(FlightDate)
SETTINGS index_granularity= 8192;
复制代码

创建分布式表

分布式表是本地表的集合,它将多个本地表抽象为一张统一的表,对外提供写入、查询功能。当数据写入分布式表时,会被自动分发到集合中的各个本地表中。当查询分布式表时,集合中的各个本地表都会被分别查询,并且把最终结果汇总后返回。您需要先创建本地表,再创建分布式表。

CREATE TABLE distributed_table ON CLUSTER default
 AS default.local_table 
ENGINE = Distributed(default, default, local_table, rand());

表引擎详细讲解参考:https://www.alibabacloud.com/help/zh/clickhouse/developer-reference/table-engines?spm=a2c63.p38356.0.0.665983d14ahBsZ

 添加公众号了解更多:

 

posted @   刘百会  阅读(1110)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示