ClickHouse单机版部署和简介

==作者:YB-Chi==

[toc]

yum在线安装

root用户下

1
2
3
4
5
6
7
8
9
10
11
# 关闭selinux
vim /etc/selinux/config
SELINUX=disabled
# 重启

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
sudo yum install -y clickhouse-server clickhouse-client

sudo /etc/init.d/clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you set up a password.
1
2
3
4
5
6
7
8
#注意 cdh会占用9000端口导致ck启动失败 可以改为9002  需要修改好几个地方
vim /etc/clickhouse-server/config.xml

启动
/etc/init.d/clickhouse-server start

客户端
clickhouse-client --port 9002 -m

添加用户

1
2
3
# 假设密码为xxxxx,利用以下python代码可以得到sha256加密后的字符串:
import hashlib
hashlib.sha256('xxxxx').hexdigest()

修改 users.xml 文件,在< users >与 </ users > 之间加入新创建的用户信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</users>
<default>
*****
</default>
<pangu>
<password_sha256_hex>f99ab85c305b4dd4a85ebbaf0138a6c17a15cd3c9f5888809655d17ba8674c91</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
<allow_databases>
<database>pangu</database>
<database>slave_db</database>
<database>system</database>
</allow_databases>
<access_management>1</access_management>
</pangu>
</users>

Tabix可视化web

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
停止server
service clickhouse-server stop
修改配置
解开注释<listen_host>::</listen_host>
解开注释<http_server_default_response><![CDATA[<html ng-app="SMI2"><head><base href="http://ui.tabix.io/"></head><body><div ui-view="" class="content-ui"></div><script src="http://loader.tabix.io/master.js"></script></body></html>]]></http_server_default_response>
启动服务
service clickhouse-server start
ps -ef|grep click查看进程
如果进程不存在,查看日志
cat /var/log/clickhouse-server/clickhouse-server.err.log

web_url:
http://10.9.1.103:8123/
user:default
pwd:空

CK数据类型

!!!数据类型关键字区分大小写

img

Spark写入CK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<dependency>
<groupId>com.github.housepower</groupId>
<artifactId>clickhouse-native-jdbc</artifactId>
<version>2.6.5</version>
</dependency>

public static Properties getCkProperties(){
Properties properties = new Properties();
properties.put("driver", "com.github.housepower.jdbc.ClickHouseDriver");
properties.put("user", "default");
properties.put("password", "");
properties.put("batchsize", "1000");
properties.put("socket_timeout", "300000");
properties.put("numPartitions", "8");
properties.put("rewriteBatchedStatements", "true");
return properties;
}

public static void write2CK(Dataset<Row> resDf, String tableName) {
resDf.write().mode(SaveMode.Append).option(JDBCOptions.JDBC_BATCH_FETCH_SIZE(), 1000).jdbc("jdbc:clickhouse://10.9.1.103:9002/default", tableName, getCkProperties());
}
文章作者: CYBSKY
文章链接: https://cybsky.top/2022/10/27/cyb-mds/database/ClickHouse/ClickHouse单机版部署和简介/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 CYBSKY