ClickHouse安装

安装源

因为官方只提供ubuntu和Docker的安装方式,所以在Centos下安装需要找第三方源

官方推荐:https://github.com/Altinity/clickhouse-rpm-install

环境准备

测试环境4台服务器

1
2
3
4
192.168.1.1    node1
192.168.1.2 node2
192.168.1.3 node3
192.168.1.4 node4

测试环境Zookeeper集群

1
2
3
zk1:2181
zk2:2181
zk3:2181

安装clickhouse

安装依赖

1
sudo yum install -y pygpgme yum-utils libicu

增加yum.repo

新建文件/etc/yum.repos.d/altinity_clickhouse.repo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[altinity_clickhouse]
name=altinity_clickhouse
baseurl=https://packagecloud.io/altinity/clickhouse/el/6/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/altinity/clickhouse/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[altinity_clickhouse-source]
name=altinity_clickhouse-source
baseurl=https://packagecloud.io/altinity/clickhouse/el/6/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/altinity/clickhouse/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

刷新yum缓存、安装

1
2
sudo yum -q makecache -y --disablerepo='*' --enablerepo='altinity_clickhouse'
sudo yum install -y clickhouse-server clickhouse-client

修改配置文件

clickhouse默认的数据文件和配置文件都在/var,由于服务器的系统盘和数据盘都是单独挂载,显然这样的配置不合理。为了方便管理,我们把日志、配置文件都存储到一个统一的根路径。

修改/etc/rc.d/init.d/clickhouse-server文件

1
2
3
CLICKHOUSE_LOGDIR=/data/clickhouse/log
CLICKHOUSE_DATADIR_OLD=/data/clickhouse/data_old
CLICKHOUSE_CONFIG=/data/clickhouse/config.xml

修改最核心配置文件config.xml,复制到其他节点,注意主机名不同!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?xml version="1.0"?>
<yandex>
<logger>
<level>trace</level>
<log>/data/clickhouse/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/data/clickhouse/log/clickhouse-server/clickhouse-server.err.log</errorlog>
<size>1000M</size>
<count>10</count>
<!-- <console>1</console> --> <!-- Default behavior is autodetection (log to console if not daemon mode and is tty) -->
</logger>
<http_port>8123</http_port>
<tcp_port>9000</tcp_port>
<interserver_http_port>9009</interserver_http_port>

<!-- 主机名-->
<interserver_http_host>node1</interserver_http_host>

<!-- 监听(集群配置必须)-->
<listen_host>0.0.0.0</listen_host>

<!-- 数据目录 -->
<path>/data/clickhouse/</path>

<tmp_path>/data/clickhouse/tmp/</tmp_path>

<!-- 用户相关配置,暂时默认 -->
<user_files_path>/data/clickhouse/user_files/</user_files_path>
<users_config>users.xml</users_config>
<default_profile>default</default_profile>
<default_database>default</default_database>

<!-- 集群配置 -->
<remote_servers incl="clickhouse_remote_servers" >
<test>
<!-- 数据分片1 -->
<shard>
<internal_replication>false</internal_replication>
<replica>
<host>192.168.1.1</host>
<port>9000</port>
</replica>
</shard>
<!-- 数据分片2 -->
<shard>
<internal_replication>false</internal_replication>
<replica>
<host>192.168.1.2</host>
<port>9000</port>
</replica>
</shard>
<!-- 数据分片3 -->
<shard>
<internal_replication>false</internal_replication>
<replica>
<host>192.168.1.3</host>
<port>9000</port>
</replica>
</shard>
<!-- 数据分片4 -->
<shard>
<internal_replication>false</internal_replication>
<replica>
<host>192.168.1.4</host>
<port>9000</port>
</replica>
</shard>
</test>
</remote_servers>

<!-- ZK集群 -->
<zookeeper incl="zookeeper-servers" optional="true">
<node index="1">
<host>zk1</host>
<port>2181</port>
</node>
<node index="2">
<host>zk2</host>
<port>2181</port>
</node>
<node index="3">
<host>zk3</host>
<port>2181</port>
</node>
</zookeeper>
</yandex>

创建相关目录

1
2
3
mkdir -p /data/clickhouse/log
mkdir -p /data/clickhouse/data
chown -R clickhouse:clickhouse /data/clickhouse

启动服务

启动

1
service clickhouse-server start

测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ clickhouse-client

:) use system;

:) select * from clusters;

SELECT *
FROM clusters

┌─cluster─┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name─────┬─host_address──┬─port─┬─is_local─┬─user────┬─default_database─┐
│ test │ 1 │ 1 │ 1 │ 192.168.1.1 │ 192.168.1.1 │ 9000 │ 0 │ default │ │
│ test │ 2 │ 1 │ 1 │ 192.168.1.2 │ 192.168.1.2 │ 9000 │ 1 │ default │ │
│ test │ 3 │ 1 │ 1 │ 192.168.1.3 │ 192.168.1.3 │ 9000 │ 0 │ default │ │
│ test │ 4 │ 1 │ 1 │ 192.168.1.4 │ 192.168.1.4 │ 9000 │ 0 │ default │ │
└─────────┴───────────┴──────────────┴─────────────┴───────────────┴───────────────┴──────┴──────────┴─────────┴──────────────────┘

4 rows in set. Elapsed: 0.001 sec.